尝试插入时,错误、字符串或二进制数据将被截断 [英] error, string or binary data would be truncated when trying to insert

查看:48
本文介绍了尝试插入时,错误、字符串或二进制数据将被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下几行运行 data.bat 文件:

I am running data.bat file with the following lines:

Rem Tis batch file will populate tables

cd\program files\Microsoft SQL Server\MSSQL
osql -U sa -P Password -d MyBusiness -i c:\data.sql

data.sql文件内容为:

The contents of the data.sql file is:

   insert Customers
            (CustomerID, CompanyName, Phone)
             Values('101','Southwinds','19126602729')

还有 8 条类似的行用于添加记录.

There are 8 more similar lines for adding records.

当我使用 start > run > cmd > c:\data.bat 运行它时,我收到此错误消息:

When I run this with start > run > cmd > c:\data.bat, I get this error message:

1>2>3>4>5>....<1 row affected>
Msg 8152, Level 16, State 4, Server SP1001, Line 1
string or binary data would be truncated.

<1 row affected>

<1 row affected>

<1 row affected>

<1 row affected>

<1 row affected>

<1 row affected>

另外,我显然是一个新手,但是 Level #state # 是什么意思,以及如何查找错误消息,例如上面的错误消息:8152?

Also, I am a newbie obviously, but what do Level #, and state # mean, and how do I look up error messages such as the one above: 8152?

推荐答案

来自 @gmmastros 的回答

每当您看到消息时....

Whenever you see the message....

字符串或二进制数据将被截断

string or binary data would be truncated

想想自己......该字段不足以容纳我的数据.

Think to yourself... The field is NOT big enough to hold my data.

检查客户表的表结构.我想您会发现一个或多个字段的长度不足以容纳您要插入的数据.例如,如果 Phone 字段是一个 varchar(8) 字段,并且您尝试将 11 个字符放入其中,则会出现此错误.

Check the table structure for the customers table. I think you'll find that the length of one or more fields is NOT big enough to hold the data you are trying to insert. For example, if the Phone field is a varchar(8) field, and you try to put 11 characters in to it, you will get this error.

这篇关于尝试插入时,错误、字符串或二进制数据将被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆