在 MySQL 中的特定列之后添加多列 [英] Adding multiple columns AFTER a specific column in MySQL

查看:38
本文介绍了在 MySQL 中的特定列之后添加多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向表中添加多列,但将列定位在之后名为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`;

检查语法

这篇关于在 MySQL 中的特定列之后添加多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆