Cannot insert data into a table which has an identity constraint

Viewed 39
CREATE TABLE Customer
(
    CustomerID int identity(100,1) PRIMARY KEY,  
    CustomerName varchar(55) not null,
    contact int not null,
    [Address] text
)
INSERT INTO Customer (CustomerID, CustomerName, contact, [Address])
VALUES (101, 'Bruce Wayne', 0012124567890, '31, Wayne Manor Estate, Gotham');

I get this error:

Msg 544, Level 16, State 1, Line 3
Cannot insert explicit value for identity column in table 'Customer' when IDENTITY_INSERT is set to OFF.

SET IDENTITY_INSERT Customer ON

INSERT INTO Customer(CustomerID, CustomerName, contact, [Address])
VALUES (101, 'Bruce Wayne', 0012124567890, '31, Wayne Manor Estate, Gotham');

Now I get another error:

Msg 8115, Level 16, State 2, Line 3
Arithmetic overflow error converting expression to data type int.

0 Answers
Related