删除mysql中包含空格的列

时间:2016-11-09 07:28:16

标签: mysql linux mysql-error-1064

我想知道如何在mysql中删除包含空格的列。 试过以下内容,并得到以下例外情况:

alter table test17 drop column [added column2];
ERROR 1064 (42000): 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 '[added column2]' at line 1

alter table test17 drop column 'added column2';
ERROR 1064 (42000): 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 ''added column2'' at line 1

alter table test17 drop column (added column2);
ERROR 1064 (42000): 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 '(added column2)' at line 1

感谢:)

3 个答案:

答案 0 :(得分:0)

首先,带空格的列名是BAD PRACTICE。然后,如果您确实要删除列,请改为使用反引号:

ALTER TABLE test17 DROP COLUMN `added_column2`;

答案 1 :(得分:0)

尝试:

alter table test17 drop column `added column2`;

请注意,引号字符向左倾斜。

顺便说一下,如果你将空格作为标识符名称的一部分(例如函数,过程,表格,列等),那就是非常非常不良做法。

答案 2 :(得分:0)

您应该尝试使用后退标记(“”“)来引用您的列名称。

ALTER TABLE test17 DROP COLUMN `added column2`;

OR

没有COLUMN字

ALTER TABLE test17 DROP `added column2`;