如何使用 T-SQL 检查 SQL Server 2000 DB 中是否自动创建统计信息?
不久前,我必须想出一种方法来清理 SQL Server 2005 数据库中某些表中的所有索引和用户创建的统计信息。经过几次尝试后,它成功了,但现在我也必须让它在 SQL Server 2000 数据库中工作。对于 SQL Server 2005,我使用
SELECT Name FROM sys.stats
WHERE object_id = object_id(@tableName)
AND auto_created = 0
以获取用户创建的统计信息。但是,SQL 2000 没有 sys.stats 表。我设法以可区分的方式从 sysindexes 表中获取索引和统计信息,但我就是无法弄清楚 SQL 2000 的 sys.stats.auto_created 匹配是什么。有任何指针吗?
顺便说一句:请使用 T-SQL。
A while back I had to come up with a way to clean up all indexes and user-created statistics from some tables in a SQL Server 2005 database. After a few attempts it worked, but now I gotta have it working in SQL Server 2000 databases as well. For SQL Server 2005, I used
SELECT Name FROM sys.stats
WHERE object_id = object_id(@tableName)
AND auto_created = 0
to fetch Statistics that were user-created. However, SQL 2000 doesn't have a sys.stats table. I managed to fetch the indexes and statistics in a distinguishable way from the sysindexes table, but I just couldn't figure out what the sys.stats.auto_created match is for SQL 2000. Any pointers?
BTW: T-SQL please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以加入
sysobjects
(基于id
列)并检查xtype
列的值:(来自 SQL Server 2000 表映射文档)
您需要类似以下内容:
You could join to the
sysobjects
(based on theid
column) and check the value of thextype
column:(from the SQL Server 2000 table map docs)
You need something like:
INDEXPROPERTY 具有“IsAutoStatistics”属性。我还记得统计信息也存储在 sysindexes 中,因此您可以从那里获取 ID。
抱歉,我没有 SQL 2000 框来测试或确认这一点...
INDEXPROPERTY has a "IsAutoStatistics" property". I also recall that statistics are stored in sysindexes too so you can get the ID from there.
Sorry, I don't have a SQL 2000 box to test or confirm this on...