zoukankan      html  css  js  c++  java
  • 字符前面的N

    1.建立一个测试表

    CREATE table myTestChar
    (
    c1 int not null identity primary key,
    c2 char(8)
    )

    插入两条语句:

    INSERT into myTestChar VALUES('中国')

     INSERT into myTestChar VALUES(N'中国')

    select * from myTestChar

    c1 c2
    1 ??     
    2 ??     

    返回的都是乱码,这是因为汉字和字符采用的是不同的编码方式,不论是否强制的采用unicode编码方式都是乱码。字符无法存储中文。

    (  有的数据库版本不会出现这种现象)

    2.给该表添加一个字段,是nchar类型的

    ALTER table mytestChar
    add c3 nchar(8)

    插入两条记录:

    INSERT into myTestChar VALUES(N'中国','中国')

    INSERT into myTestChar VALUES(N'中国',N'中国')

    返回结果:

    c1 c2 c3
    1 ??       NULL
    2 ??       NULL
    3 ??       ??     
    4 ??       中国     

    INSERT into myTestChar VALUES(N'中国','china')
    INSERT into myTestChar VALUES(N'中国',N'china')

     返回结果:

    c1 c2 c3
    1 ??       NULL
    2 ??       NULL
    3 ??       ??     
    4 ??       中国     
    5 ??       china  
    6 ??       china  

     结论:存储中国字的时候需要强制编码下。因为存储一个中国字需要两个字节。

    INSERT into myTestChar VALUES(N'中国中国中国','china')

    执行上面语言会出现:

    将截断字符串或二进制数据。
    语句已终止。

    这个因为6个字需要12char来存储。

    INSERT into myTestChar VALUES(N'中国中')

    则执行成功。

  • 相关阅读:
    SQLServer限制IP,限制用户,限制SSMS登录
    关于Natively Compiled Stored Procedures的优化
    .NET/C#- EPPLUS DEMO
    ASP.NET MVC- 视图
    ASP.NET MVC- 在Area里使用RedirectToAction跳转出错的解决方法
    ASP.NET MVC- 解决HTML转码
    ASP.NET MVC- KindEditor的使用
    ASP.NET MVC- Upload File的例子
    ASP.NET MVC- ActionFilter的使用
    ASP.NET MVC- UrlHelper的用法
  • 原文地址:https://www.cnblogs.com/363546828/p/3048630.html
Copyright © 2011-2022 走看看