使用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.