SQL 服务器 sys.tables 捕获不正确 modify_date

SQL Server sys.tables not capturing correct modify_date

上下文: 我有一个 ETL 过程设置,使用 Python 脚本在数据仓库中填充 tables。该脚本通过 sqlalchemy 执行截断语句以清空每个 table,然后使用 pandas .to_sql 方法从数据帧加载新的源数据。请参阅以下代码段:

engine.execute(sa_text(f'''TRUNCATE TABLE {schema}.{table}''').execution_options(autocommit=True))
df.to_sql(table, con=engine, schema=schema, if_exists='append', index=False, chunksize=chunksize,
          method=method)

问题:奇怪的是,SQL服务器的sys.tablesmodify_date列的每个table 未捕获反映最新 modify_date 的 table 更改。有人可以向我解释这是为什么以及我如何修改我的 Python 代码和/或 SQL 服务器设置以准确捕获 sys.tables[=23= 中的更改]?

modify_date 不捕获 TRUNCATE(或 对数据 的任何更改)。来自 the documentation on sys.objects(这是 sys.tables 获取其列的位置):

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 an index on the table or view is created or altered.

SQL 默认情况下,服务器不跟踪数据修改,而且您似乎只是在专门跟踪这些截断操作之后,在这种情况下,我建议您的应用程序记录 table写入每个操作成功(或失败,我想)。