-1

I have a simple update query, but it is not working:

update user set active = 'Y' , delete = 'N' where id = 1;// not working

but if I add a special character which phpmyadmin uses then it is working

update `user` set `active` = 'Y' , `delete` = 'N' where `id` = 1;//its working but its database generated

and there is no difference except the ` special character which is not mandatory.

syck
  • 2,984
  • 1
  • 13
  • 23
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
  • 5
    `delete` is a [MySQL reserved word](https://dev.mysql.com/doc/refman/5.5/en/keywords.html).... you cannot use it as a table or column name unless you reference it in backticks – Mark Baker Apr 13 '16 at 12:09

2 Answers2

1

DELETE is a reserved keyword in SQL. Without escaping it with the backtick character you will get a syntax error and the query will not work.

bspellmeyer
  • 783
  • 5
  • 10
1

delete is MySQL reserved keywords.

https://dev.mysql.com/doc/refman/5.7/en/keywords.html

By adding backtick, you are telling MySQL that the word enclosed is not a MySQL keyword but, rather a database name, table name or field name.

Thus, any conflict is avoided.

Pupil
  • 23,834
  • 6
  • 44
  • 66
  • `USER` is not a reserved word, it's a keyword. Two different animals here https://dev.mysql.com/doc/refman/5.7/en/keywords.html - However, `USE` is. There's an `(R)` next to it, but not for `USER`. – Funk Forty Niner Apr 13 '16 at 12:16
  • @Fred-ii-, corrected answer. Thanks – Pupil Apr 13 '16 at 12:18