2

I'm getting String or binary data would be truncated error when, I'm trying to execute

Insert into Student_info (StudentId,FirstName,LastName,DOB,StudentAddress,StudentEmail,StudentMobile) 
                         (Select StudentId,FirstName,LastName,DOB,Address,EmailId,Mobile from Student_temp where StudentId='" & studentid & "')

Table structure of Student_Temp

here

Table structure of Student_Info

here

Need Help !!

1 Answer 1

3

This error is reported by SQL Server when you try and insert string or binary data into a column which doesn't have enough width to hold it, e.g.

create table MyTable
(
    Column1 VARCHAR(10)
)

insert into MyTable (Column1) VALUES ('1234567890A')

Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated

At a guess, it is because your Student_info.StudentMobile is varchar(10) whereas Student_temp.Mobile is varchar(50)

Sign up to request clarification or add additional context in comments.

4 Comments

ok thanks, but, can you tell me in my scenario, where would be the error ? Since, the ddl statement of both tables are almost same, so i don't think so, the error, which you are talking about will be the main reason.
@coders - updated - I think it is the Mobile Number column widths. Out of interest, in this day and age it is worthwhile to model columns like Person's names as NVARCHAR in order to embrace the global community.
@StuartLC, I have the same problem, except I'm getting it, while inserting from vb.net and the field type of the field I'm inserting into is ntext. because usually in MySQL I use TEXT and their is no (or not such a small) size restriction. the thing is; when inserting the data manually, it works... any advice?
@pythonian29033 - I can't think of anything off-hand. Post a new question and I'm sure a guru will be able to solve this :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.