问题描述
我是 SQL 新手,我试图更改数据库表中的列名.我正在使用xampp"和maria DB"(操作系统 - 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);
但我得到的唯一输出是:
But the only output I got was:
ERROR 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 中的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!