sql >> データベース >  >> RDS >> Sqlserver

SQLServerデータベース内のすべてのトリガーをテーブル名とテーブルのスキーマとともに一覧表示する必要があります

    1つの方法は次のとおりです:

    SELECT 
         sysobjects.name AS trigger_name 
        ,USER_NAME(sysobjects.uid) AS trigger_owner 
        ,s.name AS table_schema 
        ,OBJECT_NAME(parent_obj) AS table_name 
        ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate 
        ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete 
        ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert 
        ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter 
        ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
        ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled] 
    FROM sysobjects 
    
    INNER JOIN sysusers 
        ON sysobjects.uid = sysusers.uid 
    
    INNER JOIN sys.tables t 
        ON sysobjects.parent_obj = t.object_id 
    
    INNER JOIN sys.schemas s 
        ON t.schema_id = s.schema_id 
    
    WHERE sysobjects.type = 'TR' 
    

    編集 :AdventureWorks2008で動作するクエリのsysusersへの参加をコメントアウトしました。

    SELECT 
         sysobjects.name AS trigger_name 
        ,USER_NAME(sysobjects.uid) AS trigger_owner 
        ,s.name AS table_schema 
        ,OBJECT_NAME(parent_obj) AS table_name 
        ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate 
        ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete 
        ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert 
        ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter 
        ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
        ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled] 
    FROM sysobjects 
    /*
    INNER JOIN sysusers 
        ON sysobjects.uid = sysusers.uid 
    */  
    INNER JOIN sys.tables t 
        ON sysobjects.parent_obj = t.object_id 
    
    INNER JOIN sys.schemas s 
        ON t.schema_id = s.schema_id 
    WHERE sysobjects.type = 'TR' 
    

    編集2 :SQL2000の場合

    SELECT 
         o.name AS trigger_name 
        ,'x' AS trigger_owner 
        /*USER_NAME(o.uid)*/ 
        ,s.name AS table_schema 
        ,OBJECT_NAME(o.parent_obj) AS table_name 
        ,OBJECTPROPERTY(o.id, 'ExecIsUpdateTrigger') AS isupdate 
        ,OBJECTPROPERTY(o.id, 'ExecIsDeleteTrigger') AS isdelete 
        ,OBJECTPROPERTY(o.id, 'ExecIsInsertTrigger') AS isinsert 
        ,OBJECTPROPERTY(o.id, 'ExecIsAfterTrigger') AS isafter 
        ,OBJECTPROPERTY(o.id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
        ,OBJECTPROPERTY(o.id, 'ExecIsTriggerDisabled') AS [disabled] 
    FROM sysobjects AS o 
    /*
    INNER JOIN sysusers 
        ON sysobjects.uid = sysusers.uid 
    */  
    INNER JOIN sysobjects AS o2 
        ON o.parent_obj = o2.id 
    
    INNER JOIN sysusers AS s 
        ON o2.uid = s.uid 
    
    WHERE o.type = 'TR'
    


    1. 複数のテーブルへの外部キー

    2. T-SQL-=とasを使用したエイリアシング

    3. SQLServerデータベースサイズを選択します

    4. MariaDBでのSEC_TO_TIME()のしくみ