2

I have database in SQL Server 2008 with triggers on almost every table. I need to review tables without active triggers.
How to get list of all tables without any active triggers (tables without any triggers or those tables where all triggers are disabled)?

4

1 回答 1

5

sys.tables您可以在和之间进行反半连接sys.triggers

例如与NOT IN

SELECT *
FROM   sys.tables
WHERE  object_id NOT IN (SELECT parent_id
                         FROM   sys.triggers
                         WHERE  is_disabled = 0)

或者NOT EXISTS

SELECT *
FROM   sys.tables t
WHERE  NOT EXISTS (SELECT *
                   FROM   sys.triggers tr
                   WHERE  is_disabled = 0
                          AND tr.parent_id = t.object_id) 

sys.tables.object_id两者或 都不能sys.triggers.parent_id为空,在这种情况下,两者都给出相同的语义和计划

于 2013-06-06T18:21:24.687 回答