将一些UTF8数据插入nvarchar时失去重音

时间:2014-07-11 09:40:09

标签: sql-server utf-8 nvarchar

创建表格:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[StringsTest](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Value] [nvarchar](max) NOT NULL,
PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING ON
GO

插入数据(拉脱维亚语):

INSERT INTO [dbo].[StringsTest]
           ([Value])
     VALUES
           ('TĀDS KĀDU JŪS')
GO

选择

SELECT * FROM [dbo].[StringsTest]

结果失去了重音:

Id          Value
1           TADS KADU JUS

1 个答案:

答案 0 :(得分:4)

在Unicode字符串之前使用N来标记它。

 INSERT [dbo].[StringsTest]
       ([Value])
 VALUES
       (N'TĀDS KĀDU JŪS')