Wednesday, March 7, 2012

Programmatically adding new column at desired place...not at the end

I understand that adding new column programmatically (using ALTER TABLE...),
adds it at the end of the table. Is it possible to specify that this column
should be placed at the 3rd place (not at the end).
Thanks in advance
J JustinHi Justin,
No, You can not do that. Only way for that is to drop and recreate the table
with new order.
Thanks
Hari
SQL Server MVP
"Justin" <justin@.gjsoft.com> wrote in message
news:%231cEsy0NFHA.2736@.tk2msftngp13.phx.gbl...
> I understand that adding new column programmatically (using ALTER
> TABLE...),
> adds it at the end of the table. Is it possible to specify that this
> column
> should be placed at the 3rd place (not at the end).
> Thanks in advance
>
> J Justin
>
>|||As Hari said, you can't without dropping and recreating the table. And your
code shouldn't be dependent on the physical order of the columns. Logically
speaking, columns in a table do not have an order. All references to columns
should be by name and not by ordinal.
Jacco Schalkwijk
SQL Server MVP
"Justin" <justin@.gjsoft.com> wrote in message
news:%231cEsy0NFHA.2736@.tk2msftngp13.phx.gbl...
> I understand that adding new column programmatically (using ALTER
> TABLE...),
> adds it at the end of the table. Is it possible to specify that this
> column
> should be placed at the 3rd place (not at the end).
> Thanks in advance
>
> J Justin
>
>|||http://www.aspfaq.com/2528
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Justin" <justin@.gjsoft.com> wrote in message
news:#1cEsy0NFHA.2736@.tk2msftngp13.phx.gbl...
> I understand that adding new column programmatically (using ALTER
TABLE...),
> adds it at the end of the table. Is it possible to specify that this
column
> should be placed at the 3rd place (not at the end).
> Thanks in advance
>
> J Justin
>
>

No comments:

Post a Comment