哪些表正在使用更改跟踪

时间:2013-11-22 00:39:46

标签: sql-server-2008-r2

我的备份失败:由于错误2601,无法将提交表刷新到dbid 12中的磁盘。请查看错误日志以获取更多信息。

我的数据库已启用更改跟踪。如何确定启用哪些表?我已经看过50+了,找不到带有它的那些。 sql 2008 r2

由于

2 个答案:

答案 0 :(得分:28)

要查找启用了更改跟踪的表,请对跟踪的数据库执行以下脚本

SELECT s.name AS Schema_name, t.name AS Table_name 
FROM sys.change_tracking_tables ctt
JOIN sys.tables t 
    ON t.object_id = ctt.object_id
JOIN sys.schemas s
    ON s.schema_id = t.schema_id
ORDER BY s.name, t.name

enter image description here

您可以在此处找到有关更改跟踪的有用系统视图的更多详细信息:

sys.change_tracking_tables (Transact-SQL)

sys.change_tracking_databases (Transact-SQL)

答案 1 :(得分:2)

这是Brent Ozar的一个查询,它提供了一个由变更跟踪维护的隐藏表的列表,用于存储更改,CT中涉及的表格在这些隐藏表格中占用的行和空间。

enter image description here

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
GO

SELECT 
   sct1.name AS CT_schema,
   sot1.name AS CT_table,
   ps1.row_count AS CT_rows,
   ps1.reserved_page_count*8./1024. AS CT_reserved_MB,
   sct2.name AS tracked_schema,
   sot2.name AS tracked_name,
   ps2.row_count AS tracked_rows,
   ps2.reserved_page_count*8./1024. AS tracked_base_table_MB,
   change_tracking_min_valid_version(sot2.object_id) AS min_valid_version
FROM sys.internal_tables it
JOIN sys.objects sot1 ON it.object_id=sot1.object_id
JOIN sys.schemas AS sct1 ON sot1.schema_id=sct1.schema_id
JOIN sys.dm_db_partition_stats ps1 ON it.object_id = ps1. object_id AND ps1.index_id in (0,1)
LEFT JOIN sys.objects sot2 ON it.parent_object_id=sot2.object_id
LEFT JOIN sys.schemas AS sct2 ON sot2.schema_id=sct2.schema_id
LEFT JOIN sys.dm_db_partition_stats ps2 ON sot2.object_id = ps2. object_id AND ps2.index_id in (0,1)
WHERE it.internal_type IN (209, 210);
GO