系统表master..spt_values的目的是什么,其值的含义是什么?

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

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:

  • 使用 master..spt_values 拆分列
  • 它包含从 0 到 2047 的数字.它非常有用.例如如果您需要使用此范围内的 100 个数字填充表格
  • 用于构建索引
  • 创建虚拟日历
  • 以有点不直观和复杂的方式获取所用对象的描述
    枚举 SQL Server 数据库中的所有索引(Giuseppe Dimauro,devx.com) 莉>
  • "SQL Server 2005 显示磁盘空间使用情况的脚本"
  • "不值一提.这张表是超级"查找表的设计噩梦

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

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):

推荐答案

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

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:

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

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.

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

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"

该表也在代码片段中有时使用MSDN 博客——但从未出现在正式文档中——通常作为数字列表的方便来源.但正如其他地方所讨论的那样,创建自己的数字源更安全、更可靠.比使用未记录的系统表更可靠的解决方案.甚至还有一个连接请求来提供一个正确的"、记录在案的数字表SQL Server 本身.

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 :-)

相关文章