sql都有哪些保留字

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql都有哪些保留字相关的知识,希望对你有一定的参考价值。

sql中的保留字

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
参考技术A

sql 中的保留关键字有很多,注意的是不同的数据库的保留关键字也是不同的

下面列举一些sql中的保留关键字

    A

    ABORT

    ABS

    ABSOLUTE

    ACCESS

    ACTION

    ADA

    ADD

    ADMIN

    AFTER

    AGGREGATE

    ALIAS

    ALL

    ALLOCATE

    ALSO

    ALTER

    ALWAYS

    ANALYSE

    ANALYZE

    ANY

    ARE

    ARRAY

资料参考:https://www.drupal.org/node/141051

SQL对象命名使用保留字导致SQL Error: 1064, SQLState: 42000

       如果在表或字段等数据库对象的命名中使用以下关键字和保留字(不区分大小写),就会报:SQL Error: 1064, SQLState: 42000。我遇到的现象是插入前2条记录都没报错,第3条及以后的插件都报这个错,所以可能跟mysql的版本有关系。为避免此类问题,尽量不使用这些关键字和保留字:

ADDALLALTER
ANALYZEANDAS
ASCASENSITIVEBEFORE
BETWEENBIGINTBINARY
BLOBBOTHBY
CALLCASCADECASE
CHANGECHARCHARACTER
CHECKCOLLATECOLUMN
CONDITIONCONNECTIONCONSTRAINT
CONTINUECONVERTCREATE
CROSSCURRENT_DATECURRENT_TIME
CURRENT_TIMESTAMPCURRENT_USERCURSOR
DATABASEDATABASESDAY_HOUR
DAY_MICROSECONDDAY_MINUTEDAY_SECOND
DECDECIMALDECLARE
DEFAULTDELAYEDDELETE
DESCDESCRIBEDETERMINISTIC
DISTINCTDISTINCTROWDIV
DOUBLEDROPDUAL
EACHELSEELSEIF
ENCLOSEDESCAPEDEXISTS
EXITEXPLAINFALSE
FETCHFLOATFLOAT4
FLOAT8FORFORCE
FOREIGNFROMFULLTEXT
GOTOGRANTGROUP
HAVINGHIGH_PRIORITYHOUR_MICROSECOND
HOUR_MINUTEHOUR_SECONDIF
IGNOREININDEX
INFILEINNERINOUT
INSENSITIVEINSERTINT
INT1INT2INT3
INT4INT8INTEGER
INTERVALINTOIS
ITERATEJOINKEY
KEYSKILLLABEL
LEADINGLEAVELEFT
LIKELIMITLINEAR
LINESLOADLOCALTIME
LOCALTIMESTAMPLOCKLONG
LONGBLOBLONGTEXTLOOP
LOW_PRIORITYMATCHMEDIUMBLOB
MEDIUMINTMEDIUMTEXTMIDDLEINT
MINUTE_MICROSECONDMINUTE_SECONDMOD
MODIFIESNATURALNOT
NO_WRITE_TO_BINLOGNULLNUMERIC
ONOPTIMIZEOPTION
OPTIONALLYORORDER
OUTOUTEROUTFILE
PRECISIONPRIMARYPROCEDURE
PURGERAID0RANGE
READREADSREAL
REFERENCESREGEXPRELEASE
RENAMEREPEATREPLACE
REQUIRERESTRICTRETURN
REVOKERIGHTRLIKE
SCHEMASCHEMASSECOND_MICROSECOND
SELECTSENSITIVESEPARATOR
SETSHOWSMALLINT
SPATIALSPECIFICSQL
SQLEXCEPTIONSQLSTATESQLWARNING
SQL_BIG_RESULTSQL_CALC_FOUND_ROWSSQL_SMALL_RESULT
SSLSTARTINGSTRAIGHT_JOIN
TABLETERMINATEDTHEN
TINYBLOBTINYINTTINYTEXT
TOTRAILINGTRIGGER
TRUEUNDOUNION
UNIQUEUNLOCKUNSIGNED
UPDATEUSAGEUSE
USINGUTC_DATEUTC_TIME
UTC_TIMESTAMPVALUESVARBINARY
VARCHARVARCHARACTEVARYING
WHENWHEREWHILE
WITHWRITEX509
XORYEAR_MONTHZEROFILL

如果必须要用这些关键字和保留字,语言不同(比如xml或Java等)方式不同,可以尝试以下方案:

       1、使用 ` `(反向引号,与单波浪线~在同一按钮)将命名包围,推荐使用此符号,相对比较通用;

       2、使用[ ](半角中括号)将命名包围;

       3、使用" "(半角双引号,如果放在字符串中需要用\\进行转译)将命名包围;

以上是关于sql都有哪些保留字的主要内容,如果未能解决你的问题,请参考以下文章

关键字和保留字

T-SQL“LineNo”保留字究竟有啥作用?

SQL执行错误#1064---保留字错误

SQL对象命名使用保留字导致SQL Error: 1064, SQLState: 42000

SQL对象命名使用保留字导致SQL Error: 1064, SQLState: 42000

SQL对象命名使用保留字导致SQL Error: 1064, SQLState: 42000