Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ALTER table - only add one column at a time?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01331519
Message ID:
01331521
Views:
12
This message has been marked as the solution to the initial question of the thread.
Naomi,

According to SQL BOL, you should be able to add multiple columns in a single ALTER statement.

Here's an portion of what BOL says...
E. Alter a table to add several columns with constraints
This example adds several columns with constraints defined with the new column. The first new column has an IDENTITY property; each row in the table has new incremental values in the identity column.

CREATE TABLE doc_exe ( column_a INT CONSTRAINT column_a_un UNIQUE) 
GO
ALTER TABLE doc_exe ADD 

/* Add a PRIMARY KEY identity column. */ 
column_b INT IDENTITY
CONSTRAINT column_b_pk PRIMARY KEY, 

/* Add a column referencing another column in the same table. */ 
column_c INT NULL  
CONSTRAINT column_c_fk 
REFERENCES doc_exe(column_a),

/* Add a column with a constraint to enforce that   */ 
/* nonnull data is in a valid phone number format.  */
column_d VARCHAR(16) NULL 
CONSTRAINT column_d_chk
CHECK 
(column_d IS NULL OR 
column_d LIKE "[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]" OR
column_d LIKE
"([0-9][0-9][0-9]) [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]"),

/* Add a nonnull column with a default.  */ 
column_e DECIMAL(3,3)
CONSTRAINT column_e_default
DEFAULT .081
GO
EXEC sp_help doc_exe
GO
DROP TABLE doc_exe
GO
Kurt
>Hi everybody,
>
>I found it strange that in SQL Server you can only add one column at a time in ALTER TABLE command. I think I discussed it here before (yes, though slightly different problem Re: Change multiple columns at once Thread #1291185 Message #1291322). In VFP you can add multiple columns at once.
>
>This is quite inconvenient.
>
>Thanks in advance.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform