TRUSTWORTHY 数据库属性TRUSTWORTHY Database Property

适用于: 是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: YesSQL Server NoAzure SQL Database NoAzure Synapse Analytics (SQL DW) NoParallel Data Warehouse

TRUSTWORTHY 数据库属性用于指明 SQL ServerSQL Server 实例是否信任该数据库以及其中的内容。The TRUSTWORTHY database property is used to indicate whether the instance of SQL ServerSQL Server trusts the database and the contents within it. 默认情况下,此设置为 OFF,但是可以使用 ALTER DATABASE 语句将其设置为 ON。By default, this setting is OFF, but can be set to ON by using the ALTER DATABASE statement. 例如,ALTER DATABASE AdventureWorks2012 SET TRUSTWORTHY ON;For example, ALTER DATABASE AdventureWorks2012 SET TRUSTWORTHY ON;.

备注

必须是 sysadmin 固定服务器角色的成员才能设置此选项。To set this option, you must be a member of the sysadmin fixed server role.

此属性可用于减少附加数据库所带来的某些隐患,该数据库包含下列对象之一:This property can be used to reduce certain threats that can exist as a result of attaching a database that contains one of the following objects:

这两种情况均要求具有特定程度的权限,并且在已附加到 SQL ServerSQL Server实例的数据库的上下文中使用这两种情况时,应采取相应的机制保护这两种情况。Both of these situations require a specific degree of privileges and are protected against by appropriate mechanisms when they are used in the context of a database that is already attached to an instance of SQL ServerSQL Server. 但是,如果数据库脱机,则对数据库文件具有访问权限的用户可能会将其附加到其选择的 SQL ServerSQL Server 实例,并将有害内容添加到数据库中。However, if the database is taken offline, a user that has access to the database file can potentially attach it to an instance of SQL ServerSQL Server of his or her choice and add malicious content to the database. SQL ServerSQL Server中分离和附加数据库时,将对限制访问数据库文件的数据和日志文件设置某些权限。When databases are detached and attached in SQL ServerSQL Server, certain permissions are set on the data and log files that restrict access to the database files.

因为无法立即信任附加到 SQL ServerSQL Server 实例的数据库,所以不允许数据库访问超出数据库范围的资源,直到数据库已显式标记为可信。Because a database that is attached to an instance of SQL ServerSQL Server cannot be immediately trusted, the database is not allowed to access resources beyond the scope of the database until the database is explicitly marked trustworthy. 因此,如果备份或分离 TRUSTWORTHY 选项设置为 ON 的数据库并将该数据库附加或还原到同一个或另一个 SQL Server 实例,则附加/还原完成后 TRUSTWORTHY 属性将设置为 OFF。Therefore, if you backup or detach a database that has the TRUSTWORTHY option ON and you attach or restore the database to the same or another SQL Server instance, the TRUSTWORTHY property will be set to OFF upon attach/restore completion. 此外,旨在访问数据库以外资源的模块和带有 EXTERNAL_ACCESS 或 UNSAFE 权限设置的程序集还需要其他条件才能成功运行。Also, modules that are designed to access resources outside the database, and assemblies with either the EXTERNAL_ACCESS and UNSAFE permission setting, have additional requirements in order to run successfully.

SQL Server 数据库引擎和 Azure SQL Database 的安全中心Security Center for SQL Server Database Engine and Azure SQL Database

ALTER DATABASE (Transact-SQL)ALTER DATABASE (Transact-SQL)