If your table name or column name is any reserved word, then you need to use quotes around the table name and column name in the MySQL query. You need to use backticks around table and column names. The syntax is as follows:
SELECT *FROM `table` where `where`=condition;
Here is a query to create a table without quotation marks and reserved words. You will receive an error message because they are predefined reserved words. The error is as follows:
mysql> create table table -> ( -> where int -> ); ERROR 1064 (42000): 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 'table ( where int )' at line 1
Now let's put quotes around the table and column names, since "table" and "where" are reserved words. This is the quoted query:
mysql> create table `table` -> ( -> `where` int -> ); Query OK, 0 rows affected (0.55 sec)
Use the insert command to insert records in the table. The query is as follows:
mysql> insert into `table`(`where`) values(1); Query OK, 1 row affected (0.13 sec) mysql> insert into `table`(`where`) values(100); Query OK, 1 row affected (0.26 sec) mysql> insert into `table`(`where`) values(1000); Query OK, 1 row affected (0.13 sec)
Display specific records in the table with the help of where conditions. The query is as follows:
mysql> select *from `table` where `where`=100;
The following is the output:
+-------+ | where | +-------+ | 100 | +-------+ 1 row in set (0.00 sec)
The above is the detailed content of Are quotes around tables and columns in MySQL queries really necessary?. For more information, please follow other related articles on the PHP Chinese website!