Alter multiple columns in a table?


If you have to alter more than one columns at one time, you’d better redesign the table with your new requirements. By using Alter Table Alter column, you can modify column only one at a time.  If you do want to alter multiple columns, there is a way to work around this. You can drop the columns you want to modify and readd them to the table later with new definition. Here is a sample.

You can drop multiple columns(keep at least one column in your table) and add them back to your table with your new definitions.

— –Drop multiple columns

ALTER

TABLE testTable

DROP

COLUMN column_c1 ,

column_c2

,

column_c3

;

— –Add multiple columns

ALTER

TABLE testTable

Add

column_c1 Varchar(35) null,

column_c2

Varchar(35) null,

column_c3

Varchar(35) null;

 

http://forums.asp.net/t/1236370.aspx

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s