First learn : Tricks For Document Delete Protection On Trigger
[sql]
CREATE PROCEDURE [System].[Utility.GenerateTriggerDeleteProtect]
@TableName NVARCHAR(250)
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@SQL NVARCHAR(MAX)
IF NOT EXISTS
(
SELECT TOP 1
name
FROM sys.triggers
WHERE parent_id = OBJECT_ID(@TableName)
)
BEGIN
SET @SQL = '
CREATE TRIGGER '+REPLACE(@TableName,']','.DeleteProtect]')+'
ON '+@TableName+'
Instead of DELETE
AS
BEGIN
SET NOCOUNT ON;
delete from '+@TableName+' where doc_id in (select doc_id from deleted where docflow_seq=0)
END'
EXEC sp_executesql @SQL
PRINT 'Create delete protect trigger for '+@TableName
END
END
[/sql]
[sql]
CREATE PROCEDURE [System].[Utility.GenerateTriggerDeleteProtect]
@TableName NVARCHAR(250)
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@SQL NVARCHAR(MAX)
IF NOT EXISTS
(
SELECT TOP 1
name
FROM sys.triggers
WHERE parent_id = OBJECT_ID(@TableName)
)
BEGIN
SET @SQL = '
CREATE TRIGGER '+REPLACE(@TableName,']','.DeleteProtect]')+'
ON '+@TableName+'
Instead of DELETE
AS
BEGIN
SET NOCOUNT ON;
delete from '+@TableName+' where doc_id in (select doc_id from deleted where docflow_seq=0)
END'
EXEC sp_executesql @SQL
PRINT 'Create delete protect trigger for '+@TableName
END
END
[/sql]
Komentar
Posting Komentar