MySQL中的保留字


在MySQL中,有特定語義的單詞或者字符串比如delete,order等語法用詞,count,sum等函數用詞,我們把它稱作MySQL保留字;

我們在數據庫設計時,也就是在創建庫表的時候,要避免使用這些字符串作為庫表的某些字段名稱,如果使用了,那么在sql語句中,要使用[]或者``以示區別,不然語句無法執行。

還記得那個update語句吧:

update dmz.award_inform set `Get`=1 where RoleID=290707225 and ZoneID=5;

在沒加反引號之前,怎么執行都報錯,而且是語法錯,但語法能有啥啥錯呢?

后來實在沒辦法聯系了DBA的同學,他說給Get加個反引號試試。。。

之后我意識到sql規范的重要性,就挺突然的!

這里給大伙大致羅列下MySQL中的保留字:(阿里整理的)

action   add   aggregate   all

alter   after   and   as

asc   avg   avg_row_length   auto_increment

between   bigint   bit   binary  

blob   bool   both   by  

cascade   case   char   character  

change   check   checksum   column  

columns   comment   constraint   create  

cross   current_date   current_time   current_timestamp  

data   database   databases   date  

datetime   day   day_hour   day_minute  

day_second   dayofmonth   dayofweek   dayofyear  

dec   decimal   default   delayed  

delay_key_write   delete   desc   describe  

distinct   distinctrow   double   drop  

end   else   escape   escaped  

enclosed   enum   explain   exists  

fields   file   first   float  

float4   float8   flush   foreign  

from   for   full   function  

global   grant   grants   group  

having   heap   high_priority   hour  

hour_minute   hour_second   hosts   identified  

ignore   in   index   infile  

inner   insert   insert_id   int  

integer   interval   int1   int2  

int3   int4   int8   into  

if   is   isam   join  

key   keys   kill   last_insert_id  

leading   left   length   like  

lines   limit   load   local  

lock   logs   long   longblob  

longtext   low_priority   max   max_rows  

match   mediumblob   mediumtext   mediumint  

middleint   min_rows   minute   minute_second  

modify   month   monthname   myisam  

natural   numeric   no   not  

null   on   optimize   option  

optionally   or   order   outer  

outfile   pack_keys   partial   password  

precision   primary   procedure   process  

processlist   privileges   read   real  

references   reload   regexp   rename  

replace   restrict   returns   revoke  

rlike   row   rows   second  

select   set   show   shutdown  

smallint   soname   sql_big_tables   sql_big_selects  

sql_low_priority_updates   sql_log_off   sql_log_update   sql_select_limit  

sql_small_result   sql_big_result   sql_warnings   straight_join  

starting   status   string   table  

tables   temporary   terminated   text  

then   time   timestamp   tinyblob  

tinytext   tinyint   trailing   to  

type   use   using   unique  

unlock   unsigned   update   usage  

values   varchar   variables   varying  

varbinary   with   write   when  

where   year   year_month   zerofill   

其實不論是否使用到了保留字,我們都需要規范我們的sql語句!~

以上。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM