How can I create a new table from an existing one in SQL Server 2012 , with both its keys and its data ?
This :
select * into New_Table
from Old_Table
Does not create the dependencies .
And this :
In Sql Server Managment Studio, right-click your existing table and select Script Table as > Create to > New Query Editor Window
Doesn't get the data .
Thanks
The following instructions work well if you want a GUI based solution and are dealing with a moderate amount of data.
Generate Scripts
Select the specific table(s) to recreate
Select the Save to new query window
radio button and click Advanced
to set scripting options for the table
Set the Types of data to script
property to Schema and data
Modify the table name in the resulting script as appropriate
One way is to use something like SQL Server Data Tools (SSDT). This is a free, Microsoft, add-on to Visual Studio 2012/2013 (which you don't need to own). This tool will do schema and data compares. So all dependencies and schema objects will be created for you, in the correct order.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.