How to insert columns at a specific position in existing table?

if you are saying ADD COLUMN column_name then it will throw error

u have to try

 ALTER TABLE temp_name ADD My_Coumn INT(1) NOT NULL DEFAULT 1

remember if table already has few record and u have to create new column then either u have to make it nullable or u have to define the default value as I did in my query


Try this

ALTER TABLE tablename ADD column_name57 INT AFTER column_name56

See here


ALTER TABLE table_name ADD COLUMN column_name57 INTEGER AFTER column_name56

ALTER TABLE by default adds new columns at the end of the table. Use the AFTER directive to place it in a certain position within the table:

ALTER table table_name
    Add column column_name57 integer AFTER column_name56

From mysql doc

To add a column at a specific position within a table row, use FIRST or AFTERcol_name. The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table.

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

I googled for this for PostgreSQL but it seems to be impossible.

Tags:

Mysql

Sql