2022-04-21 10:19:37 +03:00
|
|
|
CREATE OR ALTER TRIGGER #{qualifiedTriggerName}
|
|
|
|
ON #{qualifiedTableName}
|
|
|
|
AFTER DELETE
|
2022-11-29 20:41:41 +03:00
|
|
|
#{replicationClause}
|
2022-04-21 10:19:37 +03:00
|
|
|
AS
|
|
|
|
BEGIN
|
|
|
|
DECLARE @json NVARCHAR(MAX)
|
|
|
|
SET @json = (
|
2022-11-29 20:41:41 +03:00
|
|
|
SELECT
|
2022-04-21 10:19:37 +03:00
|
|
|
#{deliveryColsSQLExpression}, NULL as [payload.data.new],
|
|
|
|
'#{operation}' as [payload.op],
|
|
|
|
'#{schemaName}' as [schema_name],
|
|
|
|
'#{tableName}' as [table_name],
|
|
|
|
'#{triggerNameText}' as [trigger_name]
|
|
|
|
FROM DELETED
|
|
|
|
FOR JSON PATH, INCLUDE_NULL_VALUES
|
|
|
|
)
|
|
|
|
|
|
|
|
insert into hdb_catalog.event_log (schema_name,table_name,trigger_name,payload)
|
|
|
|
select * from OPENJSON (@json)
|
|
|
|
WITH(
|
|
|
|
schema_name NVARCHAR(MAX) '$.schema_name',
|
|
|
|
table_name NVARCHAR(MAX) '$.table_name',
|
|
|
|
trigger_name NVARCHAR(MAX) '$.trigger_name',
|
|
|
|
[payload] NVARCHAR(MAX) AS JSON
|
|
|
|
)
|
|
|
|
|
|
|
|
END;
|