What exactly are CreateDate and ModifyDate in sys.objects

女生的网名这么多〃 提交于 2020-01-24 19:26:05

问题


I've inherited the following admin query and run it from time to time with fully understanding what is it returning:

--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

What are the following fields?:

  1. "create_date" ...I'm guessing when "CREATE TABLE ..." was run
  2. "modify_date" ...Is this when the table schema was last altered?

Does either of them tell me the last time data was DELETED or INSERTED into the tables?
If not then how do I get this information?


回答1:


what BOL says

modify date - Date the object was last modified by using an ALTER statement. If the object is a table or a view, modify_date also changes when a clustered index on the table or view is created or altered.

so it is moment when someone added column or changed schema of the table

by default that information (when someone inserted/deleted value) is not stored

if you want the time when someone inserted a value into the table you have to implement it you can add ChangeDate datetime column into your table and add trigger wich would insert appopriate value, but it would not keep when data was deleted

typical if you want to log data changes you can implement it by creating similar table to the one you want to log , add columns like 'DataChange, operation, user' and implement DML Trigger for UPDATE, INSERT, DELETE

or use sql server change data for tracking data changes , but i personally never used that one : )



来源:https://stackoverflow.com/questions/14396750/what-exactly-are-createdate-and-modifydate-in-sys-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!