问题描述
我有一个名为Student
的表,包含一个列StudentId
作为GUID
,因此我为此使用了Uniqueidentifier
数据类型.
I have a table named Student
, contain a column StudentId
as GUID
, so I used the Uniqueidentifier
datatype for that.
如果要获取特定记录,可以通过以下查询获取结果:
If I want to get particular record, I get the result by the below query:
SELECT * FROM Student WHERE StudentId = '919C3BF9-B081-458C-897D-C0B3FF56AF73'
它返回预期结果.但是,如果我错误地在末尾添加了任何额外的字符,它也会返回相同的结果.类似于以下查询:
It returns the expected result. But in case if I mistakenly add any extra characters in the end also, it returns the same result. Like the below query:
SELECT * FROM Student WHERE StudentId = '919C3BF9-B081-458C-897D-C0B3FF56AF73xyz'
如果我在GUID
的末尾传递了多余的字符,为什么不将其视为无效的GUID
?并返回相同的结果?
If I pass the extra characters in the end of GUID
, why it is not consider as invalid GUID
? and return the same result?
推荐答案
GUID
是16个字节,因此从给定的919C3BF9-B081-458C-897D-C0B3FF56AF73
GUID
is 16 bytes, so from the given 919C3BF9-B081-458C-897D-C0B3FF56AF73
91
是第一个字节9C
是第二个字节3B
是第3个字节F9
是第4个字节
..
..
..
.. 56
是第14个字节AF
是第15个字节73
是第16个字节
91
is 1st byte9C
is 2nd byte3B
is 3rd byteF9
is 4th byte
..
..
..
..56
is 14th byteAF
is 15th byte73
is 16th byte
919C3BF9-B081-458C-897D-C0B3FF56AF73xyz
的解析在xyz
之前完成.
因此,在第16个字节之后输入字符,将不予考虑.
So the characters are entered after the 16th byte, won't be consider.
但是,如果您在前面添加任何多余的字符,它将不会被视为有效的GUID
.
But if you add any extra characters in the front, it won't consider as valid GUID
.
此外,当您使用GUID
查询时,请使用{}
之间的代码.
Moreover, when you query with GUID
, use the code in between the {}
.
SELECT * FROM Student
WHERE StudentId = '{919C3BF9-B081-458C-897D-C0B3FF56AF73}'
这篇关于引导带有额外字符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!