I created a table with 85 columns but I missed one column. The missed column should be the 57th one. I don't want to drop that table and create it again. I'm looking to edit that table and add a column in the 57th index.
I tried the following query but it added a column at the end of the table.
ALTER table table_name Add column column_name57 integer
How can I insert columns into a specific position?
The position of the column cannot be specifically given. If you need a column list in a certain order, then use a view. SELECT * FROM table_x ; new_col will appear last.
ALTER TABLE table_name ADD COLUMNS (user_id BIGINT); Now to make user_id column as the first column in your table use change column with FIRST clause: ALTER TABLE table_name CHANGE COLUMN user_id user_id BIGINT first; This will move the user_id column to the first position.
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
orAFTER
col_name
. The default is to add the column last. You can also useFIRST
andAFTER
inCHANGE
orMODIFY
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With