在 MySQL 中的特定列之后添加多列

2021-11-20 00:00:00 mysql ddl alter-table

我需要向表中添加多列,但将列定位在之后名为lastname的列.

I need to add multiple columns to a table but position the columns after a column called lastname.

我已经试过了:

ALTER TABLE `users` ADD COLUMN
(
    `count` smallint(6) NOT NULL,
    `log` varchar(12) NOT NULL,
    `status` int(10) unsigned NOT NULL
) 
AFTER `lastname`;

我收到此错误:

您的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本以使用正确的语法靠近 ') AFTER lastname' 在第 7 行

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 ') AFTER lastname' at line 7


如何在这样的查询中使用 AFTER?


How can I use AFTER in a query like this?

推荐答案

试试这个

ALTER TABLE users
ADD COLUMN `count` SMALLINT(6) NOT NULL AFTER `lastname`,
ADD COLUMN `log` VARCHAR(12) NOT NULL AFTER `count`,
ADD COLUMN `status` INT(10) UNSIGNED NOT NULL AFTER `log`;

检查语法

相关文章