In the MySQL statement we often encounter anti-quotation marks (' '), at the beginning of the time do not know what the meaning, he is what role?
It is a symbol that is introduced to differentiate between MySQL's reserved words and ordinary characters. For Example: Select ' Select ' From ' Test ' WHERE select= ' field value 'in the test table, there is a select field, without the use of anti-quotes, MySQL will treat select as a reserved word resulting in an error, so there is a MySQL reserved word as a field, you must add the anti-quote to distinguish . quotation marks are generally used in the value of the field, and if the field value is a character or string, enclose it in quotation marks , such as: select= ' field value ' tables built without anti-quotes cannot contain mysql reserved words, otherwise an error occurs anti-quote ', number 1 to the left of the symbol. reserved words cannot be used for table names , such as DESC, which need to be added in reverse quotation marks, but can be ignored when using table names. CREATE TABLE desc errorCREATE TABLE ' desc ' successCREATE table ' test ' succeededdrop table Test succeeded reserved words cannot be used for field names , such as DESC, where you also need to add anti-quotes, and insert and so on with an anti-quote. CREATE TABLE ' Test ' (' desc ' varchar (255)) succeededINSERT INTO Test (DESC) VALUES (' FXF ') failedINSERT INTO Test (' desc ') VALUES (' FXF ') succeeded
common reserved words for MySQLwhen using MySQL, be careful not to use its reserved word as the table name or the column name, otherwise there will be some inexplicable error. A table was built yesterday, where a column named interval (time interval), the results of data can not be plugged in, and finally found that the original interval is a reserved word for MySQL. If you have a similar error in the future, think about whether the table name or the column name conflict is causing the problem. found a list of MySQL reserved words from the Internet, for reference only.
ADD |
All |
Alter |
ANALYZE |
and |
As |
Asc |
Asensitive |
Before |
Between |
BIGINT |
BINARY |
Blob |
BOTH |
By |
Pager |
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 |
Inch |
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 |
Specific |
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 of the keywords to be used as unrecognized identifiers, because many people have been using them before. such as: ACTION, BIT, DATE, ENUM, NO, TEXT, time, TIMESTAMPSo for security reasons, you can add ' ' to both the table name and the field name.
Why add anti-quotes in MySQL statements