sys.objects 中的 CreateDate 和 ModifyDate 到底是什么

why*_*heq 2 sql sql-server sql-server-2008-r2

我继承了以下管理查询,并在完全理解它返回的内容的情况下不时运行它:

--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
Run Code Online (Sandbox Code Playgroud)

以下字段是什么?:

  1. “create_date”...我猜是什么时候运行“CREATE TABLE ...”
  2. "modify_date" ...这是表架构上次更改的时间吗?

他们中的任何一个告诉我上次数据是DELETEDINSERTED进入表格的时间吗?
如果没有,那么我如何获得这些信息?

WKo*_*dos 6

BOL怎么说

修改日期 - 上次使用 ALTER 语句修改对象的日期。如果对象是表或视图,则当创建或更改表或视图上的聚集索引时, modify_date 也会更改。

所以现在是有人添加列或更改表架构的时刻

默认情况下,不存储信息(当有人插入/删除值时)

如果您想要某人将值插入表中的时间,您必须实现它,您可以将ChangeDate datetime列添加到表中并添加触发器,这将插入适当的值,但在删除数据时不会保留

通常,如果您想记录数据更改,您可以通过创建与您想记录的表类似的表来实现它,添加诸如“DataChange、操作、用户”之类的列并实现用于更新、插入、删除的 DML 触发器

或使用 sql server 更改数据来跟踪数据更改,但我个人从未使用过那个 :)