Today, the company gave a task, a project because the data is too large, causing SQL Server 2012 to run with a lot of memory, so to separate the previously infrequently used data. Ask to write a script that requires:
1. Can get the table structure in the original database, the primary key is consistent. The constraint Relationship between table and table (foreign key, check,default) is consistent;
2. Some tables do not want to be, optional.
3. And efficiency to consider, this script is commonly used later.
(Here are the local test data)
Software: SQL Server2012 (other versions did not personally experiment, do not know the effect)
Figure 1: Find the original database, select the task--Generate script
Figure 2: Select the table you want to create (you can select all, this example selects all)
Figure 3: The path to the save script, which is the default path
Figure 4: Some overviews, direct next
Figure 5: Create a new database manually, here is Answertest, and then open the script you just saved, some of the names are changed to the database you just created, here all to Answertest
Figure 6: This section creates the statement that created the database just now, but because we created it, we don't need this part. However, if I do not manually create the previous database, the execution of the other place will be error, said: "Database answertest doesn ' t exist ...", do not know what the reason for advice.
Figure 7: These constraints are checked first (exactly right here), please press F5 to execute.
I tested it 4 times, and the test passed.
Get exactly the same database, including the foreign key relationship between table and table, CHECK,DEFAULT table structure script