0
votes

I tried creating my third table of phone numbers, I wrote the following commands:

CREATE TABLE MYPHONE (EMPLOYEE_ID INT, PHONE_NUMBER INT)

INSERT INTO MYPHONE 
VALUES (1 , 7894561230)

But when I tried executing this previous INSERT command, I got an error:

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

2

2 Answers

1
votes

An int probably isn't the best data type for a phone number - you don't need to do any arithmetic on phone numbers, so why use a numerical data type? Store it as a string (or varchar in SQL).

Also, if you did need to store a value as an int, 2,147,483,647 is the maximum - anything higher would "overflow", hence the error you're getting. A long (or bigint in SQL) would allow values up to 9,223,372,036,854,775,808.

1
votes

Allowed range of INT datatype is -2,147,483,648 to 2,147,483,647

You can get more details on the allowed range here

You are trying to insert beyond that range. For phone number better choose VARCHAR data type. If you still want to go for number, in that case use BIGINT instead of INT.