SQL查詢某內容來自於哪個儲存過程或觸發器

2021-10-23 05:12:22 字數 1271 閱讀 4193

在做erp運維的工作中,偶爾會遇到使用者使用系統過程**現一些錯誤提示,這時什麼快速查到報錯的源頭呢?可以用***跟蹤,找出報錯的原因,下面是根據報錯內容,查到提示來自於系統裡的哪個儲存過程或觸發器。

---檢視某內容來自於某個儲存過程

select name from sysobjects o, syscomments s

where o.id = s.id

and text like '%報錯內容%'

and o.xtype = 'p'

如果是觸發器把o.xtype 改為:tr

--查詢存在某內容的儲存過程名稱及儲存過程內容

select routine_name, routine_definition 

from information_schema.routines 

where routine_definition like '%你要查詢的內容%' 

and routine_type='procedure'

-----------檢視某內容來自哪個表裡的觸發器。

with tr as (

select name from sysobjects o, syscomments s

where o.id = s.id  

and text like '%報錯內容%'

and o.xtype = 'tr'

),tr_table as (select triggers.name as tr_name,tables.name as table_name,triggers.is_disabled as jy_yn,

triggers.is_instead_of_trigger as tr_type,

case when triggers.is_instead_of_trigger = 1 then 'instead of'

when triggers.is_instead_of_trigger = 0 then 'after'

else null

end as tr_ms

from sys.triggers triggers

inner join sys.tables tables on triggers.parent_id = tables.object_id

where triggers.type ='tr'

--order by triggers.create_date

)select * from tr a

left join tr_table b on a.name=tr_name

SQL 查詢存在某內容的儲存過程都有哪些

查詢存在某錶名的儲存過程 select distinct b.name from syscomments a,sysobjects b where a.id b.id and a.text like 你要查詢的表名 查詢存在某內容的儲存過程 select name from sysobjects o...

SQL 查詢存在某內容的儲存過程都有哪些

查詢存在某錶名的儲存過程 select distinct b.name from syscomments a,sysobjects b where a.id b.id and a.text like 你要查詢的表名 查詢存在某內容的儲存過程 select name from sysobjects o...

SQL之查詢某幾行記錄 分頁查詢

oracle 1 查詢前10行 select from sc objects where rownum 10 2 利用minus 查詢10到20行 select from sc objects where rownum 20 minus select from sc objects where ro...