Get exactly the same database, including the foreign key relationship between table and table, CHECK,DEFAULT table structure script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.