Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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

The contents of the data.sql file is:

 insert Customers

(CustomerID, CompanyName, Phone)

Values('101','Southwinds','19126602729')

There are 8 more similar lines for adding records.

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>

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?

1 Answer

0 votes
by (40.7k points)

If the below error message occurs:

 String or binary data would be truncated

It’s understood that the field is NOT big enough to hold my data.

You need to check the table structure for the customers table.To hold the data that you are trying to insert, length of one or more fields won’t be big enough.   

For example:

If the Phone field is a varchar(10) field, and you try to put 11 characters in to it, you will get the above error message.

Related questions

Browse Categories

...