简体   繁体   English

如何重命名 maria DB 中的列名

[英]How to rename a column name in maria DB

I am new to SQL, I was trying to change column name in my database's table.我是 SQL 新手,我试图更改数据库表中的列名。 I am using 'xampp' with 'maria DB' (OS - Ubuntu 18.04)我正在使用“xampp”和“maria DB”(操作系统 - 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): You have an error in your SQL syntax; ERROR 1064 (42000):您的 SQL 语法有错误; 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检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的“column course_number to course_id”附近使用正确的语法

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

Starting with MariaDB 10.5.2 you should be able to do从 MariaDB 10.5.2 开始,您应该能够做到

ALTER TABLE subject RENAME COLUMN course_number TO course_id;

see https://mariadb.com/kb/en/alter-table/#rename-columnhttps://mariadb.com/kb/en/alter-table/#rename-column

alter table "table_name" change column "old_name" "New_name" "datatype" ; alter table "table_name"改变列"old_name" "New_name" "datatype" ;

there is no need to use "TO" between old_name & New_name , datatype of new_name is must old_name 和 New_name 之间不需要使用“TO”,new_name 的数据类型是必须的

eg - alter table student change column "id" "roll_no" "int" ;例如 -更改表学生更改列“id”“roll_no”“int”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM