Skip to Main Content

Need a command to reorder columns in a table

Torsten KleiberDec 12 2014 — edited Jan 11 2016

This isuseful from performance point of view if the columns changes for null to not null or in the other direction.

Not null columns, escpecially primary and foreign key columns are filled ever and should be at the start of a database block to keep it as small as possible.

The way to reach this goal is very complex and error prone at the moment:

- renaming the original table

- creating a new table with original name and the changed order

- inserting the values in the new table from the old table

- reassign foreign keys from old table to new table

- drop renamed old table

Post Details
Added on Dec 12 2014