HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Add a new Column and define its position in a table

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
newcolumnpositionitsdefineandtableadd

Problem

I have Table A with 5 columns:

TableA
--
Name
Tel
Email
Address


I want to add a new column (mobile) in between Tel & Email:

TableA
--
Name
Tel
Mobile
Email
Address


If I use

ALTER TABLE TableA
ADD COLUMN Mobile INT NOT NULL


the mobile column is added to the end of the table.

Is there a way to achieve this without dropping the table and moving data to a new table?

Solution

No. Rebuilding the table is the only way. See this Connect Item for confirmation.

You could use SSMS to script this for you if you trust the somewhat buggy table designer.

Apart from that you could declare a view with the desired column order as a way of grouping logically related columns together.

Context

StackExchange Database Administrators Q#19536, answer score: 17

Revisions (0)

No revisions yet.