Using SQL keyword in title of table or column

杀马特。学长 韩版系。学妹 提交于 2019-11-29 11:29:09

wrap the tableName with backtick as ORDER is a reserved keyword.

SELECT * FROM `ORDER` ORDER BY NAME;

In my own opinion, using reserved keywords are fine except that you do not forget to handle it properly as it will give you such pain in the neck.

But through the years of designing schema, I never had used reserved keywords :D

As observed in another answer, backticks are used in MySQL to indicate that a word is a database object, thus preventing confusion with reserved words - in other dialects of SQL, square brackets [ ] (SQLServer) or double quotes " " (most other dialects) are used instead.

In my experience, using reserved words in table structures tends to cause problems, especially when writing new queries - it can take a while to realise that the error being returned is due to a reserved word being a column name. There's also the point (as the existence of this question indicates) that not everyone knows that you can get around the problem by using the appropriate quoting characters in your query.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!