SQL Server错误:字符串或二进制数据将被截断。

时间:2023-01-14 15:42:37

My table :

我的表:

log_id                 bigint
old_value                  xml
new_value                  xml
module                 varchar(50)
reference_id           bigint
[transaction]          varchar(100)
transaction_status         varchar(10)
stack_trace                ntext
modified_on                datetime
modified_by                bigint

Insert Query :

插入查询:

INSERT INTO [dbo].[audit_log]
           ([old_value],[new_value],[module],[reference_id],[transaction]
           ,[transaction_status],[stack_trace],[modified_on],[modified_by])
     VALUES
            ('asdf','asdf','Subscriber',4,'_transaction',
            '_transaction_status','_stack_trace',getdate(),555)

Error :

错误:

Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.

Why is that ???

这是为什么呢? ? ?

3 个解决方案

#1


44  

You're trying to write more data than a specific column can store. Check the sizes of the data you're trying to insert against the sizes of each of the fields.

您试图编写比特定列能够存储的更多的数据。检查要插入的数据的大小和每个字段的大小。

In this case transaction_status is a varchar(10) and you're trying to store 19 characters to it.

在本例中,transaction_status是varchar(10),您试图将19个字符存储到其中。

#2


3  

this type of error generally occurs when you have to put characters or values more than that you have specified in Database table like in this case: you specify transaction_status varchar(10) but you actually trying to store
_transaction_status which contain 19 characters. that's why you faced this type of error in this code..

这种类型的错误通常发生在您必须放置比在数据库表中指定的更多的字符或值时,如本例中所示:您指定transaction_status varchar(10),但实际上您试图存储包含19个字符的_transaction_status。这就是为什么你在这段代码中会遇到这种类型的错误。

#3


2  

This error is usually encountered when inserting a record in a table where one of the columns is a VARCHAR or CHAR data type and the length of the value being inserted is longer than the length of the column.

当在一个表中插入一个记录时,通常会遇到这个错误,其中的一个列是VARCHAR或CHAR数据类型,并且要插入的值的长度比列的长度要长。

I am not satisfied how Microsoft decided to inform with this "dry" response message, without any point of where to look for the answer.

我不满意微软为什么决定用这个“干”的回应信息,没有任何地方去寻找答案。

#1


44  

You're trying to write more data than a specific column can store. Check the sizes of the data you're trying to insert against the sizes of each of the fields.

您试图编写比特定列能够存储的更多的数据。检查要插入的数据的大小和每个字段的大小。

In this case transaction_status is a varchar(10) and you're trying to store 19 characters to it.

在本例中,transaction_status是varchar(10),您试图将19个字符存储到其中。

#2


3  

this type of error generally occurs when you have to put characters or values more than that you have specified in Database table like in this case: you specify transaction_status varchar(10) but you actually trying to store
_transaction_status which contain 19 characters. that's why you faced this type of error in this code..

这种类型的错误通常发生在您必须放置比在数据库表中指定的更多的字符或值时,如本例中所示:您指定transaction_status varchar(10),但实际上您试图存储包含19个字符的_transaction_status。这就是为什么你在这段代码中会遇到这种类型的错误。

#3


2  

This error is usually encountered when inserting a record in a table where one of the columns is a VARCHAR or CHAR data type and the length of the value being inserted is longer than the length of the column.

当在一个表中插入一个记录时,通常会遇到这个错误,其中的一个列是VARCHAR或CHAR数据类型,并且要插入的值的长度比列的长度要长。

I am not satisfied how Microsoft decided to inform with this "dry" response message, without any point of where to look for the answer.

我不满意微软为什么决定用这个“干”的回应信息,没有任何地方去寻找答案。