1

I've have created a SQL database, which I'm connected to with MySQL Workbench. I have one column that I for some reason can't use in the query, which Workbench actually recognize. My Query looks looked like this:

INSERT INTO `mcfluid` (desc, type, maxcap, curcap) VALUES ('tank', 'water',1000,1000);

This didn't work for some reason, but when I changed it to this:

INSERT INTO `mcfluid` (`desc`, type, maxcap, curcap) VALUES ('tank', 'lava',1000,1000);

It for some reason did?

Why is this?

My table looks like this:

id int(11) AI PK 
desc varchar(100) 
type varchar(100) 
maxcap bigint(20) 
curcap bigint(20)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
RasmusGP
  • 4,696
  • 5
  • 21
  • 28

1 Answers1

2

desc is a reserved word in SQL - it's a keyword for the order by clause that denotes the ordering in a descing order (e.g.: select * from mytable order by mycolumn DESC).

Escaping it with backticks allows MySQL to understand you've meant to use it as a name and not a syntactic element.

Mureinik
  • 297,002
  • 52
  • 306
  • 350