14 January,2016 by Tom Collins
Question: I want to copy some tables from one database to another database in the same SQL Server instance. The copy should include creating a new table with the same ddl, indexes and constraints,triggers . Once the table is created the data requires to be moved
Answer: As with a lot of things in SQL Server, it is possible to complete this task in multiple ways. This gives you the flexibility for your particular requirements. Before you start I’d make sure the database is backed up and you have recovery point in case of loss. I've listed 3 methods , and added some other methods through links at the bottom of this post
If you only want to copy tables and not concerned with relationships, this is a quick and manageable method.
Right Click on the database | Tasks | Export Data (or Import Data)
Some things you may need to consider when using the Import\Export Wizard method
Generate scripts for all tables and other objects you want to migrate. Right click on the database | Tasks | Generate scripts | select tables and objects you want to migrate.
This method requires some review before you execute the scripts. By default, SSMS doesn’t order the scripts in the correct order
Once you’ve created the Destination object , you can use the Import\Export Wizard.
Over time I’ve used a few different tools. I’ve had good experiences with a few different tools – ApexSQLDiff and SQL Compare – are two examples of comprehensive tools.These tools require licenses, but the Trial period gives you quite a bit of functionality.
bcp - export and import data on SQL Server - SQL Server DBA
SQL Server - Bulk Insert CSV into a SQL Server table - SQL
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |