Skip to Main Content
  • Questions
  • Alter columns order in a table (online)

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Geraldo.

Asked: January 17, 2020 - 6:50 pm UTC

Last updated: January 20, 2020 - 1:52 am UTC

Version: 18.6

Viewed 1000+ times

You Asked

Hello, Ask Tom.

I was asked to change the order of columns in a table. How can get this done without user interruption?

BTW, what do I gain ordering columns? Some space because null columns are placed at the end of the table? Performance?

Thanks in advanced.

and Connor said...

Unless the table has more than 255 columns, you get minimal gains from moving the columns around. It is *slightly* faster to do:

select [first_few_cols]
from table
where first_col = 


than

select [last_few_cols]
from table
where later_col = 


but we're talking fractions of a percent here.

In terms of space, once we hit the last non-null column, we don't need space for the any trailing nulls, so for example in a 10 column table:

A,null,B,null,C,null,D,null,E,null

uses a little more space then

A,B,C,D,E,null,null,null,null,null

but seriously... I would not be worrying about it. There are normally much bigger opportunities for performance improvement in terms of design, indexing and good SQL code

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.