patternModerate
Add a new Column and define its position in a table
Viewed 0 times
newcolumnpositionitsdefineandtableadd
Problem
I have Table A with 5 columns:
I want to add a new column (mobile) in between Tel & Email:
If I use
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?
TableA
--
Name
Tel
Email
AddressI want to add a new column (mobile) in between Tel & Email:
TableA
--
Name
Tel
Mobile
Email
AddressIf I use
ALTER TABLE TableA
ADD COLUMN Mobile INT NOT NULLthe 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.
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.