摘要:SQL - 取得 Database 的預存程序資訊
此篇文章的用意與專案有關,其用意是收集資料庫中有哪些預存程序名稱、傳入與傳出的參數,以及相關屬性資訊。為什麼要這做呢!? 呵呵,這就跟專案有關係了,在此就不方便多說,不過透過以下的語法,確實可以一目瞭然的得到預存程序資訊,不管在管理上或查閱上,都多了一點便利性,以下就是程式碼...
T-SQL:
SELECT A.[NAME] AS '結構敘述',
B.[NAME] AS '預存程序名稱',
C.[NAME] AS '預存程序傳入參數',
C.[PARAMETER_ID] AS '傳入參數順序',
D.[NAME] AS '傳入參數型別',
C.[MAX_LENGTH] AS '長度',
C.[PRECISION] AS '精確度',
C.[IS_OUTPUT] AS '傳出參數',
B.[CREATE_DATE] AS '建立時間',
B.[MODIFY_DATE] AS '修改時間'
FROM SYS.SCHEMAS A INNER JOIN SYS.PROCEDURES B
ON A.[SCHEMA_ID] = B.[SCHEMA_ID]
INNER JOIN SYS.PARAMETERS C
ON B.[OBJECT_ID] = C.[OBJECT_ID]
INNER JOIN SYS.TYPES D
ON C.[SYSTEM_TYPE_ID] = D.[SYSTEM_TYPE_ID] AND C.[USER_TYPE_ID] = D.[USER_TYPE_ID]
WHERE B.[TYPE] = 'P'
ORDER BY A.[NAME], B.[NAME], C.[PARAMETER_ID] ASC
結果:
以北風資料庫為例
參考:
sys.schemas (Transact-SQL)
sys.procedures (Transact-SQL)
sys.parameters (Transact-SQL)
sys.types (Transact-SQL)