数据库项目设置Database Project Settings

使用数据库项目设置可控制数据库、调试和生成配置的各个方面。You use database project settings to control aspects of your database, debugging and build configurations. 这些设置分为以下几类。These settings fall into the following categories.

为数据库项目配置属性To configure properties for your database project

  1. 在“解决方案资源管理器” 中,右键单击要为其配置属性的数据库项目,然后选择“属性” 。In Solution Explorer, right-click the database project for which you want to configure properties, and select Properties.

    或者,在“解决方案资源管理器” 中双击项目的“属性” 节点。Alternatively, double click the Properties node of the project in Solution Explorer.

  2. 此时将显示数据库项目的属性表。The properties sheet for your database project appears.

  3. 单击“项目设置” 选项卡。现在,您可以配置数据库项目属性的常规属性了。Click the Project Settings tab. You can now configure general properties of your database project properties. 请注意左窗格上各个选项卡(代表不同类别)的可用性。Notice the availability of various tabs (representing different categories) on the left pane.

项目设置Project Settings

下表中的设置适用于此数据库项目的所有配置。The settings in the following table apply to all configurations of this database project.

字段Field 默认值Default value 描述Description
目标平台Target Platform Microsoft SQL Server 2012Microsoft SQL Server 2012 指定针对此数据库项目使用的 SQL Server 版本。Specifies the version of SQL Server that you are targeting with this database project.
对常见对象启用扩展 Transact-SQL 验证。Enable extended Transact-SQL verification for common objects. 创建新项目时不启用。Not enabled when you create a new project.

从连接到 SQL Azure 的 SQL Server 对象资源管理器创建项目时、将 SQL Azure 数据库导入该项目时,或将项目的目标平台更改为 SQL Azure 时启用。Enabled when you create a project from SQL Server Object Explorer connected to SQL Azure, import a SQL Azure Database into the project, or change a project's Target Platform to SQL Azure.
启用此选项时,将报告项目中发现的 SQL Server 编译器验证失败的错误。When this option is enabled, errors found in the project that failed SQL Server Compiler verification are reported. 如果将目标平台更改为 SQL Azure,则会启用扩展验证。If you change your target platform to SQL Azure, Extended Verification becomes enabled. 如果您更改目标平台,则不会取消选中该选项。The option will not be unchecked if you change your Target Platform.

可以为其他版本的 SQL Server 启用此选项,但验证将限制为 Microsoft SQL Server 2012 部分包含数据库和 SQL Azure。You can enable this option for other versions of SQL Server, but validation is limited to Microsoft SQL Server 2012 Partially Contained Databases and SQL Azure. 并非所有 Transact-SQL 语法都受到所有 SQL Server 版本的支持。Not all Transact-SQL syntax is supported for all versions of SQL Server.

有关详细信息,请参阅本主题中稍后的扩展的 Transact-SQL 验证For more detailed information, see Extended Transact-SQL Verification later in this topic
输出类型Output types
数据层应用程序包(.dacpac 文件)Data-tier Application (.dacpac file) 启用并且锁定。Enabled and locked. 在生成一个数据库项目时,该数据库项目的生成输出始终生成一个 .dacpac 包。The build output of a database project always produces a .dacpac package when the project is built. 如果正在使用具有“创建其他下级 .dacpac 文件 (v2.0)”选项的 SQL Server 数据工具 (SSDT) 版本,且希望包与 SQL Server Management Studio 或 SQL Azure 管理门户兼容,则选中该选项。If you are using the version of SQL Server Data Tools (SSDT) that has the "Create additional down-level .dacpac file (v2.0)" option, check it if you want for the package to be compatible with SQL Server Management Studio or SQL Azure Management Portal. 可以从 (SSDT) 直接部署 .dacpac 包,但在发布 SQL Server 数据工具时只能通过 SQL Server Management Studio 部署 2.0 版本的 .dacpac 文件。You can deploy a .dacpac package directly from (SSDT), but you can deploy only a version 2.0 .dacpac file through SQL Server Management Studio at the time SQL Server Data Tools is released.
创建脚本(.sql 文件)Create Script (.sql File) 指定完整 .sql CREATE 脚本是否为项目中的所有对象生成,以及当项目生成时该脚本是否位于 bin\debug 文件夹中。Specifies whether a full .sql CREATE script is generated for all the objects in the project, and placed in the bin\debug folder when the project is built. 您可以使用 “项目发布” 命令或 SQL Compare 实用工具创建增量更新脚本。You can create an incremental update script using the Project Publish command or SQL Compare utility.
泛型Generic
默认架构Default schema dbodbo 指定在其中创建 SQLCLR 和 Transact-SQL 对象的默认架构。Specifies the default schema in which both SQLCLR and Transact-SQL objects are created. 可以通过直接对项目指定架构来重写此设置。You can override this setting by specifying schema directly on objects."
在文件名中包括架构名称Include schema name in file name no 指定文件名是否包括架构作为前缀(例如,dbo.Products.table.sql)。Specifies whether file names include the schema as a prefix (for example, dbo.Products.table.sql). 如果清除此复选框,则对象的文件名将采用以下形式:ObjectName.ObjectType.sql(例如 Products.table.sql)。If this check box is cleared, file names for objects take the form ObjectName.ObjectType.sql (for example, Products.table.sql).
验证标识符的大小写Validate Casing on Identifiers yes 指定在项目生成时是否验证其中的 SQL 对象中的标识符的大小写。Specifies whether casing on identifiers in the SQL objects in the project are validated when the project is built. 此选项适用于为数据库指定区分大小写的排序规则的数据库项目。This option applies to database projects that specify case-sensitive collation for the database.
数据库设置Database Settings 基于数据库的标准配置设置的默认设置Default settings based on the standard configuration settings for a database 您可以指定的设置示例包括针对 SQL Server 数据库的排序规则方法和数据库级别设置。Examples of settings you can specify include the collation method and database level settings for a SQL Server database.

扩展的 Transact-SQL 验证Extended Transact-SQL Verification

重要

扩展 Transact-SQL 验证功能将从 SQL Server 数据工具的下一个功能版本和 Visual Studio 的下一个主要版本中删除。The Extended Transact-SQL Verification feature will be removed from the next feature release of SQL Server Data Tools and next major release of Visual Studio.

扩展的 Transact-SQL 验证是数据库项目系统内的一项功能,开发人员利用它可以在构建时将其数据库项目提交到 Transact-SQL 编译器服务,以针对 SQL Server 引擎的解析器和解释器验证其代码。Extended Transact-SQL Verification is a feature within the database project system that allows developers to submit their database project to the Transact-SQL Compiler Service at build time to validate their code against the SQL Server Engine's parser and interpreter.

Transact-SQL 编译器服务Transact-SQL Compiler Service

Transact-SQL 编译器服务是基于 Microsoft SQL Server 2012 数据库引擎的组件。Transact-SQL Compiler Service is a component based on the Microsoft SQL Server 2012 Database Engine. 此服务可验证 DDL 语句的语法和语义,保真度与 Microsoft SQL Server 2012 数据库引擎相同。This service can validate the syntax and semantics of DDL statements with the same fidelity as a Microsoft SQL Server 2012 Database engine. 从内在本质看,这意味着编译器服务不支持 Microsoft SQL Server 2012 中不推荐使用的语法或功能。This inherently means that the Compiler Service does not support syntax or features that have been deprecated in Microsoft SQL Server 2012. 要详细了解已弃用的功能,请参见 SQL Server 2012 中中止的数据库引擎功能For more information about deprecated features, see Discontinued Database Engine Functionality in SQL Server 2012.

为了进行数据库项目验证,编译器服务会创建一个部分包含的数据库,并会针对该数据库模拟执行 DDL 语句。For purpose of validation of the database project, the Compiler Service creates a partially contained database and simulates execution of the DDL statements against that database. 有关详细信息,请参阅 部分包含的数据库For more information, see Partially Contained Databases.

编译器服务具有两类限制。The Compiler Service has two categories of limitations.

依赖数据库或实例配置的功能包括:Features that rely on database or instance configuration including:

  • 3 或 4 部分对象引用3 or 4-part object references

  • FileTableFileTables

  • 更改跟踪Change Tracking

  • Rowset 函数 - OPENROWSET、OPENQUERY、OPENDATASOURCERowset functions - OPENROWSET, OPENQUERY, OPENDATASOURCE

  • 全文语义搜索FullText Semantic Search

目前不支持验证的功能包括:Features that are not currently supported for validation including:

  • Service BrokerService Broker

  • 具有用户定义的 FileGroup 的分区架构Partitioned Schemas with user-defined FileGroups

  • SQL Azure 元数据排序规则(编译器服务使用 SQL Server 2012 部分包含的数据库元数据排序规则 - Latin1_General_100_CI_AS_KS_WS_SC)SQL Azure Metadata Collation (Compiler Service uses SQL Server 2012 Partially Contained Database metadata collation - Latin1_General_100_CI_AS_KS_WS_SC)

启用/禁用扩验证Enabling/Disabling Extended Verification

在直接从 SQL Azure 数据库创建的项目中,或目标平台设置为 SQL Azure 的项目中,扩展的 Transact-SQL 验证会默认启用。Extended Transact-SQL Verification is enabled by default in a database project that is created directly from a SQL Azure database or a project whose target platform is set to SQL Azure. 在为 SQL Azure 数据库或以 SQL Server 2012 为目标的应用程序范围的数据库开发时,推荐使用扩展验证。It is recommended that Extended Verification be used when developing for SQL Azure or an application-scoped database targeting SQL Server 2012. 有关应用程序范围的数据库的详细信息,请参阅 部分包含的数据库For more information about application scoped databases, see Partially Contained Databases.

在为 SQL Server 2008/R2 开发应用程序范围的数据库以实现与 Microsoft SQL Server 2012 和 SQL Azure 兼容时,也可以使用扩展验证功能。The Extended Verification feature can also be used when developing an application-scoped database for SQL Server 2008/R2 to achieve compatibility with Microsoft SQL Server 2012 and SQL Azure.

在项目级别启用或禁用扩展验证To enable or disable Extended Verification at the project level
  1. 在“解决方案资源管理器” 中,右键单击项目文件,然后单击“属性” 。In Solution Explorer, right-click on the project file, and then click Properties.

  2. 在“属性设置” 中的“目标平台” 下,选中或取消选中“对常见对象启用扩展 Transact-SQL 验证” 。In Project Settings, under Target Platform, check or uncheck Enable extended Transact-SQL verification for common objects.

在文件级别启禁用扩展验证To disable Extended Verification at the file level
  1. 在“解决方案资源管理器” 中,右键单击 .sql 文件。In Solution Explorer, right-click on a .sql file.

    备注

    为了在文件级别禁用扩展 Transact-SQL 验证功能,文件的“生成操作”属性必须设置为“生成” 。In order to disable the Extended Transact-SQL Verification feature at the file level, the file's Build Action property must be set to Build.

  2. 在“属性” 中,将“扩展 T-SQL 验证” 属性更改为 False 。In Properties, change the Extended T-SQL Verification property to False.

文件属性File Properties

排序规则的特殊注意事项Special Considerations for Collations

有关部分包含的数据库中排序规则的详细信息,请参阅 包含的数据库排序规则For more information regarding collations in partially contained databases, see Contained Database Collations.

SQLCLRSQLCLR

有关“程序集”选项的信息,请参见 “程序集信息”对话框For information about the Assembly options, see Assembly Information Dialog Box.

有关签名的信息,请参见 “签名”页, 项目设计器 主题的“程序集签名” 一节。For information about signing, see the Assembly Signing section of the Signing Page, Project Designer topic.

SQLCLR 和 SQLCLR 生成SQLCLR and SQLCLR Build

SQLCLR“SQLCLR 生成” 属性页包含可供在您的项目中使用 SQL CLR 对象的许多设置。The SQLCLR and SQLCLR Build property pages contain many settings for using SQL CLR objects in your project. 具体来说, SQLCLR 属性页具有用于对 SQLCLR 程序集设置权限的权限级别设置。Specifically, the SQLCLR property page has a permission level setting to set permissions on the SQLCLR assembly. 它还具有“生成 DDL”设置,以便控制为已添加到项目的 SQLCLR 对象是否生成动态数据语言 (DDL)。It also has a "generate DDL" setting to control whether Dynamic Data Language (DDL) is generated for the SQLCLR objects that have been added to the project. “SQLCLR 生成” 属性页包含可为配置项目中 SQLCLR 代码的编译而设置的所有编译器选项。The SQLCLR Build property page contains all the compiler options that you can set to configure the compilation of SQLCLR code in the project.

“SQLCLR 生成” 属性页包含用于生成 SQL CLR 对象的高级生成设置。The SQLCLR Build property page contains advanced build settings for building your SQL CLR objects. 已基于用来编写 SQL CLR 对象代码的语言(VB 或 C#)提供了不同选项。Different options are provided based on the language (VB or C#) used to code the SQL CLR objects.

  1. 如果对象是用 C# 编写的,则可以通过单击“SQLCLR 生成” 属性页上的“高级” 按钮访问这些选项。If the object is written in C#, you can access the options by clicking the Advanced button in the SQLCLR Build property page. 可以在“高级生成设置”对话框 (C#) 中找到 C# 选项的说明。Descriptions for C# options can be found at Advanced Build Settings Dialog Box (C#).

  2. 如果对象是用 VB 编写的,则可以先选择 “语言” 下拉列表中的“VB”,然后单击 “高级” 按钮。If the object is written in VB, you can first choose VB in the Language dropdown list, then click the Advanced button. 可以在“高级编译器设置”对话框 (Visual Basic) 中找到 VB 选项的说明Descriptions for VB options can be found at Advanced Compiler Settings Dialog Box (Visual Basic)

生成Build

可以为解决方案中的每个数据库项目选择生成配置。You can choose a build configuration for each database project in your solution. 默认情况下有一个配置,但您可以添加自定义配置。By default there is a single configuration, but you can add custom configurations. 例如,如果您需要一个总是删除并重新创建数据库的自定义配置,您可以选择添加自定义配置。You might choose to do this, for example, if you wanted a custom configuration in which you always deleted and re-created the database. 在包含不同项目类型的解决方案中,可以创建一个自定义解决方案配置,其中包含每个项目的特定生成配置。In solutions that contain different project types, you can create a custom solution configuration that contains a particular build configuration for each project.

为解决方案指定生成配置To specify a build configuration for a solution

  1. 在“解决方案资源管理器” 中,单击要为其指定生成配置的解决方案节点。In Solution Explorer, click the solution node for which for which you want specify a build configuration.

  2. 在“生成” 菜单上,单击“配置管理器” 。On the Build menu, click Configuration Manager. 将显示“配置管理器” 对话框。The Configuration Manager dialog box appears.

    指定要对解决方案中的每个项目使用的配置设置。Specify the configuration settings that you want to use for each project in your solution.

为数据库项目指定生成配置To specify a build configuration for a database project

  1. 在“解决方案资源管理器” 中,右键单击要为其指定生成配置的数据库项目,然后选择“属性” 。In Solution Explorer, right-click the database project for which for which you want specify a build configuration, and select Properties.

  2. 在“生成” 选项卡上,使用“配置” 下拉列表指定要用于此项目的配置设置。On the Build tab, use the Configuration dropdown list to specify the configuration settings that you want to use for this project.

下表中的设置适用于此数据库项目的生成配置。The settings in the following table apply to build configurations of this database project.

字段Field 默认值Default value 描述Description
生成输出路径Build output path bin\Debug|指定生成或部署数据库项目时产生生成输出的位置。bin\Debug|Specifies where the build output is generated when you build or deploy the database project. 如果指定的是相对路径,则该路径必须是相对于数据库项目路径的路径。If you specify a relative path, you must specify it relative to the database project path. 如果路径不存在,则会创建一个。If the path does not exist, it is created.
生成输出文件名Build output file name DatabaseProjectName DatabaseProjectName 指定要为在生成数据库项目时所生成的输出赋予的名称Specifies the name that you want to give the output that is generated when you build the database project
将 Transact-SQL 警告视为错误Treat Transact-SQL warnings as errors No 指定出现 Transact-SQL 警告是否应导致取消生成和部署过程。Specifies whether a Transact-SQL warning should cause the build and deployment process to be canceled. 如果清除此复选框,则将显示警告,但生成和部署过程将继续。If this check box is cleared, warnings appear, but the build and deployment process continues. 此设置特定于项目而不是用户,并且存储在 .sqlproj 文件中。This setting is specific to the project, not the user, and is stored in the .sqlproj file.
禁止显示 Transact-SQL 警告Suppress Transact-SQL Warnings 空白Blank 指定一个以逗号或分号分隔的警告编号列表,这些编号标识禁止显示的警告。Specifies a list of warning numbers, delimited by commas or semi-colons that identify warnings that are suppressed.

即使选中了“将 Transact-SQL 警告视为错误” 复选框,禁止显示的警告也不会显示在“错误列表” 窗口中,并且不会影响生成操作成功完成。Suppressed warnings do not appear in the Error List window, and they do not affect the build success, even if you select the Treat Transact-SQL warnings as errors check box.

SQLCMD 变量SQLCMD Variables

在 SQL Server 数据库项目中,您可以使用 SQLCMD 变量提供要用于调试或发布的动态替换。In SQL Server Database Projects you can utilize SQLCMD variables to provide dynamic substitution to be used for debugging or publishing. 您输入变量名称和值,并且在生成过程中,将替换这些值。You enter the variable name and values and during build, the values will be substituted. 如果没有本地值,则会使用默认值。If there are no local values, the default value will be used. 通过在项目属性中输入这些变量,它们将在发布时自动提供并且存储于发布配置文件中。By entering these variables in project properties, they will automatically be offered in publishing and are stored in publishing profiles. 您可以通过“加载值”按钮,将这些变量的项目值拖入发布中。You can pull in the project values of the variables into publish via the Load Values button.

请确保在项目属性中输入正确的变量,因为不会针对项目中的脚本对这些变量进行验证,并且不自动填充在脚本中使用的变量。Make sure the right variables are entered in project properties, because these variables are not validated against a script in the project, nor are the variables used in script automatically populated.

此外,命令行发布还让您可以在命令行重写这些值或使用配置文件重写这些值。Additionally, command line publishing enables you to override these values at the command line or using a profile.

生成事件Build Events

使用这些设置可以指定要在生成操作开始之前执行的命令行以及要在生成操作完成之后执行的命令行。You can use these settings to specify a command line to execute before the build operation starts and a command line to execute after the build operation is completed.

字段Field 默认值Default value 描述Description
预生成事件命令行Pre-build event command line NoneNone 指定要在项目生成之前执行的命令行。Specifies the command line to execute before the project is built. 单击“编辑预生成事件” 可修改该命令行。Click Edit Pre-build to modify the command line.
生成后事件命令行Post-build event command line NoneNone 指定要在项目生成之后执行的命令行。Specifies the command line to execute after the project is built. 单击“编辑生成后事件” 可修改该命令行。Click Edit Post-build to modify the command line.
运行生成后事件Run the post-build event 成功生成时On successful build 指定生成后命令行应始终运行、仅在生成操作成功后运行还是仅在生成操作更新了项目输出(生成脚本)时运行。Specifies whether the post-build command line should be run always, only if the build was successful, or only when the build updated the project output (the build script).

调试Debug

可以使用这些设置来控制数据库项目的调试。You can use these settings to control the debugging of your database project.

字段Field 默认值Default value 描述Description
启动操作Start Action NoneNone 指定在调试您的项目时要运行的脚本或外部程序。Specifies a script or external program to run when you debug your project.
目标连接字符串Target Connection String Data Source=(localdb)\SolutionName;Initial Catalog=DatabaseProjectName;Integrated Security=True;Pooling=False;Connect Timeout=30Data Source=(localdb)\SolutionName;Initial Catalog=DatabaseProjectName;Integrated Security=True;Pooling=False;Connect Timeout=30 指定要用作指定生成配置的目标的数据库服务器的连接信息。Specifies the connection information for the database server that you want to target for the specified build configuration. 默认连接字符串针对动态创建的 SQL Server LocalDB 实例和数据库。The default connection string is against a dynamically created SQL Server LocalDB instance and database.
部署数据库属性Deploy database properties Yes 指定是否在部署数据库项目时部署或更新 DatabaseProerties.DatabaseProperties 设置。Specifies whether the DatabaseProerties.DatabaseProperties settings are deployed or updated when you deploy the database project.
始终重新创建数据库Always re-create database No 指定是否删除后重新创建数据库,而非执行增量升级。Specifies whether to drop and recreate the database instead of performing an incremental upgrade. 例如,如果你要针对数据库的干净部署运行数据库单元测试,则可能需要选中此复选框。You might want to select this check box if you want to run database unit tests against a clean deployment of the database, for example. 如果清除此复选框,则将更新现有数据库,而不是删除并重新创建数据库。If this check box is cleared, the existing database will be updated instead of dropped and re-created.
如果可能发生数据丢失则阻止增量部署Block incremental deployment if data loss might occur Yes 指定在更新可能会造成数据丢失的情况下是否应停止部署。Specifies whether deployment will stop if an update might cause data loss. 如果选中此复选框,则可能造成数据丢失的更改会导致部署因出现错误而停止,从而防止丢失数据。If this check box is selected, changes that would create data loss cause deployment to stop with an error, which keeps data from being lost. 例如,在将 varchar(50) 列更改为 varchar(30)时,部署将会停止。For example, deployment would stop if a varchar(50) column were changed to varchar(30).

注意:只有当可能发生数据丢失的表中包含数据时,才会阻止部署。NOTE: Deployment is blocked only if the tables where data loss might occur contain data. 如果不会丢失任何数据,则部署将继续。Deployment continues if no data would be lost.
DROP 目标中但不在项目中的对象DROP objects in target but not in project No 指定是否应将目标数据库中存在而数据库项目中不存在的对象作为部署脚本的一部分删除。Specifies whether objects that are in the target database but not in the database project should be dropped as part of the deployment script. 您可以排除项目中的一些文件以将它们暂时从生成脚本中移除。You can exclude some files in your project to temporarily remove them from your build script. 但是,您可能希望在目标数据库中保留这些对象的现有版本。However, you might want to leave the existing versions of those objects in the target database. 如果选中“始终重新创建数据库” 复选框,该复选框将没有任何作用,因为数据库会被删除。This check box has no effect if the Always re-create database check box is selected, because the database will be dropped.
不使用 ALTER ASSEMBLY 语句更新 CLR 类型Do not use ALTER ASSEMBLY statements to update CLR types No 指定在部署更改时,是否使用 ALTER ASSEMBLY 语句来更新公共语言运行时 (CLR) 类型,或者是否将删除并重新创建实例化 CLR 类型的对象。Specifies whether ALTER ASSEMBLY statements are used to update common language run-time (CLR) types or whether the object that instantiates the CLR type will instead be dropped and re-created when you deploy changes.
高级...Advanced... No 一种命令按钮,可用于指定控制部署的事件和行为的选项。Command button that allows you to specify options that control events and behavior for the deployment.

引用路径Reference Paths

使用此页,可以定义与跨数据库引用相关联的服务器变量和数据库变量。You can use this page to define the server and database variables that are associated with a cross-database reference. 此外,你可以指定这些变量的值。In addition, you can specify the values of those variables. 有关详细信息,请参阅 在数据库项目中使用引用For more information, see Using References in Database Projects.

代码分析Code Analysis

可以使用代码分析发现您的脚本中的潜在问题,例如设计、命名和性能问题。You can use Code Analysis to discover potential issues in your scripts, such as design, naming and performance problems. 数据库项目的规则组织成针对特定领域的预定义的规则集,并且您可以在 “项目属性” 属性页的 “代码分析” 选项卡中启用或禁用任何规则。Rules for database projects are organized into predefined rule sets that target specific areas, and you can enable or disable any rule in the Code Analysis tab of the Project Properties property page. 在同一个选项卡上,您可以指定代码分析以便在每次生成项目时自动运行,或者指定是否将警告视为错误。In the same tab, you can specify code analysis to be run automatically every time that a project is built, or whether warnings are treated as errors.

若要手动使用代码分析,请在“解决方案资源管理器” 中右键单击你的项目,然后选择“运行代码分析” 。To use Code Analysis manually, right-click your project in Solution Explorer and select Run Code Analysis. 代码分析警告在 “错误列表” 窗口中列出。Code analysis warnings are listed in the Error List window. 可以双击某一警告以便导航到包含该问题的源代码,并且可以通过使用“显示错误帮助” 上下文菜单查看警告的附加信息和可能的更正措施。You can double-click a warning to navigate to the source code that contains the issue, and you can view additional information and possible corrections for a warning by using the Show Error Help contextual menu. 有关代码分析的详细信息,请参阅分析数据库代码以提高代码质量For more information on Code Analysis, see Analyzing Database Code to Improve Code Quality.