Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use column name "desc" in mysql

Tags:

php

mysql

web

INSERT INTO movie (id, title, desc, released, views, featured) VALUES ('', 'title', '
\r\n    description
\r\n', '2006-12-12', '0', '0')

error is

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 'desc, released, views, featured) VALUES ('', 'title', ' \r\n description \r\n', ' at line 1

table structure is

id [ (pk, auto_inc) int(11) ]
title [ varchar(256) ]
desc [ text ]
released [ date ]
views [ int(11) ]
featured [ int(11) ]

running in phpmyadmin sql editor

like image 765
Bilal Avatar asked Nov 20 '11 07:11

Bilal


3 Answers

desc is a mysql reserved word. you must use backticks `` with the columns which are reserved words.

INSERT INTO movie (id, title, `desc`, released, views, featured)...

You should avoid using reserved words as column name or must use backticks (``)

like image 113
Shakti Singh Avatar answered Sep 21 '22 02:09

Shakti Singh


The word desc is a reserved word and must be in backticks when used as a column name.

INSERT INTO movie (id, title, `desc`, released, views, featured) VALUES
-- ...etc...

I'd also advise you not to use desc as a column name in future as it is confusing and will just cause problems. You could use description instead, for example.

like image 24
Mark Byers Avatar answered Sep 21 '22 02:09

Mark Byers


DESC is a reserved word of MySQL and if you use it for naming consider using `desc`.

like image 23
Nedret Recep Avatar answered Sep 24 '22 02:09

Nedret Recep