删除 mysql 中包含空格的列
deleting column containing white spaces in 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
谢谢:)
首先,带有 space 的列名是错误的做法。然后,如果您真的想删除列,请改用反引号:
ALTER TABLE test17 DROP COLUMN `added_column2`;
尝试:
alter table test17 drop column `added column2`;
注意引号字符向左倾斜。
顺便说一句,如果您将空格作为标识符名称的一部分(例如函数、过程、表、列等),那将是非常、非常 的错误做法.
您应该尝试使用反引号 ("`") 来引用您的列名。
ALTER TABLE test17 DROP COLUMN `added column2`;
或
没有COLUMN词
ALTER TABLE test17 DROP `added column2`;
我想知道如何在 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
谢谢:)
首先,带有 space 的列名是错误的做法。然后,如果您真的想删除列,请改用反引号:
ALTER TABLE test17 DROP COLUMN `added_column2`;
尝试:
alter table test17 drop column `added column2`;
注意引号字符向左倾斜。
顺便说一句,如果您将空格作为标识符名称的一部分(例如函数、过程、表、列等),那将是非常、非常 的错误做法.
您应该尝试使用反引号 ("`") 来引用您的列名。
ALTER TABLE test17 DROP COLUMN `added column2`;
或
没有COLUMN词
ALTER TABLE test17 DROP `added column2`;