Я использую проект базы данных SSDT для создания сценариев развертывания для моей базы данных. Один из триггеров, [trddl_GrantUserRights], изменяется при каждом запуске развертывания. Ничего не изменилось в определении триггера в файлах проекта. Определение триггера:
ALTER trigger [trddl_GrantUserRights] ON DATABASE
WITH EXECUTE AS 'dbo'
FOR DDL_DATABASE_LEVEL_EVENTS
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Cmd varchar(250)
/* InterfaceDeveloperUsers ve InterfaceDeveloperUsers rolleri db_datareader ve db_datawriter rollerini kapsadığından bu bölüme gerek kalmamıştır.
IF EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(100)')='CREATE_TABLE'
OR EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(100)')='CREATE_VIEW'
BEGIN
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceAnalistUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT SELECT,VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceAnalistUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceDeveloperUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT SELECT,UPDATE,DELETE,INSERT,VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceDeveloperUsers]'
EXEC (@Cmd)
END
END
*/
IF EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(100)')='CREATE_PROCEDURE'
BEGIN
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceAnalistUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceAnalistUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceDeveloperUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT EXECUTE,VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceDeveloperUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'PusulaUser' AND type = 'S')
BEGIN
SET @Cmd = 'GRANT EXECUTE ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [PusulaUser]'
EXEC (@Cmd)
END
END
IF EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(100)')='CREATE_FUNCTION'
BEGIN
IF EVENTDATA().value('(/EVENT_INSTANCE/ObjectType)[1]','nvarchar(100)')='TF'
BEGIN
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceAnalistUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT SELECT,VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceAnalistUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceDeveloperUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT SELECT,VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceDeveloperUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'PusulaUser' AND type = 'S')
BEGIN
SET @Cmd = 'GRANT SELECT ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [PusulaUser]'
EXEC (@Cmd)
END
END
IF EVENTDATA().value('(/EVENT_INSTANCE/ObjectType)[1]','nvarchar(100)')='FN'
BEGIN
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceAnalistUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceAnalistUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceDeveloperUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT EXECUTE,VIEW DEFINITION ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [InterfaceDeveloperUsers]'
EXEC (@Cmd)
END
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'PusulaUser' AND type = 'S')
BEGIN
SET @Cmd = 'GRANT EXECUTE ON [' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + '].[' + EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)') + '] TO [PusulaUser]'
EXEC (@Cmd)
END
END
END
IF EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(100)')='CREATE_SCHEMA'
BEGIN
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'InterfaceDeveloperUsers' AND type = 'R')
BEGIN
SET @Cmd = 'GRANT ALTER ON SCHEMA::' + EVENTDATA().value('(/EVENT_INSTANCE/SchemaName)[1]','nvarchar(100)') + ' TO [InterfaceDeveloperUsers]'
EXEC (@Cmd)
END
END
END;