January 9, 2010 at 5:30 am
hi
I have 3 columns .
I want to add one more column to the table after 2 column.
January 9, 2010 at 5:52 am
Why does it have to be after the 2nd column?
If you absolutely have to have the table design in that order (for whatever reason), create a new table, copy all the data over, add all the constraints, drop the old table.
There's no support for adding columns in specific places, because there's no meaning to column 'position' in SQL server. If you want the columns returned in a particular order, change the order they are specified in the select clause.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 9, 2010 at 5:53 am
by default, all columns are added to the end to a table; to add one in the middle, you have to rebuild the whole table.
SQL doesn't care about column order or even the order of the rows in the data.
for aesthetic reasons (meaning it looks right to you), it's probably easiest to use SQL Server Management Studio to do this, because the designer lets you change the column order, and then does all the hard work for you...it rebuilds the table, as well as movinf data nad all related constraints.
Lowell
January 9, 2010 at 11:32 am
Lowell (1/9/2010)
for aesthetic reasons (meaning it looks right to you), it's probably easiest to use SQL Server Management Studio to do this, because the designer lets you change the column order, and then does all the hard work for you...it rebuilds the table, as well as movinf data nad all related constraints.
That said, if you do use management studio and there are thousands or millions of rows in the table, it could take quite some time to run.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 12, 2010 at 12:54 pm
If you use SQL Server 2008, then once you query this table and the output is in the grid then you will be able to just drag the column of your interest to whatever position you want.
January 12, 2010 at 1:01 pm
GilaMonster (1/9/2010)
Lowell (1/9/2010)
for aesthetic reasons (meaning it looks right to you), it's probably easiest to use SQL Server Management Studio to do this, because the designer lets you change the column order, and then does all the hard work for you...it rebuilds the table, as well as movinf data nad all related constraints.That said, if you do use management studio and there are thousands or millions of rows in the table, it could take quite some time to run.
And if it has that many rows, it will probably timeout as well.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply