SQL Server 中是否有 UniqueIdentifiers 的验证规则?
假设我有一些 SQL 按 UniqueIdentifier
类型的列过滤数据。
从 core.Pages WHERE PageId = '1DC4E71C-4E68-489D-A837-2C9BA8DCC1DC' 中选择 *
(该 guid 是由 NewID() 函数生成的)
为了快速测试/健全性检查,我想用“x”替换其中一个字符并再次运行查询。想象一下当我收到错误消息时我的惊讶:
从字符串转换为时转换失败 唯一标识符。
我认为 GUID 或 UniqueIdentifier 的范围是无限的,即。任何字母数字字符都可以替换为任何其他字符,但 SQL Server 似乎对 GUID 的构成有自己的想法。任何字母“X”的使用都会产生此错误。其他字符似乎不会扰乱 RDBMS。
谁能解释一下吗?
Supposing I've got a bit of SQL that filters data by a column which is of type UniqueIdentifier
.
Select * from core.Pages WHERE PageId = '1DC4E71C-4E68-489D-A837-2C9BA8DCC1DC'
(This guid was generated by the NewID() function)
For the purposes of a quick test/sanity check I thought I'd replace one of the characters with an 'x' and run the query again. Imagine my surprise when I got an error message:
Conversion failed when converting from a character string to
uniqueidentifier.
I thought GUID or UniqueIdentifier was unlimited in its scope ie. any alphanumeric character could be replaced with any other but it seems that SQL Server has its own ideas about what constitutes a GUID. Any use of the letter 'X' generates this error. Other characters don't seem to upset the RDBMS.
Can anyone explain this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GUID 是一个十六进制数字 - 它不仅仅是“任何字符都可以用来替换任何其他字符”,生成的字符串必须是有效的十六进制数字。 GUID 本身并不一定是唯一的,而是 GUID 可以表示的数字范围 (2^128) 使得同一 GUID 在系统内生成两次的几率可以忽略不计。
GUIDs are a hexidecimal number - it's not just "any character can be used to replace any other character", the resulting string must be a valid hexidecimal number. It's not the GUID itself that is necessarily unique, it's that the range of numbers that the GUID can represent (2^128) that the odds of the same GUID being generated twice within a system are negligible.