使用SQL Server变量的时候碰到变量名称大小写的问题:
当前数据库是大小写不敏感的,但是声明变量之后发现变量名称是大小写敏感的。一直认为SQL Server的变量名称的Collcation是跟当前数据库的,在MSDN:
You cannot specify a collation for character variables and parameters; they are always created with the default collation of the database.http://msdn.microsoft.com/en-us/library/aa174903(v=sql.80).aspx
但是这篇文章只是提到变量的数据是跟当前数据的,但是没有提到变量名称的Collcation. 之后在MSDN论坛发现有相同的问题,微软工程师的回复如下:
Please note that variable collation is based on the server side (master db) collation, not on the user database collation.
For example if you have a case sensitive server, but a case-insensitive user database the variable declarions are case sensitive, since they live in memory of the server, and that uses the server collation.(http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/0d833fab-2b32-4b98-a3ab-cdf8c743e5e0)
综上可以得出SQL Server变量名称的Collcation是跟系统Master数据库,也就是Instance的Collation.