如何使用 T-SQL 检查 SQL Server 2000 DB 中是否自动创建统计信息?

发布于 2024-08-21 07:12:09 字数 403 浏览 5 评论 0原文

不久前,我必须想出一种方法来清理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南街九尾狐 2024-08-28 07:12:09

您可以加入sysobjects(基于id列)并检查xtype列的值:

C = CHECK 约束
D = 默认或 DEFAULT 约束
F = 外键约束
L = 对数
FN = 标量函数
IF = 内联表函数
P = 存储过程
PK = PRIMARY KEY 约束(类型为 K)
RF = 复制过滤器存储过程
S = 系统表
TF = 表函数
TR = 触发器
U = 用户表
UQ = UNIQUE 约束(类型为 K)
V = 查看
X = 扩展存储过程

(来自 SQL Server 2000 表映射文档)

您需要类似以下内容:

SELECT SI.name FROM sysobjects AS SO, sysindexes AS SI
WHERE SO.id = SI.id
AND SO.xtype <> 'S'

You could join to the sysobjects (based on the id column) and check the value of the xtype column:

C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
IF = Inlined table-function
P = Stored procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure

(from the SQL Server 2000 table map docs)

You need something like:

SELECT SI.name FROM sysobjects AS SO, sysindexes AS SI
WHERE SO.id = SI.id
AND SO.xtype <> 'S'
太阳男子 2024-08-28 07:12:09

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文