MySQL中的describe关键字

2022-07-11 12:42:28 浏览数 (1)

大家好,又见面了,我是全栈君。

今天写代码的时候,老是提示在You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘describe。 写SQL语句的时候删掉这个字段就不会报错,加上这个字段添加和查询又会报错,纠结了很久,最后终于试着把describe改为describes,可以正常插入数据,也可以正常查询了,后面在网上一查,describe竟然是mysql中的关键词,我们不能用这个作为数据库中的表的字段。

在SQL语句中出现的关键字和保留字 如果要使用人他们的字符意思而不是作为关键字、保留字使用,关键字可以正常使用,但是保留字必须使用`(键盘tab键上面,数字1左边的那个按键)来分割。这个在SQLServer里面是使用[]中括号实现的。所以我们要尽量避免使用关键字和保留字来作为表名和字段名。

代码语言:javascript复制
create table api_community_pic(
id int(11) unsigned not null auto_increment primary key comment '图片id',
user_id int(11) not null comment '用户id',
title varchar(255) not null default '' comment '图片标题',
`describe` varchar(255) not null default '' comment '图片描述',
s3_url varchar(255) not null default '' comment '图片s3路径',
praise int(10) NOT NULL DEFAULT '0' COMMENT '点赞数',
status tinyint(1) unsigned not null default '0' comment '图片状态: 0 等待审核 1 审核通过 2审核不通过',
created_at int(11) unsigned NOT NULL DEFAULT '0' COMMENT '上传时间'
)comment='图片表';

另外附上mysql保留字列表:

Reserved Words in

MySQL 5.6.23

ACCESSIBLE

ADD

ALL

ALTER

ANALYZE

AND

AS

ASC

ASENSITIVE

BEFORE

BETWEEN

BIGINT

BINARY

BLOB

BOTH

BY

CALL

CASCADE

CASE

CHANGE

CHAR

CHARACTER

CHECK

COLLATE

COLUMN

CONDITION

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

GET

GRANT

GROUP

HAVING

HIGH_PRIORITY

HOUR_MICROSECOND

HOUR_MINUTE

HOUR_SECOND

IF

IGNORE

IN

INDEX

INFILE

INNER

INOUT

INSENSITIVE

INSERT

INT

INT1

INT2

INT3

INT4

INT8

INTEGER

INTERVAL

INTO

IO_AFTER_GTIDS

IO_BEFORE_GTIDS

IS

ITERATE

JOIN

KEY

KEYS

KILL

LEADING

LEAVE

LEFT

LIKE

LIMIT

LINEAR

LINES

LOAD

LOCALTIME

LOCALTIMESTAMP

LOCK

LONG

LONGBLOB

LONGTEXT

LOOP

LOW_PRIORITY

MASTER_BIND

MASTER_SSL_VERIFY_SERVER_CERT

MATCH

MAXVALUE

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

PARTITION

PRECISION

PRIMARY

PROCEDURE

PURGE

RANGE

READ

READS

READ_WRITE

REAL

REFERENCES

REGEXP

RELEASE

RENAME

REPEAT

REPLACE

REQUIRE

RESIGNAL

RESTRICT

RETURN

REVOKE

RIGHT

RLIKE

SCHEMA

SCHEMAS

SECOND_MICROSECOND

SELECT

SENSITIVE

SEPARATOR

SET

SHOW

SIGNAL

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

XOR

YEAR_MONTH

ZEROFILL

NewReserved Words in MySQL 5.6

GET

IO_AFTER_GTIDS

IO_BEFORE_GTIDS

MASTER_BIND

ONE_SHOT

PARTITION

SQL_AFTER_GTIDS

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/112084.html原文链接:https://javaforall.cn

0 人点赞