[英]How is data with nvarchar[n] type stored?
If I create a table like this如果我创建这样的表
CREATE TABLE [dbo].[Car]
(
[Car_ID] [varchar](20) NOT NULL,
[Car_CODE] [nvarchar](20) NULL,
[Car_NAME] [nvarchar](50) NULL,
)
Does Car_Name
have a maximum of 50 characters? Car_Name
是否最多包含 50 个字符?
Say I give an input like this假设我给出这样的输入
"Teslaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
(60 chars), will it be stored as (60个字符),它会被存储为
"Teslaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
(50 chars)? (50 个字符)? Can someone help me with this?有人可以帮我弄这个吗? Thank you very much非常感谢
If you try to insert or update a value greater than the column length by a query or Entity Framework, you'll get an error:如果您尝试通过查询或实体框架插入或更新大于列长度的值,您将收到错误消息:
String or binary data would be truncated字符串或二进制数据将被截断
If you use a stored procedure, the truncation will be done automatically and no error will occur.如果使用存储过程,截断会自动完成,不会出现错误。
The information is not inserted, it gives you an error信息没有插入,它给你一个错误
String or binary data would be truncated
The way I see your post raises two questions and therefore two answers.我看到您的帖子的方式提出了两个问题,因此提出了两个答案。
1. How is nvarchar
stored? 1、 nvarchar
是如何存储的?
Data type nvarchar
will store 2 bytes per character whereas varchar
only 1 byte.数据类型nvarchar
将存储每个字符 2 个字节,而varchar
仅存储 1 个字节。
2. Will my nvarchar
accept more chars than the maximum permitted? 2. 我的nvarchar
接受的字符是否超过了允许的最大值?
No. The INSERT
statement will fail and you'll be getting an error since it accepts only <= 50 chars.不, INSERT
语句将失败并且您将收到错误消息,因为它只接受 <= 50 个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.