欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql中的保留字段产生的问题

程序员文章站 2024-03-01 09:45:28
you have an error in your sql syntax; check the manual that corresponds to your mysql...

you have an error in your sql syntax; check the manual that corresponds to your mysql server versio····这句话对于咱们并不陌生,无非就是多了“,”之类的问题。但是你如果无意之中添加了一个mysql中的保留字段作为数据库中存贮的字段名,悲剧就这样发生了。

前几天因为功能的临时变更,需要给数据表添加一个字段用来区别导入的批次,我就在mysql中添加了group字段,没想到我的噩梦就此展开·····
  本来程序已经接近收尾,本想着今早来公司给程序来个欢乐的结尾,没想到····每次导入excel表总是提示我sql语句错误,我变在sql语句上添添减减,也没有把错误搞定,整整一个上午外加下午两个小时,简直已经到了抓狂的程度。简直要跪地苦思冥想,但是还是没有搞定这个错误。
  把问题放在一边,继续搞其他的东西····当在写一个group by 语句时,突然意识到,group 是mysql的一个保留字,就此问题迎刃而解。切记切记,多么痛的领悟啊

mysql的保留字段

在mysql中,下表中的字显式被保留。其中大多数字进制被标准sql用作列名和/或表名(例如,group)。少数被保留了,因为mysql需要它们,在mysql中,当表名或字段名乃至数据库名和保留字冲突时,在sql语句里可以用撇号()括起来,当让我们一般都尽量少使用这些保留的字段。

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 connection 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
goto 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 is
iterate join key
keys kill label
leading leave left
like limit linear
lines load localtime
localtimestamp lock long
longblob longtext loop
low_priority match 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
precision primary procedure
purge raid0 range
read reads real
references regexp release
rename repeat replace
require restrict return
revoke right rlike
schema schemas second_microsecond
select sensitive separator
set show 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 x509
xor year_month zerofill