Sql-server – Transfer of data from table to other database table have the same primary key

sql serversql server 2014

I have a database with data, I want to copy the all tables with data to newly created database also with same existed auto incremented primary field. How I can do that process.

Best Answer

There are a couple of ways to do this. It depends on your setup. As per the previous question, if you just need a copy of everything you can backup and restore the database onto a new instance or, on the same instance with a different name.

If you need to physically pipe data with identity columns, into a new database thats already setup, you could use the import export tool. With that you can easily select just the tables you want data from, and the destination. Its quick and easy for a one time load. If you need to keep Identity columns, remember to select Column Mappings, and check the box to enable Identity insert per the article on Microsoft's website.

This is just one option to moving the data. A quick google and you will find many other options, including BCP, Linked Servers, SSIS, etc. It all depends on how often you want to do this load. How often do you need to do this?