引导带有额外字符的问题 [英] Guid with extra characters issue

查看:100
本文介绍了引导带有额外字符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为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 byte
9C is 2nd byte
3B is 3rd byte
F9 is 4th byte
..
..
..
..
56 is 14th byte
AF is 15th byte
73 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}'

这篇关于引导带有额外字符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆