nvarchar and nchar

Same:

1.store unicode charactor.

2. A charactor is stroed with 2 bytes.

Different.

1. nchar  会自动填充数据到定义的固定长度;nvarchar 是数据有多长就存多少数据。

Example:

Create a table like below and store "A" in the two column.

CREATE TABLE [dbo].[AAAAA](
[name] [nchar](10) NULL,
[newName] [nvarchar](10) NULL
) ON [PRIMARY]

Result:the data length of the name is 20 bytes.

     the data length of the newname is 2 bytes.  

You can get the data length with the below method.

select datalength(name) as Bytes, * from [dbo].[AAAAA]
select datalength(newName) as Bytes, * from [dbo].[AAAAA]

上一篇:Dapper事务操作


下一篇:android TDD平台插入双卡时,查看允许返回发送报告的选项,去掉勾选,不起作用