共用方式為


SQL 項目屬性

適用於:SQL ServerAzure SQL DatabaseAzure SQL 受控實例Microsoft Fabric 中的 SQL 資料庫

除了個別 .sql 檔案的內容之外,SQL Database 專案還包含定義專案行為和資料庫層級設定的屬性。 這些屬性會儲存在 .sqlproj 檔案中,而且可以直接編輯 .sqlproj 檔案來設定。 某些 SQL 專案工具,例如 Visual Studio 和 VS Code,提供在圖形使用者介面中編輯一些或多個專案屬性的存取權。 本文提供您可以針對 SQL 資料庫項目設定的屬性概觀。

常用的 SQL 專案屬性包括:

Disable database options changes

在 SQL 專案發佈期間,資料庫選項的變更會根據專案屬性中定義的值和預設專案值來編寫腳本。 若要防止在發佈期間修改資料庫選項,請使用 SqlPackage CLI 或 Visual Studio 之類的工具,將 publish 屬性設定為 false ScriptDatabaseOptions。 This setting can also be incorporated in a publish profile.

一般項目屬性

目標平臺 屬性會指定專案目標 SQL Server 的版本。 DSP 屬性可用來設定 SQL 專案的目標平臺。 如需目標平臺的詳細資訊,請參閱 目標平臺 一文。

程序代碼分析可藉由在開發生命週期早期攔截潛在問題,大幅改善持續整合和部署程式。 深入瞭解如何啟用程式代碼分析,並在 SQL 程式代碼分析 一文中包含自定義規則。

數據層應用程式屬性

下列屬性可用來定義在建置 SQL 專案時所建立的數據層應用程式 (DAC)。

  • DacApplicationName:資料層應用程式的名稱 .dacpac。 預設值為項目名稱。
  • DacDescription:資料層應用程式 .dacpac的選擇性描述。
  • DacVersion:資料層應用程式版本 .dacpac。 預設值為 1.0.0.0

默認架構

DefaultSchema 屬性會設定 SQL 專案的預設架構。 This property applies to 1-part named objects. 預設值為 dbo

T-SQL 警告

SuppressTSqlWarningsTreatTSqlWarningsAsErrors 屬性可控制在專案建置期間如何處理 T-SQL 警告。 SuppressTSqlWarnings 屬性會在專案建置期間隱藏 T-SQL 警告,指定為逗號分隔的錯誤編號清單。

TreatTSqlWarningsAsErrors 屬性會將 T-SQL 警告視為錯誤,這會導致建置因任何 T-SQL 警告而失敗。 TreatTSqlWarningsAsErrors 預設值為 False

項目屬性的範例使用方式

下列範例示範如何在 SQL 專案檔中設定 CompatibilityModeIsChangeTrackingOnTreatTSqlWarningsAsErrors 屬性。 CompatibilityMode 屬性會設定為 130IsChangeTrackingOn 屬性設定為 True,而 TreatTSqlWarningsAsErrors 屬性設定為 TrueTreatSqlWarningsAsErrors 屬性只會在 True 組建組態上設定為 Release

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
  <Sdk Name="Microsoft.Build.Sql" Version="1.0.0-rc1" />
  <PropertyGroup>
    <Name>AdventureWorks</Name>
    <DSP>Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider</DSP>
    <ModelCollation>1033, CI</ModelCollation>
    <ProjectGuid>{00000000-0000-0000-0000-000000000000}</ProjectGuid>
    <RunSqlCodeAnalysis>true</RunSqlCodeAnalysis>
    <CompatibilityMode>130</CompatibilityMode>
    <IsChangeTrackingOn>True</IsChangeTrackingOn>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)'=='Release'">
    <TreatTSqlWarningsAsErrors>True</TreatTSqlWarningsAsErrors>
  </PropertyGroup>
</Project>

所有項目屬性

某些項目屬性與僅適用於 SQL Server 資料庫或特定 SQL Server 版本的資料庫選項相關聯。 在專案中加入專案屬性之前,請先檢閱資料庫選項的相關文件,以瞭解屬性和資料庫需求的行為。

財產 DATABASE SET option UI label SQL 項目預設值 允許的值
AllowSnapshotIsolation ALLOW_SNAPSHOT_ISOLATION Database settings, Operational, Allow snapshot isolation {真|假}
AnsiNulls ANSI_NULLS Database settings, SET ANSI_NULLS True {真|假}
AnsiPadding ANSI_PADDING Database settings, SET ANSI_PADDING True {真|假}
AnsiWarnings(ANSI 警告) ANSI_WARNINGS Database settings, SET ANSI_WARNINGS True {真|假}
ArithAbort ARITHABORT Database settings, SET ARITHABORT True {真|假}
自動關閉 AUTO_CLOSE 資料庫設定、操作、自動關閉 {真|假}
AutoCreateStatistics (自動建立統計資料) AUTO_CREATE_STATISTICS 資料庫設定、操作、自動建立統計數據 True {真|假}
AutoCreateStatisticsIncremental AUTO_CREATE_STATISTICS (INCREMENTAL) 資料庫設定、運行、自動創建增量 {真|假}
自動縮小 AUTO_SHRINK 資料庫設定、操作、自動壓縮 {真|假}
AutoUpdateStatistics AUTO_UPDATE_STATISTICS 資料庫設定、操作、自動更新統計數據 True {真|假}
自動異步更新統計資料 AUTO_UPDATE_STATISTICS_ASYNC 資料庫設定、操作、自動異步更新統計數據 {真|假}
ChangeTrackingRetentionPeriod CHANGE_RETENTION Database settings, Operational, Change tracking retention period 2 {integer}
ChangeTrackingRetentionUnit CHANGE_RETENTION Database settings, Operational, Change tracking retention period MINUTES {天|小時|分鐘}
CloseCursorOnCommitEnabled CURSOR_CLOSE_ON_COMMIT Database settings, Operational, Close cursor on commit enabled {真|假}
相容模式 COMPATIBILITY_LEVEL 資料庫設定、相容性層級 {100|110|120|130|140|150|160|170}1
ConcatNullYieldsNull CONCAT_NULL_YIELDS_NULL Database settings, SET CONCAT_NULL_YIELDS_NULL True {真|假}
Containment CONTAINMENT 資料庫設定,限制 沒有 {NONE|PARTIAL}
DacApplicationName 數據層應用程式 (.dacpac) 屬性,名稱 專案名稱 {string}
DacDescription 數據層應用程式 (.dacpac) 屬性,描述 {string}
DacVersion 數據層應用程式 (.dacpac) 屬性,版本 1.0.0.0 {semantic version number}
DatabaseAccess db_user_access_option 資料庫設定、數據庫存取 MULTI_USER {多用戶|單用戶|限制用戶}
DatabaseChaining DB_CHAINING 資料庫設定、資料庫鏈結 {真|假}
DatabaseDefaultFulltextLanguage DEFAULT_FULLTEXT_LANGUAGE Database settings, Default fulltext language 1033 {integer language id}
資料庫預設語言 DEFAULT_LANGUAGE 資料庫設定、默認語言 1033 {integer language id}
DatabaseState db_state_option 資料庫設定、資料庫狀態 在線 {在線|離線}
DbScopedConfigLegacyCardinalityEstimation LEGACY_CARDINALITY_ESTIMATION 2 Database scoped configuration, Legacy cardinality estimation Off {關閉|開啟}
DbScopedConfigLegacyCardinalitySecondaryEstimation LEGACY_CARDINALITY_SECONDARY_ESTIMATION 2 Database scoped configuration, Legacy cardinality estimation for secondary Primary {Primary|Off|On}
DbScopedConfigParameterSniffing PARAMETER_SNIFFING 2 Database scoped configuration, Parameter sniffing On {開啟|關閉}
DbScopedConfigParameterSniffingSecondary PARAMETER_SNIFFING_SECONDARY 2 Database scoped configuration, Parameter sniffing for secondary Primary {Primary|Off|On}
DbScopedConfigOptimizerHotfixes OPTIMIZER_HOTFIXES 2 資料庫範圍設定、查詢最佳化程式修正補丁 Off {關閉|開啟}
DbScopedConfigOptimizerHotfixesSecondary OPTIMIZER_HOTFIXES_SECONDARY 2 Database scoped configuration, Query optimizer hotfixes for secondary Primary {Primary|Off|On}
DbScopedConfigMaxDOP MAXDOP 2 資料庫範圍設定、最大平行度 0 {integer}
DbScopedConfigMaxDOPSecondary MAXDOP_SECONDARY 2 Database scoped configuration, Max degrees of parallelism for secondary {integer}
DbScopedConfigDWCompatibilityLevel DW_COMPATIBILITY_LEVEL 2 資料庫範圍設定、DW 相容性層級 0 {0|10|20|30|40|50|9000}3
DefaultCollation COLLATE 4 資料庫設定、資料庫定序 SQL_Latin1_General_CP1_CI_AS 如需有效值,請參閱 SQL Server 定序名稱
DefaultCursor CURSOR_DEFAULT 資料庫設定、操作、預設游標 Local {Global|Local}
DefaultFilegroup 資料庫設定、操作、預設檔案群組 PRIMARY {string}
DefaultFileStreamFilegroup Database settings, Operational, Default filestream filegroup {string}
DefaultSchema 一般項目設定,默認架構 dbo {string}
DelayedDurability DELAYED_DURABILITY Database settings, Operational, Transactions delayed durability DISABLED {禁用|允許|強制}
數位訊號處理 (DSP) SQL 專案的 目標平臺 如需有效值,請參閱 目標平臺
啟用全文檢索 資料庫設定,啟用全文搜索 True {真|假}
文件流目錄名稱 FILESTREAM (DIRECTORY_NAME) 資料庫設定、FILESTREAM 目錄名稱 {string}
IsBrokerPriorityHonored HONOR_BROKER_PRIORITY Database settings, Broker priority honored {真|假}
IsChangeTrackingAutoCleanupOn CHANGE_TRACKING Database settings, Operational, Change tracking auto cleanup True {真|假}
IsChangeTrackingOn CHANGE_TRACKING 資料庫設定、運作、變更追蹤 {真|假}
加密是否已開啟 ENCRYPTION 資料庫設定,已啟用加密 {真|假}
IsLedgerOn LEDGER 4 資料庫設置,啟用帳本 {真|假}
IsNestedTriggersOn NESTED_TRIGGERS Database settings, Nested triggers enabled True {真|假}
IsTransformNoiseWordsOn TRANSFORM_NOISE_WORDS Database settings, Transform noise words {真|假}
MemoryOptimizedElevateToSnapshot MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT Database settings, Operational, Memory optimized elevate to snapshot {真|假}
ModelCollation 項目設定、定序 1033,CI {integer language id}, {CI|CS}
NonTransactedFileStreamAccess NON_TRANSACTED_ACCESS 資料庫設定、FILESTREAM 非交易存取 OFF {OFF|READ_ONLY|FULL}
NumericRoundAbort NUMERIC_ROUNDABORT Database settings, SET NUMERIC_ROUNDABORT {真|假}
輸出路徑 組建設定、輸出路徑 bin\Debugbin\Release {string}
頁面驗證 PAGE_VERIFY 資料庫設定、操作、頁面驗證 沒有 {NONE|TORN_PAGE_DETECTION|CHECKSUM}
參數化 PARAMETERIZATION 資料庫設定、參數化 簡單 {簡單|強制}
QueryStoreCaptureMode QUERY_STORE (QUERY_CAPTURE_MODE) Database settings, Operational, Query store capture mode ALL {OFF|ALL|AUTO}
QueryStoreDesiredState QUERY_STORE (OPERATION_MODE) Database settings, Operational, Query store operation mode OFF {OFF|READ_WRITE|READ_ONLY}
QueryStoreFlushInterval QUERY_STORE (DATA_FLUSH_INTERVAL_SECONDS) 資料庫設定、操作、查詢儲存區數據清除間隔(秒) 900 {integer}
QueryStoreIntervalLength QUERY_STORE (INTERVAL_LENGTH_MINUTES) 資料庫設定、操作、查詢儲存區間長度(分鐘) 60 {integer}
QueryStoreMaxPlansPerQuery QUERY_STORE (MAX_PLANS_PER_QUERY) Database settings, Operational, Query store max plans per query 200 {integer}
QueryStoreMaxStorageSize QUERY_STORE (MAX_STORAGE_SIZE_MB) 資料庫設定、操作、查詢存放區最大存儲大小(MB) 100 {integer}
QueryStoreStaleQueryThreshold QUERY_STORE (STALE_QUERY_THRESHOLD_DAYS) Database settings, Operational, Query store stale query threshold (days) 367 {integer}
QuotedIdentifier QUOTED_IDENTIFIER Database settings, SET QUOTED_IDENTIFIER True {真|假}
ReadCommittedSnapshot READ_COMMITTED_SNAPSHOT Database settings, Operational, Read committed snapshot {真|假}
恢復 RECOVERY 資料庫設定、操作、恢復 FULL {FULL|SIMPLE|BULK_LOGGED}
RecursiveTriggersEnabled (遞迴觸發器啟用) RECURSIVE_TRIGGERS 資料庫設定中已啟用遞迴觸發器 {真|假}
ServiceBrokerOption SERVICE_BROKER 資料庫設定、Service Broker 選項 DisableBroker {DisableBroker|EnableBroker|NewBroker|ErrorBrokerConversations}
SuppressTSqlWarnings 建置設定、隱藏 T-SQL 警告 (T-SQL 警告碼的逗號分隔清單) {string}
目標復原時間周期 資料庫設定、運作、目標復原時間(秒) 指定每個資料庫間接檢查點的頻率。 60 {integer}
TargetRecoveryTimeUnit 資料庫設定、作業、目標復原時間 SECONDS {分鐘、秒}
將T-SQL警告視為錯誤 建置設定,將 T-SQL 警告視為錯誤 {真|假}
值得 信賴 TRUSTWORTHY 資料庫設定,可信任 {真|假}
TwoDigitYearCutoff TWO_DIGIT_YEAR_CUTOFF Database settings, Two digit year cutoff 2049 {integer}
UpdateOptions db_update_option 資料庫設定、更新選項 READ_WRITE {READ_WRITE|READ_ONLY}
ValidateCasingOnIdentifiers General project setting, validate the casing of identifiers True {真|假}
  1. 預設值會根據引擎版本和伺服器設定而有所不同。
  2. 資料庫範圍組態 選項。
  3. AUTO 會設定為 0 值。
  4. 僅適用於 CREATE DATABASE選項