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

标签 mysql ddl alter-table

我需要向一个表中添加多个列,但将这些列放置在 一个名为 lastname 的列之后。

我试过这个:

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

我收到此错误:

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?

最佳答案

试试这个

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`;

查看syntax

关于mysql - 在 MySQL 中的特定列之后添加多个列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17541312/

相关文章:

mysql - "Error Code: 1205. Lock wait timeout exceeded; try restarting transaction"删除事件

javascript - 通过从 mysql 数据库获取图像的 URL 显示来自 S3 的图像

php - 你能从一个 MySQL 查询中得到 2 个不同的结果吗?

postgresql - 如何使用 Postgresql 创建脚本来参数化序列的起始值

MySQL 如果我改变它所在的列,索引会发生什么?

mysql - SQL 内连接不返回正确的答案

java - Oracle ORA-29536 关于 DDL-将 java 源加载到数据库中

SQL 更改表然后修改值

postgresql - Postgres ALTER TABLE 的问题

postgresql - 从 PostgreSQL 中的所有对象中删除 COMMENT ON