檢視SqlServer資料庫上面指令碼修改資訊以及修改日誌
阿新 • • 發佈:2019-02-14
只是檢視簡單的修改時間資訊,參照下面語句:
SELECT name
, create_date --建立時間
, modify_date --修改時間
FROM YarnStoreDB.sys.objects
WHERE type = 'P' --注意如果是函式則為fn
AND NAME='儲存過程名字'
ORDER BY modify_date DESC
檢視完整日誌資訊,參照如下語句:
SELECT ISNULL(NAME, '') AS [Action], ISNULL(DatabaseName, '') AS DatabaseName, ISNULL(NTUserName, '') AS NTUserName, ISNULL(HostName, '') AS HostName, ISNULL(ApplicationName, '') AS ApplicationName, ISNULL(LoginName, '') AS LoginName, ISNULL(StartTime, GETDATE()) AS StartTime, ISNULL(ObjectName, '') AS ObjectName --物件名字,如儲存過程名等 FROM ( SELECT NAME, T.* FROM sys.fn_trace_gettable( CONVERT( VARCHAR(150), ( SELECT TOP 1 f.[value] FROM sys.fn_trace_getinfo(NULL) f WHERE f.property = 2 ) ), DEFAULT ) T JOIN sys.trace_events TE ON T.EventClass = TE.trace_event_id ) A WHERE NAME LIKE 'Object%' AND DatabaseName <> 'TEMPDB' AND ObjectName IS NOT NULL AND ObjectName NOT LIKE '_WA_Sys%'