如果表中的特定列具有统计信息,我想检查Transact SQL,如果是,则要检查所有内容。
答案 0 :(得分:2)
此查询应该这样做 我在存储过程中使用它来浏览数据库以查找统计数据 适用于SQL Server 2005以及可能的旧版本。
SELECT S.NAME
FROM SYS.OBJECTS AS O
INNER JOIN SYS.STATS AS S
ON O.OBJECT_ID = S.OBJECT_ID
INNER JOIN SYS.STATS_COLUMNS AS SC
ON SC.OBJECT_ID = S.OBJECT_ID
AND S.STATS_ID = SC.STATS_ID
WHERE (O.OBJECT_ID = OBJECT_ID('MyTable','local'))
AND (O.TYPE IN ('U'))
AND (INDEXPROPERTY(S.OBJECT_ID,S.NAME,'IsStatistics') = 1) /* only stats */
AND (COL_NAME(SC.OBJECT_ID,SC.COLUMN_ID) = 'MyColumn')