我已经从代码峡谷安装了一个脚本,并且有一个名为Case的表。
当我尝试执行查询时
SELECT COUNT(*) as total FROM case
它显示以下错误
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
我知道这种情况是MYSQL的保留字,但现在我该如何解决此问题,因为我无法更改表名,也无法将其修改为整个脚本。
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:这会转义名称,并告诉MySQL将其视为某物的名称,而不是关键字。
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.