Mysql关键字和保留字(注意)

   日期:2020-04-30     浏览:93    评论:0    
核心提示:check the manual that corresponds to your MySQL se数据库

SQLGrammarException:

头部错误信息:

2019-09-24 14:51:11.842  INFO 6728 --- [nio-9002-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 18 ms
Hibernate: select recruit0_.id as id1_1_0_, recruit0_.address as address2_1_0_, recruit0_.condition as conditio3_1_0_, recruit0_.content1 as content4_1_0_, recruit0_.content2 as content5_1_0_, recruit0_.createtime as createti6_1_0_, recruit0_.education as educatio7_1_0_, recruit0_.eid as eid8_1_0_, recruit0_.jobname as jobname9_1_0_, recruit0_.label as label10_1_0_, recruit0_.salary as salary11_1_0_, recruit0_.state as state12_1_0_, recruit0_.type as type13_1_0_, recruit0_.url as url14_1_0_ from tb_recruit recruit0_ where recruit0_.id=?
Hibernate: insert into tb_recruit (address, condition, content1, content2, createtime, education, eid, jobname, label, salary, state, type, url, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2019-09-24 14:51:11.939  WARN 6728 --- [nio-9002-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1064, SQLState: 42000
2019-09-24 14:51:11.939 ERROR 6728 --- [nio-9002-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : 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 'condition, content1, content2, createtime, education, eid, jobname, label, salar' at line 1
2019-09-24 14:51:11.939  INFO 6728 --- [nio-9002-exec-2] o.h.e.j.b.internal.AbstractBatchImpl     : HHH000010: On release of batch it still contained JDBC statements
2019-09-24 14:51:11.943 ERROR 6728 --- [nio-9002-exec-2] o.h.i.ExceptionMapperStandardImpl        : HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:242)

。。。。。。。中间的省略

	at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
	at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:536)
	... 72 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'condition, content1, content2, createtime, education, eid, jobname, label, salar' at line 1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'condition, content1,

condition mysql5.7的保留字,因数据库某表中一字段用的condition,结果在用spring-boot-jpa的时候新增记录,一直失败。

又如: Desc,mysql保留的关键字,在创建字段时给自己提个醒!!!

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
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 'Desc, TestWebUrl, UpdateTime, WebUrl) values (null, 'ajaxurl', 'baby-techcenter-' at line 1

关键字VS保留字

SQL和编程语言一样,是有关键字的。但是我们所理解的关键字在SQL中分为两类:

关键字

这类字在Mysql中具有特殊含义,例如常见的alter、static、cache。虽然具有特殊含义,但是还是可以作为Mysql中的标识符来使用的。例如你创建一个表名为static的表并没有什么问题,但是在实际中不推荐这么做。

保留字

这类字在Mysql中就比较强势了。保留字,顾名思义,就是Mysql自身保留的标识符。一般情况下是不允许使用的,例如select、insert等。但是有两种例外的情况:

加反引号,即可当做正常的标识符使用
接在另一个合法的标识符后面,例如你创建一个mydb.insert表,就是没有问题的。
不过话说回来,谁会这么做呢?

Mysql命名建议

用英文,如果不知道怎么表述,就去google,千万不要用汉语拼音将就;
不要使用关键字、更不要使用保留字;
尽量使用统一的前缀。

参考:https://dev.mysql.com/doc/refman/5.7/en/keywords.html
参考:https://blog.csdn.net/hfut_wowo/article/details/81011952

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服