How to generate scripts in SQL Server

Source: Internet
Author: User

Many parameters can be selected during script generation. reasonable configuration of these parameters makes it easy for us to generate scripts as expected.

Script generation options, such:

Here is the SQL 2005 option, which is slightly different from this option.

For the difference, see the following two articles.

SQL Server 2005 SQL Server script generation wizard "select script option" Page)
Http://technet.microsoft.com/zh-cn/library/ms186472 (SQL .90). aspx

SQL Server 2008 SQL Server script generation wizard "select script option" Page)
Http://technet.microsoft.com/zh-cn/library/ms186472.aspx

Parameter description. The red part is commonly used.

General options:

Ansi Padding

Add the SET ANSI_PADDING ON statement before and after each create table statement. The default value is True.

Append to File

Add the script to the bottom of the existing script and specify it on the "output options" page. The default value is False, indicating that the new script will overwrite the previous one.

Continue Scripting on Error

True indicates that the script is stopped when an error occurs. If the value is False, write the script again. The default value is False.

Convert UDDTs to Base Types

If the value is True, the user-defined data type is converted to the basic data type used to create the user-defined data type. Use True if the user-defined data type does not exist in the database that runs the script. The default value is False, indicating that scripts will be written for user-defined data types using UDDT.

Generate Script for Dependent Objects

The script for generating dependent objects is used to generate scripts for any objects that must exist when the script for the selected object is executed. The default value is True.

Include Descriptive Headers

When the value is True, descriptive comments are added to the script. The script is divided into several parts, and each object is a part. The default value is False.

I used to change this item to true when generating it, so that you can see the comment.

Include If NOT EXISTS

When the value is True, the script contains a statement used to check whether the object already exists in the database, and does not try to create a new object if the object already exists. The default value is True.

Include system constraint names

Contains the name of the constraint generated by the system to force declarative reference integrity. The default value is False. Yes

Script Collation

Include the sorting Rule Information in the script. The default value is False.

See http://technet.microsoft.com/zh-cn/library/ms187582 (SQL .90). aspx

Script Create

Contains the CREATE statement of each object. The default value is True.

Script Defaults

Columns include their default values when they exist in the original object. The default value is True.

Script Drop

The DROP statement that contains each object. The default value is False.

Script Extended Properties

If the object has extended attributes, the script contains the extended attributes. The default value is True.

Script for Server Version

Create a script that can run on the selected SQL Server version. You cannot write scripts for new features of SQL Server 2005 for earlier versions. Some scripts created for SQL Server 2005 cannot run on servers that run earlier SQL Server versions, nor on databases with earlier database compatibility settings. The default value is SQL Server 2005.

Script Logins

When you want to write a script for a database user, use the "Write logon script" option to create the login on which the user depends. The default value is False.

Script Object-Level Permissions

Contains scripts for setting permissions on objects in the database. The default value is False.

Script Owner

If the value is True, the CREATE statement contains the current object owner or schema. If the value is False, the CREATE statement does not contain the object owner or schema, and the object created by the script uses the default value for users who are executing the script. The default value is True.

If it is true, for example, the stored procedure name may be dbo. *** if it is false, the information about dbo. is not found. I am used to false.

Script Statistics

When it is set to "Write STATISTICS script", it will contain the create statistics statement to recreate STATISTICS about the object. The "Write statistics and histogram script" setting also creates the histogram information. By default, no statistical script is written.

Script USE DATABASE

Add the use database statement to the script. To create DATABASE objects in the correct DATABASE, include the use database statement. If the script is expected to be used in other databases, select False to omit the use database statement. The default value is False.

Script VarDecimal Options

The vardecimal storage option that contains the script. The default value is False.
See http://technet.microsoft.com/zh-cn/library/bb326755 (SQL .90). aspx

Table and view

Script Check Constraints

Add the CHECK constraint to the script. The default value is True. The CHECK constraint requires that the data in the input table meet certain specified conditions.

Script Foreign Keys

Add the foreign key to the script. The default value is True. The foreign key can indicate and forcibly maintain the relationship between tables.

Script Full-Text Indexes

The index view that contains the full text index or script of each table. The default value is False.

Script Indexes

Add clustered indexes, non-clustered indexes, and XML indexes for each table, or add the index view of the script. The default value is False.

Script Primary Keys

Add a primary key creation script for the table. The default value is True. A primary key uniquely identifies each row of a table.

Script Triggers

Add a trigger script for creating a table. The default value is True. The trigger triggers operations when data is modified.

Script Unique Keys

Add a unique key script for the table. Unique keys prevent repeated input data. The default value is True.

We are familiar with other options, that is, let us select the database objects to be generated. Ignore.

When generating the format, SQL Server provides us with the following options:

Here, you can easily generate scripts to The. SQL file in Unicode or ANSI text format.

In addition, all scripts can be stored in one file, or the scripts of each object can be stored in one file.

Then, confirm the generation option and generate it.

Related Article

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.