反引号(`):一般在ESC键的下方,或者数字1左边
作用:是为了区分MySQL的保留字与普通字符而引入的符号。
注意:有MySQL保留字作为字段的,必须加上反引号来区分!!!
所谓的保留字就是select database insert 这一类数据库的sql指令,当我们不得已要拿他们来做表名和字段名的时候 我们必须要加反引号来避免编译器把这部分认为是保留字而产生错误。
例如:SELECT `select` FROM `test` WHERE select=’字段值’
在test表中,有个select字段,如果不用反引号,MySQL将把select视为保留字而导致出错,所以,有MySQL保留字作为字段的,必须加上反引号来区分。
建表语句中加反引号只是作一个保险,也是一个良好的sql建表习惯。
网上整理的MySQL保留字列表:
accessible | else | localtime | schemas |
add | elseif | localtimestamp | second_microsecond |
all | enclosed | lock | select |
alter | escaped | long | sensitive |
analyze | exists | longblob | separator |
and | exit | longtext | set |
as | explain | loop | show |
asc | fetch | low_priority | signal |
asensitive | float | master_bind | smallint |
before | float4 | master_ssl_verify_server_cert | spatial |
between | float8 | match | specific |
bigint | for | maxvalue | sql |
binary | force | mediumblob | sql_big_result |
blob | foreign | mediumint | sql_calc_found_rows |
both | from | mediumtext | sql_small_result |
by | fulltext | middleint | sqlexception |
call | get | minute_microsecond | sqlstate |
cascade | grant | minute_second | sqlwarning |
case | group | mod | ssl |
change | having | modifies | starting |
char | high_priority | natural | straight_join |
character | hour_microsecond | no_write_to_binlog | table |
check | hour_minute | not | terminated |
collate | hour_second | null | then |
column | if | numeric | tinyblob |
condition | ignore | on | tinyint |
constraint | in | optimize | tinytext |
continue | index | option | to |
convert | infile | optionally | trailing |
create | inner | or | trigger |
cross | inout | order | undo |
current_date | insensitive | out | union |
current_time | insert | outer | unique |
current_timestamp | int | outfile | unlock |
current_user | int1 | partition | unsigned |
cursor | int2 | precision | update |
database | int3 | primary | usage |
databases | int4 | procedure | use |
day_hour | int8 | purge | using |
day_microsecond | integer | range | utc_date |
day_minute | interval | read | utc_time |
day_second | into | read_write | utc_timestamp |
dec | io_after_gtids | reads | values |
decimal | io_before_gtids | real | varbinary |
declare | is | references | varchar |
default | iterate | regexp | varcharacter |
delayed | join | release | varying |
delete | key | rename | when |
desc | keys | repeat | where |
describe | kill | replace | while |
deterministic | leading | require | with |
distinct | leave | resignal | write |
distinctrow | left | restrict | xor |
div | like | return | year_month |
double | limit | revoke | zerofill |
drop | linear | right | |
dual | lines | rlike | |
each | load | schema |