简体   繁体   中英

Cannot grant CHANGE TRACKING permission at database level

We have change tracking enabled on our SQL Server. The tables which are enabled for change tracking span multiple schemas. We can successfully execute the following to grant VIEW CHANGE TRACKING on the schema class, but we would like to grant this permission at the database level to cover all schemas. When attempting to grant at the database class level, it returns the following error. I am running the command in the context of the Test database. I can't find any documentation that would indicate this specific permission cannot be granted at this level.

Incorrect syntax near 'VIEW CHANGE TRACKING'.

-- Granting on schema class works
GRANT VIEW CHANGE TRACKING ON SCHEMA::dbo TO TestUser

-- Granting on database class fails
GRANT VIEW CHANGE TRACKING ON DATABASE::Test TO TestUser

Here's a script to generate the grant for all the schemas containing a change tracked table:

select distinct 'grant view change tracking on schema::' +quotename(schema_name(schema_id))+ ' to testuser;'
from sys.tables t
join sys.change_tracking_tables ct
  on t.object_id = ct.object_id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM