Reputation: 856
I have two database there is two table both databse how to import data from database table to another database table in sql2008 standard edition. I have tried to export/import function but no luck . would you Please help me ?
Upvotes: 5
Views: 32700
Reputation: 53958
I think the code below will work for your case:
INSERT INTO table1 (column1,column2)
SELECT oldcolumn1, oldcolumn2
FROM table2
Optionally you could add a where clause.
Upvotes: 15
Reputation: 3329
Use this code and check below links
The insert statement actually has a syntax for doing just that. It's a lot easier if you specify the column names rather than selecting "*" though:
INSERT INTO new_table (Foo, Bar, Fizz, Buzz)
SELECT Foo, Bar, Fizz, Buzz
FROM initial_table
-- optionally WHERE ...
The INSERT INTO ... SELECT FROM
syntax is for when the table you're inserting into ("new_table" in my example above) already exists. As others have said, the SELECT ... INTO
syntax is for when you want to create the new table as part of the command.
You didn't specify whether the new table needs to be created as part of the command, so INSERT INTO ... SELECT FROM
should be fine if your destination table already exists.
i hope this answer useful for you.
Upvotes: 3