all groups > sql server (alternate) > july 2003 >
You're in the

sql server (alternate)

group:

How can I insert a column using a script (instead of appending)?


How can I insert a column using a script (instead of appending)? warren.wright NO[at]SPAM us.scorex.com
7/30/2003 11:44:30 AM
sql server (alternate): Hi,

I recently had to add a new column to a table that resides off-site,
in a customer's environment. Previously, the table had around 300
columns, all of which were in alphabetical order.

I found that the ALTER TABLE command appeared to be only capable of
appending a new column, but wasn't capable of inserting one into the
middle of the table.

Since alphabetical order wasn't a requirement, but just a "nice to
look at" feature, I appended it anyway, and forgot about it.

Anyone know of a clever way to do this though?

Curiously,

Warren Wright
Re: How can I insert a column using a script (instead of appending)? Erland Sommarskog
7/30/2003 7:35:31 PM
Warren Wright (warren.wright@us.scorex.com) writes:
[quoted text, click to view]

The "clever" way is to fiddle with syscolumns, but I highly discourge
from this.

The normal way is to go the long way: rename the old table, create
the new table including triggers, constrains and clustered index, insert
data from the old table to the new, move referencing foreign keys, drop the
old table. Restore non-clustered index.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button