系统表master..spt_values的用途是什么?其值的含义是什么?

发布于 2024-10-04 11:51:55 字数 1597 浏览 0 评论 0原文

系统表master..spt_values的目的是什么?
为什么提供它以及应该如何使用它?

它的类型、低值、高值的含义是什么?

更新:
Google 搜索提供了数千个“其用途”,例如:

因为它可以在 SQL Server 的未来版本中删除,但已经有代码脚本使用它来说明新 SQL Server 11 (Denali) 的新功能:

What is the purpose of system table master..spt_values?
Why was it provided and how one should use it?

What are the meanings of its type, low, high values?

Update:
Google search gives thousands of " its uses", for example:

Some posts warn against its use since it can be removed in future versions of SQL Server but there are already code scripts using it to illustrate new features of new SQL Server 11 (Denali):

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

‘画卷フ 2024-10-11 11:51:55

SQL Server 文档中没有提到 spt_values 表,但它可以追溯到 Sybase 时代,并且有一些 Sybase 在线文档中的文档非常少,可以总结为评论:

要了解如何使用它,请执行 sp_helptext 并查看文本
引用它的系统过程之一。

换句话说,阅读代码并自己解决。

如果您浏览系统存储过程并检查表数据本身,那么很明显该表用于将代码转换为可读字符串(除其他外)。或者正如上面链接的 Sybase 文档所说,“将内部系统值 [...] 转换为人类可读的格式”

该表也是 有时在 MSDN 博客的代码片段中使用 - 但从未在正式文档中使用 - 通常作为数字列表的便捷来源。但正如其他地方所讨论的,创建自己的数字源是一种更安全、更可靠的方法。比使用未记录的系统表更可靠的解决方案。甚至有Connect 请求提供一个“正确的”、记录在案的数字表SQL Server 本身。

无论如何,该表完全没有记录,因此了解它没有任何重要价值,至少从实际的角度来看:下一个服务包或升级可能会完全改变它。当然,求知欲是另一回事:-)

The spt_values table is not mentioned in the the SQL Server documentation but it goes back to the Sybase days and there is some extremely minimal documentation in the Sybase online docs that can be summed up in this comment:

To see how it is used, execute sp_helptext and look at the text for
one of the system procedures that references it.

In other words, read the code and work it out for yourself.

If you poke around the system stored procedures and examine the table data itself, it's fairly clear that the table is used to translate codes into readable strings (among other things). Or as the Sybase documentation linked above puts it, "to convert internal system values [...] into human-readable format"

The table is also sometimes used in code snippets in MSDN blogs - but never in formal documentation - usually as a convenient source of a list of numbers. But as discussed elsewhere, creating your own source of numbers is a safer and more reliable solution than using an undocumented system table. There is even a Connect request to provide a 'proper', documented number table in SQL Server itself.

Anyway, the table is entirely undocumented so there is no significant value in knowing anything about it, at least from a practical standpoint: the next servicepack or upgrade might change it completely. Intellectual curiosity is something else, of course :-)

只为守护你 2024-10-11 11:51:55

主要在另一个问题中得到回答

其类型、低值、高值的含义是什么?

大多数类型(即每个特定的查找表,如果它们是单独的)需要名称或数字。某些类型还需要低柱和高柱。在Sybase中,我们有一个ErrorNumber列,因此存储过程可以RAISERROR,它不是硬编码的(可以随版本等而变化)。

它并不“神秘”,除非枚举列表对您来说“神秘”;它只是一个查找表(所有这些表,通过类型列区分)。

Mostly answered in another question.

What are the meanings of its type, low, high values?

Most Types (ie. each specific lookup table, if they were separate) require either Name or Number. Some Types require Low and High columns as well. In Sybase, we have an ErrorNumber column, so the sproc can RAISERROR which is not hard-coded (can be changes with versions, etc).

It is not "cryptic" unless an enumerated list is "cryptic" to you; it is just a lookup table (all of them, differentiated by the Type column).

平定天下 2024-10-11 11:51:55

一种用法(绝对不是其主要用法)是生成一系列数字:

--Generate a series from 1 to 100
SELECT
    TOP 100
    ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS RowNum
FROM master.dbo.spt_values ORDER BY RowNum

One usage, definitely not its primary usage, is to generate a series of numbers:

--Generate a series from 1 to 100
SELECT
    TOP 100
    ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS RowNum
FROM master.dbo.spt_values ORDER BY RowNum
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文