Why do backticks need to be added to mysql statements?
In MySQL statements, we often encounter backquotes (''). At the beginning, we don't know what it means. What does it mean?
Select * from `member` order by posts desc limit 0,10;
It is a symbol introduced to distinguish reserved MYSQL characters from common characters.For example, SELECT 'select' FROM 'test' WHERE select = 'field value' has a select field in the test table. If no quotation marks are used, MYSQL regards the select statement as a reserved word and leads to an error. Therefore, if a MYSQL reserved word is used as a field, it must be differentiated by quotation marks. Quotation marks are generally used for field values. If the field value is a character or string, quotation marks are required. For example, if select = 'field value' is not added with backticks, the table cannot contain reserved MYSQL characters, otherwise, the quotation mark (') is the symbol on the left of number 1. Reserved Words cannot be used for table names, such as desc. In this case, you need to add backquotes to differentiate them. However, when using table names, you can ignore backquotes. Create table desc error create table 'desc' successful create table 'test' successful drop table test successful reserved words cannot be used for field names, such as desc, at this time also need to add back quotes, in addition, quotation marks must be added for use such as insert. Create table 'test' ('desc' varchar (255) Successful insert into test (desc) values ('fxf') failed insert into test ('desc ') values ('fxf') successful
Mysql Common Reserved WordsWhen using mysql, be sure not to use its reserved words as the table name or column name. Otherwise, an inexplicable error may occur. I created a table yesterday, and one of the column names is interval (time interval). As a result, no data can be inserted into the table. I found that interval is a reserved word of mysql. If a similar error occurs in the future, first think about whether it is caused by table name or column Name Conflict. I found a mysql reserved word list from the Internet for reference only.
ADD |
ALL |
ALTER |
ANALYZE |
AND |
AS |
ASC |
ASENSITIVE |
BEFORE |
BETWEEN |
BIGINT |
BINARY |
BLOB |
BOTH |
BY |
CALL |
CASCADE |
CASE |
CHANGE |
CHAR |
CHARACTER |
CHECK |
COLLATE |
COLUMN |
CONDITION |
CONNECTION |
CONSTRAINT |
CONTINUE |
CONVERT |
CREATE |
CROSS |
CURRENT_DATE |
CURRENT_TIME |
CURRENT_TIMESTAMP |
CURRENT_USER |
CURSOR |
DATABASE |
DATABASES |
DAY_HOUR |
DAY_MICROSECOND |
DAY_MINUTE |
DAY_SECOND |
DEC |
DECIMAL |
DECLARE |
DEFAULT |
DELAYED |
DELETE |
DESC |
DESCRIBE |
DETERMINISTIC |
DISTINCT |
DISTINCTROW |
DIV |
DOUBLE |
DROP |
DUAL |
EACH |
ELSE |
ELSEIF |
ENCLOSED |
ESCAPED |
EXISTS |
EXIT |
EXPLAIN |
FALSE |
FETCH |
FLOAT |
FLOAT4 |
FLOAT8 |
FOR |
FORCE |
FOREIGN |
FROM |
FULLTEXT |
GOTO |
GRANT |
GROUP |
HAVING |
HIGH_PRIORITY |
HOUR_MICROSECOND |
HOUR_MINUTE |
HOUR_SECOND |
IF |
IGNORE |
IN |
INDEX |
INFILE |
INNER |
INOUT |
INSENSITIVE |
INSERT |
INT |
INT1 |
INT2 |
INT3 |
INT4 |
INT8 |
INTEGER |
INTERVAL |
INTO |
IS |
ITERATE |
JOIN |
KEY |
KEYS |
KILL |
LABEL |
LEADING |
LEAVE |
LEFT |
LIKE |
LIMIT |
LINEAR |
LINES |
LOAD |
LOCALTIME |
LOCALTIMESTAMP |
LOCK |
LONG |
LONGBLOB |
LONGTEXT |
LOOP |
LOW_PRIORITY |
MATCH |
MEDIUMBLOB |
MEDIUMINT |
MEDIUMTEXT |
MIDDLEINT |
MINUTE_MICROSECOND |
MINUTE_SECOND |
MOD |
MODIFIES |
NATURAL |
NOT |
NO_WRITE_TO_BINLOG |
NULL |
NUMERIC |
ON |
OPTIMIZE |
OPTION |
OPTIONALLY |
OR |
ORDER |
OUT |
OUTER |
OUTFILE |
PRECISION |
PRIMARY |
PROCEDURE |
PURGE |
RAID0 |
RANGE |
READ |
READS |
REAL |
REFERENCES |
REGEXP |
RELEASE |
RENAME |
REPEAT |
REPLACE |
REQUIRE |
RESTRICT |
RETURN |
REVOKE |
RIGHT |
RLIKE |
SCHEMA |
SCHEMAS |
SECOND_MICROSECOND |
SELECT |
SENSITIVE |
SEPARATOR |
SET |
SHOW |
SMALLINT |
SPATIAL |
Specpacific |
SQL |
SQLEXCEPTION |
SQLSTATE |
SQLWARNING |
SQL _BIG_RESULT |
SQL _CALC_FOUND_ROWS |
SQL _SMALL_RESULT |
SSL |
STARTING |
STRAIGHT_JOIN |
TABLE |
TERMINATED |
THEN |
TINYBLOB |
TINYINT |
TINYTEXT |
TO |
TRAILING |
TRIGGER |
TRUE |
UNDO |
UNION |
UNIQUE |
UNLOCK |
UNSIGNED |
UPDATE |
USAGE |
USE |
USING |
UTC_DATE |
UTC_TIME |
UTC_TIMESTAMP |
VALUES |
VARBINARY |
VARCHAR |
VARCHARACTER |
VARYING |
WHEN |
WHERE |
WHILE |
WITH |
WRITE |
X509 |
XOR |
YEAR_MONTH |
ZEROFILL |
Note: MySQL allows some keywords to be used as unprovoked identifiers, because many people have used them before. For example: ACTION, BIT, DATE, ENUM, NO, TEXT, TIME, TIMESTAMP. Therefore, you can add ''To the table name and field name for security reasons ''.