簡體   English   中英

sys.objects中究竟是CreateDate和ModifyDate是什么

[英]What exactly are CreateDate and ModifyDate in sys.objects

我繼承了以下管理查詢,並在完全了解返回結果的基礎上不時運行它:

--Loop until the Cursor was not able to fetch
WHILE (@@Fetch_Status >= 0)
BEGIN
    --Dump the results of the sp_spaceused query to the temp table
    INSERT  #TempTable
        EXEC sp_spaceused @TableName

    --Get the next table name
    FETCH NEXT FROM tableCursor INTO @TableName
END

--get rid of the Cursor
CLOSE tableCursor
DEALLOCATE tableCursor



--Select TABLE properties with SIZE -- Final step
SELECT name, 
convert(date,create_date) as CreateDate, 
convert(date,modify_date) as ModifyDate, 
numberofRows, 
dataSize

FROM sys.objects
join #temptable tm on
tm.tablename = sys.objects.name
WHERE type  in ('U')

order by modify_date 
GO

以下是哪些字段?:

  1. “ create_date” ...我猜想何時運行“ CREATE TABLE ...”
  2. “ modify_date” ...上次更改表架構時是這樣嗎?

無論是否他們告訴我最后一次數據DELETEDINSERTED到表?
如果沒有,我如何獲得此信息?

布爾

修改日期-使用ALTER語句最后修改對象的日期。 如果對象是表或視圖,則在創建或更改表或視圖上的聚集索引時,modify_date也會更改。

因此,當有人添加列或更改表的架構時

默認情況下,不存儲信息(當有人插入/刪除值時)

如果您希望有人在表中插入一個值的時間,您必須實現它,可以將ChangeDate datetime列添加到表中,並添加觸發器,這樣會插入適當的值,但是在刪除數據時不會保留

通常,如果要記錄數據更改,則可以通過創建與要記錄的表相似的表來實現它,添加“ DataChange,operation,user”等列,並對UPDATE,INSERT,DELETE實現DML觸發器

或使用sql server change數據來跟蹤數據更改,但我個人從未使用過該方法:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM