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

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

原创:https://www.panoramacn.com
源码网提供WordPress源码,帝国CMS源码discuz源码,微信小程序,小说源码,杰奇源码,thinkphp源码,ecshop模板源码,微擎模板源码,dede源码,织梦源码等。

专业搭建小说网站,小说程序,杰奇系列,微信小说系列,app系列小说

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

免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。

您必须遵守我们的协议,如果您下载了该资源行为将被视为对《免责声明》全部内容的认可-> 联系客服 投诉资源
www.panoramacn.com资源全部来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。 敬请谅解! 侵权删帖/违法举报/投稿等事物联系邮箱:2640602276@qq.com
未经允许不得转载:书荒源码源码网每日更新网站源码模板! » Mysql关键字和保留字(注意)
关注我们小说电影免费看
关注我们,获取更多的全网素材资源,有趣有料!
120000+人已关注
分享到:
赞(0) 打赏

评论抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

您的打赏就是我分享的动力!

支付宝扫一扫打赏

微信扫一扫打赏