Pages

Friday, November 21, 2008

Copy in SQL Server

How to copy the tables, schema and views from one SQL Server to another?

There are multiple ways to do this.

1. "Detach Database" from one server and "Attach Database" to another server.
2. Manually script all the objects using SSMS and run the script on new server.
3. Use Wizard of SSMS.
How to copy data from one table to another table?

There are multiple ways to do this.

INSERT INTO SELECT

This method is used when table is already created in the database earlier and data is to be inserted into this table from another table. If columns listed in insert clause and select clause are same, they are not required to list them.

SELECT INTO

This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.

3 comments:

Aashish Gupta said...
This comment has been removed by the author.
Ashish Kumar said...

Sorry i dont know what just happened while commenting the comment shows that it just got deleted so i once again thank you for this nice work which you are doing.Keep it up,nice small article.

Vijaya Kadiyala said...

Hi Aashish,
Thank you for visiting my blog..
watch out for more information.
Thanks -- Vj