Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-08-26 : 04:43:48
|
Hi,How is it possible to set the column ordinal i.e. position of a new column when using the alter table statement?It seems when using alter table add... it adds the column at the end of the existing columns. I would like to also set the position of the column being added to.How is this done please?Thanks |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-26 : 04:44:08
|
No. N 56°04'39.26"E 12°55'05.63" |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-08-26 : 04:44:53
|
I see.Thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-26 : 11:33:25
|
can i ask the need of this requirement? you can always retrieve column in order you want right?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-08-27 : 01:56:32
|
"I would like to also set the position of the column being added to.How is this done please?"Create new temporary table with all columns, in desired orderINSERT data into new temporary table, from old table.DROP old tableRENAME new temporary table to old tableplus some messing around with dropping and recreating constraints / FKeys / indexes etc.Use the GUI in SSMS. Add the column at the bottom and DRAG it to the desired position - or click on a column and INSERT a blank row where you want your new column.Then use the GENERATE SCRIPT button to give you a script which will do all the steps above Personally I like to have the columns in my tables grouped by any common theme - rather than adding a new column miles away at the end of the table. |
 |
|
|
|
|