Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I keep getting arithmetic overflow error converting numeric to data type numeric when I try inserting values into a table. I am using MS Visual Studios.

What I have tried:

this is the table:

SQL
CREATE TABLE RESERVATION(
R_RESERVATIONNUM	VARCHAR(7) NOT NULL UNIQUE,
T_TRIPNUM		INTEGER NOT NULL,
R_TRIPDATE		DATE NOT NULL,
R_NUMPERSONS		INTEGER NOT NULL,
R_TRIPPRICE		DECIMAL(3,2) NOT NULL,
R_OTHERFEES		DECIMAL(3,2) NOT NULL,
C_CUSTOMERNUM		VARCHAR(3) NOT NULL,
PRIMARY KEY (R_RESERVATIONNUM),
FOREIGN KEY (T_TRIPNUM) REFERENCES TRIP,
FOREIGN KEY (C_CUSTOMERNUM) REFERENCES CUSTOMER);

here is the insert:

SQL
INSERT INTO RESERVATION VALUES ('1600001',40,'2018-3-26',2,55.00,0.00,'101');
INSERT INTO RESERVATION VALUES ('1600002',21,'2018-6-8',2,95.00,0.00,'101');
INSERT INTO RESERVATION VALUES ('1600003',28,'2018-9-12',1,35.00,0.00,'103');
Posted
Updated 26-Apr-18 21:37pm
v2

1 solution

Correct syntax is
SQL
INSERT INTO RESERVATION (R_RESERVATIONNUM, T_TRIPNUM, R_TRIPDATE, R_NUMPERSONS, R_TRIPPRICE, R_OTHERFEES, C_CUSTOMERNUM) VALUES ( ... );

You have to indicate which columns, and in which order, for the INSERT statement to be clear about what goes where.

Moreover, the precision you have chosen for your decimal columns seems a little bit too low (only 3 digits, left and right from the decimal point). With the values you provided, precision should be at least 4, but you could go to 9 without impacting the number of bytes used to store the values.

Please see decimal and numeric (Transact-SQL) | Microsoft Docs[^] for further information.
 
Share this answer
 
Comments
Maciej Los 27-Apr-18 3:48am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900