Sybase 資料一覧

トリガ情報を参照する

2007/9/28更新

対応バージョン: 11.9.2

トリガはデータベースオブジェクトとしてsysobjectsテーブルに格納されている。

sysobjectsテーブルのtypeカラムが"TR"となっているものがトリガである。

1> select * from sysobjects where type = "TR"
2> go
 name  id    uid type ...
 ----- ----- --- ---- ...
 trig1 63433   1 TR   ...
 :

各トリガのソースはsyscommentsに格納されている。

1> select * from syscomments
2> go
 id    number colid texttype language text                   colid2 status  
 ----- ------ ----- -------- -------- ---------------------- ------ ------
 63433      0     1        0        0 create trigger trig1        0 NULL
                                      on test
                                      for delete
                                      as
                                      begin
                                        rollback transaction
                                        print "can't delete record"
                                      end
 :

トリガのソースのみを表示したい場合はsp_helptextを使用する。

sp_helptext <トリガ>

sp_helpを使用するとトリガについてのレポートを取得できる。

1> sp_help delixderdef
2> go
 Name   Owner  Type
 ------ ------ ---------
 trig1  dbo    trigger

 Data_located_on_segment When_created
 ----------------------- -------------------
 not applicable          Mar 17 2000  9:22AM

テーブルに関連付けられているトリガの一覧を表示するにはchecktrigを使用する。

1> checktrig <テーブル>
2> go
 Trigger_name Owner
 ------------ ----- 
 trig1        dbo
 trig2        dbo
 trig3        dbo

また、逆にトリガに関連付けられているオブジェクトを表示するにはsp_dependsを使用する。

1> sp_depends <トリガ>
2> go
 Things the object references in the current database.
 object      type             updated selected
 ----------- ---------------- ------- ----------
 dbo.test    user table       no      no
 dbo.test2   user table       no      no
 dbo.sp_test stored procedure no      no