"String or binary data will be truncated" on insertion, despite the data seeming suitable

I have 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 to insert this table into this table:

Insert into Customers (customerName, Address, Phones, Email, Gender, Age)
Values ('Anosa Seunge', 'Keskuskatu 200', 358-3-4180, 'ijiosd@ao.com', 'Male', 19),
        ('Jihad Christian', '305 - 14th Ave. Suite 3B', 358-1-3688, 'jihado@ao.com', '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.
+4
source share
1 answer

The fields Emailand Genderhave a length of 1, which may be what you want for Gender(although probably not based on your insert statement), but certainly not for Email.

You need 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, 
);
+5
source

Source: https://habr.com/ru/post/1654700/


All Articles