Question : How to create a copy of table from one database to another(need schema as well)+sql server 2005

Hi,
In db1 I do not have table1 which exists in db2.I need to create the table1 in db1 and copy the data as well.i am using sql server 2005.
Any suggestions appreciated.

Answer : How to create a copy of table from one database to another(need schema as well)+sql server 2005

You can do it in two simple steps:

Step1: on DB2, right-click on table1, then select "Script table as-->CREATE TO-->New Query Window Editor" this will script your table structure; then just run the generated script USING DB1 ( USE DB1 on top of the generated script).

Step2: Run this if your 2 databases are located on the same SQL server instance
INSERT INTO DB1.table1
SELECT * FROM DB2;table1
if not, then if you have a linked server just run it like this:
INSERT INTO DB1.table1
SELECT * FROM YourLinkedServerName.DB2;table1

And you're done !
Random Solutions  
 
programming4us programming4us