Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"String or binary data would be truncated" upon insert despite the data seemingly fitting

I've got a table like this:

CREATE TABLE Customers
(CustomerID int Identity (1,1) NOT NULL PRIMARY KEY,
customerName varchar (50),
Address varchar (255),
Phone int NOT NULL,
Email varchar,
Gender varchar,
Age int, 
);

I tried inserting into this table like this:

Insert into Customers (customerName, Address, Phones, Email, Gender, Age)
Values ('Anosa Seunge', 'Keskuskatu 200', 358-3-4180, '[email protected]', 'Male', 19),
        ('Jihad Christian', '305 - 14th Ave. Suite 3B', 358-1-3688, '[email protected]', 'Female', 29);

and got this error:

Msg 8152, Level 16, State 14, Line 4
String or binary data would be truncated.
The statement has been terminated.
like image 853
linkonabe Avatar asked Sep 15 '16 13:09

linkonabe


1 Answers

Your Email and Gender fields have a length of 1, which might be what you want for Gender (although probably not based on your insert statement) but is surely not for Email.

You want something like:

CREATE TABLE Customers
(CustomerID int Identity (1,1) NOT NULL PRIMARY KEY,
customerName varchar (50),
Address varchar (255),
Phone int NOT NULL,
Email varchar(50),
Gender varchar(50),
Age int, 
);
like image 195
Mike L Avatar answered Sep 29 '22 07:09

Mike L