在SQL Server中,当你处理Unicode字符串常量的时候,你必须在所有Unicode字符串前添加N前缀

来源:互联网 发布:江苏网络协会 编辑:程序博客网 时间:2024/05/29 17:41

You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server

When dealing with Unicode string constants in SQL Server you must precede all Unicode strings with a capital letter N, as documented in the SQL Server Books Online topic "Using Unicode Data". The "N" prefix stands for National Language in the SQL-92 standard, and must be uppercase. If you do not prefix a Unicode string constant with N, SQL Server will convert it to the non-Unicode code page of the current database before it uses the string. (摘自msdn,http://support.microsoft.com/kb/239530/en-us )

----

例如如下一张表,

CREATE TABLE [dbo].[FeedbackData](    [username] [nvarchar](16) COLLATE Chinese_PRC_CI_AS NOT NULL,    [avatar] [nvarchar](32) COLLATE Chinese_PRC_CI_AS NOT NULL,    [title] [nvarchar](32) COLLATE Chinese_PRC_CI_AS NOT NULL,    [location] [nvarchar](32) COLLATE Chinese_PRC_CI_AS NOT NULL,    [datetime] [datetime] NOT NULL,    [content] [nvarchar](256) COLLATE Chinese_PRC_CI_AS NOT NULL,    [id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_FeedbackData_uid]  DEFAULT (newid())) ON [PRIMARY]


想要插入数据,则需要这样子写SQL:

insert into FeedbackData ( username, avatar, title, location, datetime, content)

values( N'张大千', N'3', N'界面问题很大', N'浙江省', '2013-01-02 00:02:00', N'中国的自我认识没有达到社会共识应有的低线,这是当前舆论场上出现一系列重大争议的根源之一。');

0 0