Arithmetic overflow error converting expression to data type int in SQL Server

cygmwpex  于 2023-10-15  发布在  SQL Server
关注(0)|答案(1)|浏览(139)

When I try to execute this small code, I am getting this error. Could someone please help me to sort it out.

CREATE TABLE Student_details11 
(
    ROLL_NO Int,
    NAME VARCHAR(25),
    ADDRESS VARCHAR(25),
    PHONE Int,
    AGE Int
);

INSERT INTO Student_details11 (ROLL_NO, NAME, ADDRESS, PHONE, AGE) 
VALUES (1, 'Ram', 'Delhi', 9415536635, 24)
zz2j4svz

zz2j4svz1#

As per the Microsoft documentation on the int data type , it only supports values between -2,147,483,648 and 2,147,483,647, while you are trying to insert a value of 9,415,536,635, which is outside of this range.

If the value really needs to be numeric, consider using bigint :

create table #Student_details11 
(
    ROLL_NO int,
    [NAME] varchar(25),
    [ADDRESS] varchar(25),
    PHONE int,
    AGE int
)

However, if the PHONE column is intended to store a phone number, you'd probably be better using a text-type such as varchar as suggested in the comments:

create table #Student_details11 
(
    ROLL_NO int,
    [NAME] varchar(25),
    [ADDRESS] varchar(25),
    PHONE varchar(10),
    AGE int
)

相关问题