Copying Table In SQL Server 2005

Copy table from same Database:

select * into destination table from source table

Here NewTable created automatically along with data insertion from existing table.

Copy table from another Database:

SELECT * INTO DestinationDatabase.dbo.destination table FROM SourceDatabase.dbo.source table

Copy few columns into the destination table:

select col1, col2, col3 into  

This will copy the table from one database to another database.
NOTE: using this query will only transfer the schema and data. It does not transfer the indexes, foreign keys, statistics etc.

If you want to transfer all the objects from one database to another, open Sql Server Management Studio > Right click on your database > All Tasks > Generate SQL Scripts. Then run these scripts against the new database.

The Generate SQL Server Scripts Wizaed allows you to generate scripts for database and objects inside of databases.


Post a Comment