Ernesto
asked on
insert from another database
Hi all,
How can I do an insert from another database table:
insert into paso2.proj.PIPE_PIPE_SPEC (select * from 1008.proj.PIPE_PIPE_SPEC )
How can I do an insert from another database table:
insert into paso2.proj.PIPE_PIPE_SPEC (select * from 1008.proj.PIPE_PIPE_SPEC )
ASKER
PIPE_PIPE_SPEC is the table name in the 2 databases
oh different database! hmmm not sure if you can - what database vendor are we talking about?
ASKER
is sql server
Anyway, I don't see how you can do this in whatever database. You need a 3rd-party tool or script to read from the source database then insert to the destination. Shouldn't be difficult to do if you know a scripting language like Perl or Ruby. Either that or copy the source table to another table of different name, export the new table, import to destination database, then just:
insert into table_name select * from imported_table_name.
insert into table_name select * from imported_table_name.
ASKER
Realy?
is not posible insert data from an other database via sql query?, oh man is so dissapointed hear that
i supposed is part off all this thing
tys
is not posible insert data from an other database via sql query?, oh man is so dissapointed hear that
i supposed is part off all this thing
tys
I don't know of anything that would do it automatically without paying. Some options:
- Semi-automatic: If you already own something like Microsoft Access, on any DB create a linked table to your souce table, and another one to your target table. Then do the insert as select as you say. You will need to be familiar with creating ODBC datasources, and bear in mind that you will generate large network traffic if your data volume is large
- Manual: In your source DB, run a statement like this and send the output to "insert.sql":
SELECT 'insert into target_table values (' ||
number_field_1 || ', ' ||
''' || char_field_1 || '', ' ||
...and so on for the rest of the fields...
');'
FROM source_table;
Then run insert.sql on the target DB
- Semi-automatic: If you already own something like Microsoft Access, on any DB create a linked table to your souce table, and another one to your target table. Then do the insert as select as you say. You will need to be familiar with creating ODBC datasources, and bear in mind that you will generate large network traffic if your data volume is large
- Manual: In your source DB, run a statement like this and send the output to "insert.sql":
SELECT 'insert into target_table values (' ||
number_field_1 || ', ' ||
''' || char_field_1 || '', ' ||
...and so on for the rest of the fields...
');'
FROM source_table;
Then run insert.sql on the target DB
ASKER
I need to perform this in a VB.Net code
is any idea?
is any idea?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
yes them are in the same server
Again, if you have permission on both databases and they are both on the same server, all you have to do is send the insert statement in the format above to the database that has the table where data is inserted and it should work fine. Don't use () around the select statement.
ASKER
but i have problem because 1 database has a number name 1008, how can solve this?
thanks
INSERT INTO paso2.proj.pipe_pipe_spec
SELECT * FROM 1008.proj.PIPE_PIPE_SPEC
thanks
INSERT INTO paso2.proj.pipe_pipe_spec
SELECT * FROM 1008.proj.PIPE_PIPE_SPEC
INSERT INTO paso2.proj.PIPE_PIPE_SPEC
SELECT * FROM 1008.proj.PIPE_PIPE_SPEC
This assumes that paso2 and 1008 are both databases on the same server and proj is the owner of the table named PIPE_PIPE_SPEC
SELECT * FROM 1008.proj.PIPE_PIPE_SPEC
This assumes that paso2 and 1008 are both databases on the same server and proj is the owner of the table named PIPE_PIPE_SPEC
ASKER
yes
but cant run because 1008 name
but cant run because 1008 name
ASKER
ok
INSERT INTO paso2.proj.PIPE_PIPE_SPEC
SELECT * FROM "1008".proj.PIPE_PIPE_SPEC
thank you a lot
INSERT INTO paso2.proj.PIPE_PIPE_SPEC
SELECT * FROM "1008".proj.PIPE_PIPE_SPEC
thank you a lot
place the name in [ ] like this [1008].proj.PIPE_PIPE_SPEC
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
insert into paso2.proj (PIPE_PIPE_SPEC) select PIPE_PIPE_SPEC from 1008.proj;