maxtwoknight
maxtwoknight

Reputation: 5346

Is it possible to alter multiple columns in one statement in MS SQL?

I am trying to add default values to a group of columns, but I get a syntax error when I combine them all into one statement like this:

ALTER TABLE drawinglist 
ADD CONSTRAINT ISOKEYPLAN_DWGTITLEPREFIX_def DEFAULT 0 FOR ISOKEYPLAN_DWGTITLEPREFIX,
ADD CONSTRAINT PIPE_VENDOR_def DEFAULT 0 FOR PIPE_VENDOR;

Is the above syntax (or something similar) possible or do I have to separate them all out into their own statements?

Upvotes: 3

Views: 1402

Answers (1)

rsbarro
rsbarro

Reputation: 27339

The documentation for ALTER TABLE says you can. The SQL below should work:

ALTER TABLE drawinglist 
ADD 
    CONSTRAINT ISOKEYPLAN_DWGTITLEPREFIX_def DEFAULT 0 FOR ISOKEYPLAN_DWGTITLEPREFIX,
    CONSTRAINT PIPE_VENDOR_def DEFAULT 0 FOR PIPE_VENDOR;
GO

I tested on a dev database I have and that syntax worked in SQL Server 2008.

Upvotes: 2

Related Questions