简体   繁体   English

nvarchar[n] 类型的数据如何存储?

[英]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.

相关问题 存储过程和错误的数据类型nvarchar转换为数值 - Stored procedure and bad data type nvarchar to numeric 如何解决此错误“将数据类型nvarchar转换为float”。 使用存储过程在sql中插入记录时 - How to solve this error ' converting data type nvarchar to float.' while inserting a record in sql using stored procedure 使用存储过程将数据类型nvarchar转换为datetime时出错 - Error converting data type nvarchar to datetime with stored procedure 从代码将存储过程中的数据类型nvarchar转换为datetime时出错 - Error converting data type nvarchar to datetime in a Stored Procedure from code 存储过程将数据类型nvarchar转换为数值时出错 - Stored procedure Error converting data type nvarchar to numeric 调用存储过程错误:将数据类型nvarchar转换为datetime时出错 - Calling stored procedure Error: Error converting data type nvarchar to datetime 存储过程错误:“将数据类型nvarchar转换为uniqueidentifier时出错” - Stored procedure error: “Error converting data type nvarchar to uniqueidentifier” Nvarchar数据类型到日期时间 - Nvarchar data type to datetime 如何通过在SQL Server存储过程中尝试catch语句来获取错误“将nvarchar数据类型转换为int。”的错误? - How to get the error “Error converting data type nvarchar to int.” by try catch statement in SQL Server stored procedure? 在存储过程中将nvarchar类型转换为数字sql - Converting nvarchar type to numeric sql in stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM