跨資料庫擁有權鏈結伺服器組態選項cross db ownership chaining Server Configuration Option

適用於: 是SQL Server 否Azure SQL Database 否Azure Synapse Analytics (SQL DW) 否平行處理資料倉儲 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

使用 [跨資料庫擁有權鏈結] 選項,可為 MicrosoftMicrosoft SQL ServerSQL Server 的執行個體設定跨資料庫擁有權鏈結。Use the cross db ownership chaining option to configure cross-database ownership chaining for an instance of MicrosoftMicrosoft SQL ServerSQL Server.

此伺服器選項允許您在資料庫層級控制跨資料庫擁有權鏈結,或允許所有資料庫的跨資料庫擁有權鏈結:This server option allows you to control cross-database ownership chaining at the database level or to allow cross-database ownership chaining for all databases:

  • 當執行個體的 [跨資料庫擁有權鏈結] 設定為關閉 (0) 時,所有資料庫的跨資料庫擁有權鏈結都會停用。When cross db ownership chaining is off (0) for the instance, cross-database ownership chaining is disabled for all databases.

  • 當執行個體的 [跨資料庫擁有權鏈結] 設定為開啟 (1) 時,所有資料庫的跨資料庫擁有權鏈結都會開啟。When cross db ownership chaining is on (1) for the instance, cross-database ownership chaining is on for all databases.

  • 您可以使用 ALTER DATABASE 陳述式的 SET 子句,來設定個別資料庫的跨資料庫擁有權鏈結。You can set cross-database ownership chaining for individual databases using the SET clause of the ALTER DATABASE statement. 若您要建立新的資料庫,您可以使用 CREATE DATABASE 陳述式,來為新的資料庫設定跨資料庫擁有權鏈結選項。If you are creating a new database, you can set the cross-database ownership chaining option for the new database using the CREATE DATABASE statement.

    除非 SQL ServerSQL Server 執行個體所裝載的資料庫都必須參與跨資料庫擁有權鏈結,而且您了解此設定的安全性含意,否則不建議將 [跨資料庫擁有權鏈結] 設定為 1。Setting cross db ownership chaining to 1 is not recommended unless all of the databases hosted by the instance of SQL ServerSQL Server must participate in cross-database ownership chaining and you are aware of the security implications of this setting.

若要判斷跨資料庫擁有權鏈結的目前狀態,請執行下列查詢:To determine the current status of cross-database ownership chaining, execute the following query:

SELECT is_db_chaining_on, name FROM sys.databases;

若結果為 1,表示已啟用跨資料庫擁有權鏈結。A result of 1 indicates that cross-database ownership chaining is enabled.

控制跨資料庫擁有權鏈結Controlling Cross-Database Ownership Chaining

在開啟或關閉跨資料庫擁有權鏈結之前,請考量下列事項:Before turning cross-database ownership chaining on or off, consider the following:

  • 您必須是 系統管理員 固定伺服器角色的成員,才能開啟或關閉跨資料庫擁有權鏈結。You must be a member of the sysadmin fixed server role to turn cross-database ownership chaining on or off.

  • 在產品伺服器上關閉跨資料庫擁有權鏈結,請完整測試所有的應用程式 (包含協力廠商應用程式),才能確定變更不會影響應用程式功能。Before turning off cross-database ownership chaining on a production server, fully test all applications, including third-party applications, to ensure that the changes do not affect application functionality.

  • 若您以 sp_configure 來指定 RECONFIGURE,當伺服器執行時,您可以變更 [跨資料庫擁有權鏈結] 選項。You can change the cross db ownership chaining option while the server is running if you specify RECONFIGURE with sp_configure.

  • 若您有資料庫需要跨資料庫擁有權鏈結,建議您使用 sp_configure 來關閉執行個體的 [跨資料庫擁有權鏈結] 選項,再使用 ALTER DATABASE 陳述式來為有需要的個別資料庫,開啟跨資料庫擁有權鏈結。If you have databases that require cross-database ownership chaining, the recommended practice is to turn off the cross db ownership chaining option for the instance using sp_configure; then turn on cross-database ownership chaining for individual databases that require it using the ALTER DATABASE statement.

另請參閱See Also

ALTER DATABASE (Transact-SQL) ALTER DATABASE (Transact-SQL)
CREATE DATABASE (SQL Server Transact-SQL) CREATE DATABASE (SQL Server Transact-SQL)
伺服器組態選項 (SQL Server) Server Configuration Options (SQL Server)
sp_configure (Transact-SQL) sp_configure (Transact-SQL)
RECONFIGURE (Transact-SQL)RECONFIGURE (Transact-SQL)