我通过python将数据帧作为表导入到mysql服务器(表名=提示)。在此过程中,我无意中将名为“索引”和“未命名:0”的列添加到mysql服务器。我尝试了不同的方法来删除下面的列。
alter table tips drop 'index';
alter table tips drop column 'index';
alter table tips drop [index];
alter table tips drop ['index'];
对于上面下面“索引”列的所有语句,都是错误。
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 ''index'' at line 1
我为“未命名:0”尝试了相同的操作
alter table tips drop 'Unnamed: 0';
alter table tips drop column 'Unnamed: 0';
alter table tips drop [Unnamed: 0];
alter table tips drop ['Unnamed: 0'];
对于上面下面“未命名:0”的所有语句,都是错误。
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 ''Unnamed: 0'' at line 1
答案 0 :(得分:1)
当列名包含保留字或无效字符时,必须在反引号(`)中用引号引起来。改用它:
alter table tips drop column `index`, drop column `Unnamed: 0`