Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this SQL INSERT statement return a syntax error?

Tags:

sql

mysql

Ok I have a very simple mysql database but when i try to run this query via mysql-admin i get weird errors

INSERT INTO customreports (study, type, mode, select, description) VALUES ('1', '2', '3', '4', '5');

Error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select, description) VALUES ('1', '2', '3', '4', '5')' at line 1

like image 400
The Digital Ninja Avatar asked Oct 28 '25 21:10

The Digital Ninja


2 Answers

You're having problems because you're using SQL reserved words as column names and not escaping them. Try like this:

INSERT INTO `customreports`
(`study`, `type`, `mode`, `select`, `description`)
VALUES
('1', '2', '3', '4', '5');
like image 188
chaos Avatar answered Oct 31 '25 09:10

chaos


Yeah, I would rewrite as:

INSERT INTO [customreports] ([study], [type], [mode], [select], [description]) VALUES ('1', '2', '3', '4', '5');

like image 26
alex Avatar answered Oct 31 '25 11:10

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!