Monday 20 November 2017

ddl - Adding multiple columns AFTER a specific column in MySQL

itemprop="text">

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?


class="post-text" itemprop="text">
class="normal">Answer



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 href="http://dev.mysql.com/doc/refman/5.1/en/alter-table.html">syntax



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...