sql有哪些保留字

sql有哪些保留字,第1张

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

但是这里要提一下的是mysql是支持使用关键字做字段名的,但是针对保留关键字是必须要加引用。mysql官网提供了三个例子是可以很好的说明这些的。

interval begin、end都是关键字,interval是保留关键字,因此会报

mysql>CREATE TABLE interval (begin INT, end INT)

ERROR 1064 (42000): You have an error in your SQL syntax ...

near 'interval (begin INT, end INT)'

当给interval加上引用''后便可以正确执行该sql语句,也不会报begin、end的错,因为这是mysql允许的,但是不推荐这个用法,谁知道升级之后会不会变成保留字。。。。。。

mysql>CREATE TABLE `interval` (begin INT, end INT)

Query OK, 0 rows affected (0.01 sec)

(这个可以略过,,,,,反正不推荐使用关键字做这些事,)还有一种情况——内置函数的名字,官网是这样说的:

Names of built-in functions are permitted as identifiers but may require care to be used as such

mysql>CREATE TABLE mydb.interval (begin INT, end INT)

Query OK, 0 rows affected (0.01 sec)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9924703.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存