mysql - issue in MySQL query due Table name 'CASE'
问题描述
I have installed a script from code canyon and that is having a table with the name of Case.
When I try to execute a query
SELECT COUNT(*) as total FROM case
it shows the following error
Static analysis:
1 errors were found during analysis.
Unexpected end of CASE expression (near "" at position 0)
SQL query: Documentation
SELECT COUNT(*) as total FROM case
MySQL said: Documentation
#1064 - 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 'case' at line 1
I know the case is a reserved word for MYSQL but now How I can resolve this because I can't change the table name and cant modify it into whole script.
解决方案
case
is a really poor name for a table or column name. It is obviously a SQL keyword. But, if you can't fix it, use backticks:
select count(*)
from `CASE`
That escapes the name and tells MySQL to treat it as the name of something, rather than the keyword.
I would encourage you to figure out how the database can be fixed. I generally name tables in the plural -- cases
for instance. First, they are plural because they almost always have more than one row. A side effect is that plurals conflict with many fewer keywords.
推荐阅读
- python - 我如何执行外键查询
- angular - 角材料滚动不显示
- laravel-backpack - 如何在 CRUD 创建和更新中禁用?
- mysql - 多态关系与每种类型的单独表
- javascript - 如何在 JS 中的特定索引处替换更多字符?
- math - 如何在具有相同填充的多个卷积后计算最终大小?
- javascript - 如何在仅允许模态内容滚动的同时固定模态的页眉和页脚?
- java - Dynamo DB 映射器在子类上调用时未将基类元素保存到 DB
- javascript - 为什么我的电子应用程序无法访问“fs”模块?
- python - GPIO 引脚在 While 循环中未打开