关于在SQL语句中使用字符N
Database Name: Northwind
数据库的目前排序规则:SQL_Latin1_General_CP1_CI_AS
Orders 表中的字段ShipCity 字段类型是 nvarchar(15),即可以存放多语言字符串
插入:
insert into orders (shipcity) values (‘苏州’)
insert into orders (shipcity) values (N’苏州’)
结果:前面插入的字符是乱码,后一个字符正常。
查询:
SELECT * FROM [Northwind].[dbo].[Orders] where ShipCity =N’苏州’
SELECT * FROM [Northwind].[dbo].[Orders] where ShipCity =’苏州’
结果:前面可以得到一条记录,后面查询不到。
结论: 如果一个数据库是处理多语言事务的(实际情况要根据他的排序规则决定),那在操作时需要在相应的段值前面加上修饰符’N',否则就会出现乱码。
————————————————–
如果数据库的排序规则是:Chinese_PRC_CI_AS
经过测试存放“简体”和“繁體”都不会乱码,无论是加N还是不加N.
如果排序规则是 SQL_Latin1_General_CP1_CI_AS,如果 字段的类型是 varchar 类的,那是不能存放“中文”的,无论是加N还是不加N.
if your database’s collation is english collation, such as sql_latin1_general_ci_as, and
if you want to input chinese characters into a nvarchar column, then you have to use
N’字符’ to input chinese.
Note: ‘字符’ is wrong character string for english collation, and can not be inserted into any varchar/nvarchar column
最新评论