2016-11-09 75 views
0

我想知道如何在mysql中删除包含空格的列。 试过以下,并得到了以下情况除外:在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 

谢谢:)

+0

不列名包含空间? – Viki888

回答

0

您应该尝试使用back tick(“`”)来引用您的列名称。

ALTER TABLE test17 DROP COLUMN `added column2`; 

OR

无柱字

ALTER TABLE test17 DROP `added column2`; 
0

首先,空间列名是不好的做法。然后,如果你真的想删除一列,用反引号代替:

ALTER TABLE test17 DROP COLUMN `added_column2`; 
+0

是的,这是一个错误...谢谢:) – Dardar1991

0

尝试:

alter table test17 drop column `added column2`; 

注意,引号字符向左倾斜。顺便说一句,如果你将空格作为标识符名称的一部分(例如函数,过程,表格,列等),这是一个非常糟糕的做法。

+0

谢谢!初学者错误:/ – Dardar1991

+0

确实:-)。顺便说一下,如果您使用正常的命名方法(例如'ThisIsColumn_5'等,仅使用字母数字字符和'_',以字母开头),则可以避免将标识符包含在标题中。例如,你的情况就是:'alter table test17 drop column added_column2;'。最后,我的回答是第一个,但你选择将其他标记为答案... – FDavidov

+0

嗯,谢谢..我不知道我用另一个人的答案(没有列),所以我认为你选择了你实际的答案最终使用... – Dardar1991