我想在我的博客表中将一列从 read-more 重命名为 read_more
我尝试了所有这些:
ALTER TABLE blog RENAME COLUMN read-more to read_more; ALTER TABLE blog CHANGE COLUMN 'read-more' 'read_more' VARCHAR(255) NOT NULL;
我总是得到这个!
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 'COLUMN read-more to read_more' at line 1
我正在使用 MySQL 5.5
有效语法接近您的第二次尝试,但您需要使用反引号而不是单引号来转义列名:
ALTER TABLE `blog` CHANGE COLUMN `read-more` `read_more` VARCHAR(255) NOT NULL;