Through the menu below, we can generate scripts for every object in the database we selected in SQL Server Management studio. This allows us to manage database versions, and the Database Upgrade documentation is very convenient.
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.Article
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
Generate scripts for dependent objects
Generate scripts for any objects that must exist when executing scripts for the selected objects. 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.
References:
F1 help for generating SQL server script wizard
Http://technet.microsoft.com/zh-cn/library/ms181421.aspx
How to: generate a script (SQL Server Management studio)
Http://technet.microsoft.com/en-us/library/ms178078.aspx
How can I automate the "generate scripts" task in SQL Server Management studio 2008?
Http://stackoverflow.com/questions/483568/how-can-i-automate-the-generate-scripts-task-in-sql-server-management-studio-2008
Microsoft SQL Server database Publishing Wizard 1.1
Http://www.microsoft.com/downloads/details.aspx? Displaylang = ZH-CN & familyid = 56e5b1c5-bf17-42e0-a410-371a838e570a