MacOS Mojave,MySQL Server版本:10.1.39-MariaDB源分发
制作CRUD应用,但我想更改表格列,
从text
到desc
,所以我搜索并使用了alter
命令,但是正确的SQL命令返回错误消息。
MariaDB [cake_cms]> describe interns;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | | NULL | |
| name | varchar(64) | NO | | NULL | |
| text | varchar(255) | NO | | NULL | |
| location | varchar(64) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
MariaDB [cake_cms]> Alter Table interns Rename Column text to desc;
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 text to desc' at line 1
https://www.dbonline.jp/mysql/table/index18.html
说要使用
ALTER TABLE table_name
CHANGE COLUMN old_name TO new_name;
Rename a column in MySQL 该网站说:
ALTER TABLE tableName RENAME COLUMN "oldcolname" TO "newcolname" datatype(length);
所以我写
alter table interns rename column "name" to "newname" varchar(255);
但是返回了语法错误消息。...
我不知道该怎么办。请帮我!
答案 0 :(得分:0)
desc是一个sql命令,因此您不能这样命名表