ssms 生成迁移脚本 Generate script in SQL Server Management Studio

Generate script in SQL Server Management Studio

Here what you have to do:

  1. right click the database (not the table) and select tasks --> generate scripts
  2. Next --> select the requested table/tables (from select specific database objects)
  3. next --> click advanced --> types of data to script = schema and data
  4. next and finish

Generate and Publish Scripts Wizard

You can use the Generate and Publish Scripts Wizard to create scripts for transferring a database between instances of the SQL Server Database Engine or Azure SQL Database. You can generate scripts for a database on an instance of the Database Engine in your local network, or from SQL Database. The generated scripts can be run on another instance of the Database Engine or SQL Database. You can also use the wizard to publish the contents of a database directly to a Web service created by using the Database Publishing Services. You can create scripts for an entire database, or limit it to specific objects.

For a more detailed Tutorial on using the Generate and Publish Scripts wizard, see Tutorial: Generate Scripts Wizard.

 Advanced Scripting Options Page

Use this page to specify how you want this wizard to generate scripts. Many different options are available. Options are greyed out if they are not supported by the version of SQL Server or SQL Database specified in Database engine type.

Options - Specify advanced options by selecting a value from the list of available settings to the right of each option.

General - The following options apply to the entire script.

  • ANSI Padding - Includes ANSI PADDING ON in the script. The default is True.

  • Append to file - When True, this script is added to the bottom of an existing script, specified on the Set Scripting Options page. When False, the new script overwrites a previous script. The default is False.

  • Continue scripting on error - When False, scripting stops when an error occurs. When True, scripting continues. The default is False.

  • Convert UDDTs to base types - When True, user-defined data types (UDDT) are converted into the underlying base data types that were used to create them. Use True when the UDDT does not exist in the database where the script runs. When False, UDDTs are used. The default is False.

  • Generate script for dependent objects - Generates a script for any object that is required to be present when the script for the selected object is executed. The default is True.

  • Include descriptive headers - When True, descriptive comments are added to the script separating the script into sections for each object. The default is False.

  • Include if NOT EXISTS - When True, the script includes a statement 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 is False.

  • Include system constraint names - When False, the default value of constraints that were automatically named on the origin database are automatically renamed on the target database. When True, constraints have the same name on the origin and target databases.

  • Include unsupported statements - When False, the script does not contain statements for objects that are not supported on the selected server version or engine type. When True, the script contains the unsupported objects. Each statement for an unsupported object has a comment that the statement must be edited before the script can be run against the selected SQL Server version or engine type. The default is False.

  • Schema qualify object names - Includes the schema name in the name of objects that are created. The default is True.

  • Script binding - Generates a script for binding default and rule objects. The default is False. For more information, see CREATE DEFAULT (Transact-SQL) and CREATE RULE (Transact-SQL).

  • Script collation - Includes collation information in the script. The default is False. For more information, see Collation and Unicode Support.

  • Script defaults - Includes default objects used to set default values in table columns. The default is True. For more information, see CREATE DEFAULT (Transact-SQL).

  • Script drop and create - When Script CREATE, Transact-SQL statements are included to create objects. When Script DROP, Transact-SQL statements are included to drop objects. When Script DROP and CREATE, the Transact-SQL drop statement is included in the script, followed by the create statement, for each scripted object. The default is Script CREATE.

  • Script extended properties - Includes extended properties in the script if the object has extended properties. The default is True.

  • Script for engine type - Creates a script that can be run on the selected type of either SQL Database or an instance of the SQL Server Database Engine. Objects not supported on the specified type are not included in the script. The default is the type of the origin server.

  • Script for server version - Creates a script that can be run on the selected version of SQL Server. Features new to a version cannot be scripted for earlier versions. The default is the version of the origin server.

  • Script logins - When the object to be scripted is a database user, this option creates the logins on which the user depends. The default is False.

  • Script object-Level permissions - Includes scripts to set permission on the objects in the database. The default is False.

  • Script statistics - When set to Script Statistics, this option includes the CREATE STATISTICS statement to re-create statistics on the object. The Script statistics and histograms option also creates histogram information. The default is Do not script statistics. For more information, see CREATE STATISTICS (Transact-SQL).

  • Script USE DATABASE - Adds the USE DATABASE statement to the script. To make sure that database objects are created in the correct database, include the USE DATABASE statement. When the script is expected to be used in a different database, select False to omit the USE DATABASE statement. The default is True. For more information, see USE (Transact-SQL).

  • Types of data to script - Selects what should be scripted: Data only, Schema only, or both. The default is Schema only.

Table/View Options - The following options apply only to scripts for tables or views.

  • Script change tracking - Scripts change tracking if it is enabled on the origin database or tables in the origin database. The default is False. For more information, see About Change Tracking (SQL Server).

  • Script check constraints - Adds CHECK constraints to the script. The default is True. CHECK constraints require data that is entered into a table to meet some specified condition. For more information, see Unique Constraints and Check Constraints.

  • Script data compression options - Scripts data compression options if they are configured on the origin database or tables in the origin database. For more information, see Data Compression. The default is False.

  • Script foreign keys - Adds foreign keys to the script. The default is True. Foreign keys indicate and enforce relationships between tables.

  • Script full-text indexes - Scripts the creation of full-text indexes. The default is False.

  • Script indexes - Scripts the creation of indexes. The default is True. Indexes help you find data quickly.

  • Script primary keys - Scripts the creation of primary keys on tables. The default is True. Primary keys uniquely identify each row of a table.

  • Script triggers - Scripts the creation of DML triggers on tables. The default is False. A DML trigger is an action programmed to execute when a data manipulation language (DML) event occurs in the database server. For more information, see DML Triggers.

  • Script unique keys - Scripts the creation of unique keys on tables. Unique keys prevent duplicate data from being entered. The default is True. For more information, see Unique Constraints and Check Constraints.

配置需要启用

Check for object existence  设置为true

Script drop and create - When Script CREATE, Transact-SQL statements are included to create objects. When Script DROP, Transact-SQL statements are included to drop objects. When Script DROP and CREATE, the Transact-SQL drop statement is included in the script, followed by the create statement, for each scripted object. The default is Script CREATE.  设置为drop and create

Script USE DATABASE - Adds the USE DATABASE statement to the script. To make sure that database objects are created in the correct database, include the USE DATABASE statement. When the script is expected to be used in a different database, select False to omit the USE DATABASE statement. The default is True. For more information, see USE (Transact-SQL).  设置为false

猜你喜欢

转载自www.cnblogs.com/chucklu/p/12744606.html