如何去查看一支預存程序,Trigger,Function的指令 龐大的商業邏輯2千行起跳的預存程序 在這麼大串程式中 若要去查看其完整定義 透過T-SQL的 exec sp_helptext {SP名稱|Trigger名稱|Function名稱} 就可陳列出來 而若要針對此段,保留有用到特定某關鍵字的篩選 類似Visual Studio IDE的尋找參考 可使用到之前用過的2個技巧 1.暫存表 2.欄位trim 這邊用openrowset來去接exec 預存程序的回傳 1 2 3 4 5 6 7 8 9 10 11 IF Object_id( 'tempdb..#tmp_table' ) IS NOT NULL BEGIN DROP TABLE #tmp_table END select a. Text as cmd into #tmp_table from openrowset( 'SQLNCLI' , 'Server={DB主機};Trusted_Connection=yes;' , 'SET NOCOUNT ON;SET FMTONLY OFF;exec sp_helptext {SP名|trigger名|function名}' ) AS a; select LTRIM(RTRIM( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE (cmd, CHAR ( 0 ), CHAR ( 32 )), CHAR ( 9 ), CHAR ( 32 )) , CHAR ( 10 ), CHAR ( 32 )), CHAR ( 11 ), CHAR ( 32 )), CHAR ( 12 ), CHAR ( 32 )), CHAR ( 13 ), CHAR ( 32 )), CHAR ( 14 ), CHAR ( 32 )))) from #tmp_table where cmd like '%{關鍵字}%' Ref: "SELECT * INTO table FROM" a stored procedure?