如何在Maria DB中重命名列名称 [英] How to rename a column name in maria DB
问题描述
我是SQL的新手,我试图更改数据库表中的列名.我正在将'xampp'与'maria DB'(OS-Ubuntu 18.04)一起使用
I am new to SQL, I was trying to change column name in my database's table. I am using 'xampp' with 'maria DB' (OS - Ubuntu 18.04)
我尝试了以下所有操作:
I tried all of the followings:
ALTER TABLE subject RENAME COLUMN course_number TO course_id;
ALTER TABLE subject CHANGE course_number course_id;
ALTER TABLE subject CHANGE 'course_number' 'course_id';
ALTER TABLE subject CHANGE COLUMN 'course_number' course_id varchar(255);
ALTER TABLE subject CHANGE 'course_number' 'course_id' varchar(255);
但是我唯一的输出是:
错误1064(42000):您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第1行的"column course_number to course_id"附近使用
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'column course_number to course_id' at line 1
有人可以告诉我正确答案是什么.我不知道该怎么做.
Could someone please tell me what is the correct answer. I have no idea what to do further.
推荐答案
表名,列名等可能需要用反引号引起来,而不需要用撇号('
)或双引号("
).
Table names, column names, etc, may need quoting with backticks, but not with apostrophes ('
) or double quotes ("
).
ALTER TABLE subject
CHANGE COLUMN `course_number` -- old name; notice optional backticks
course_id -- new name
varchar(255); -- must include all the datatype info
这篇关于如何在Maria DB中重命名列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!