避免使用Microsoft SQLServer和Unicode更改代码 [英] Avoiding code change with Microsoft SQLServer and Unicode
问题描述
默认情况下,如何使MSSQL Server接受Unicode数据到VARCHAR或NVARCHAR列中?
How can you get MSSQL server to accept Unicode data by default into a VARCHAR or NVARCHAR column?
我知道您可以通过在前面加上N来实现放置在字段中的字符串,但说实话,这在2008年尤其是在使用SQL Server 2005时显得有些陈旧。
I know that you can do it by placing a N in front of the string to be placed in the field but to by quite honest this seems a bit archaic in 2008 and particuarily with using SQL Server 2005.
推荐答案
N
语法是在SQL Server中指定Unicode字符串文字的方式。
The N
syntax is how you specify a unicode string literal in SQL Server.
N'Unicode string'
'ANSI string'
SQL Server
SQL Server will auto convert between the two when possible, using either a column's collation or the database's collation.
因此,如果您的字符串文字实际上不包含Unicode字符,则不会使用列的排序规则或数据库的排序规则自动在两者之间进行转换。需要指定 N
前缀。
So if your string literals don't actually contain unicode characters, you do not need to specify the N
prefix.
但是如果您的字符串文字 do 包含unicode字符,然后必须使用 N
前缀。
But if your string literals do contain unicode characters then using the N
prefix is necessary.
这篇关于避免使用Microsoft SQLServer和Unicode更改代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!