Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple columns AFTER a specific column in MySQL

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

I have tried this:

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

I get this error:

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


How can I use AFTER in a query like this?

like image 460
Koala Avatar asked Jul 09 '13 06:07

Koala


People also ask

How do I add a column after a particular column in MySQL?

The syntax to add a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ]; table_name.

Can I add multiple column in MySQL?

First, you specify the table name after the ALTER TABLE clause. Second, you put the new column and its definition after the ADD COLUMN clause. Note that COLUMN keyword is optional so you can omit it. Third, MySQL allows you to add the new column as the first column of the table by specifying the FIRST keyword.


1 Answers

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

check the syntax

like image 59
Ayyappan Sekar Avatar answered Oct 04 '22 07:10

Ayyappan Sekar