feat: add mssql triggers to analyser

This commit is contained in:
Nybkox
2024-12-12 19:05:02 +01:00
parent 4cc0a66a7d
commit 62daa13e54
3 changed files with 44 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ const functionParameters = require('./functionParameters');
const viewColumns = require('./viewColumns');
const indexes = require('./indexes');
const indexcols = require('./indexcols');
const triggers = require('./triggers');
module.exports = {
columns,
@@ -28,4 +29,5 @@ module.exports = {
indexes,
indexcols,
tableSizes,
triggers,
};

View File

@@ -0,0 +1,28 @@
module.exports = `
SELECT
o.modify_date as modifyDate,
o.object_id as objectId,
o.name AS triggerName,
s.name AS schemaName,
OBJECT_NAME(o.parent_object_id) AS tableName,
CASE
WHEN OBJECTPROPERTY(o.object_id, 'ExecIsAfterTrigger') = 1 THEN 'AFTER'
WHEN OBJECTPROPERTY(o.object_id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF'
ELSE 'BEFORE'
END AS triggerTiming,
CASE
WHEN OBJECTPROPERTY(o.object_id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT'
WHEN OBJECTPROPERTY(o.object_id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE'
WHEN OBJECTPROPERTY(o.object_id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE'
END AS triggerEvent,
OBJECT_DEFINITION(o.object_id) AS definition
FROM sys.objects o
INNER JOIN sys.tables t
ON o.parent_object_id = t.object_id
INNER JOIN sys.schemas s
ON t.schema_id = s.schema_id
WHERE o.type = 'TR'
AND o.is_ms_shipped = 0
AND o.object_id =OBJECT_ID_CONDITION
AND s.name =SCHEMA_NAME_CONDITION
`;