Posts
825
Comments
689
Trackbacks
1
T-SQL: Can you alter multiple columns within a single alter table statement?

No.  You can add multiple columns, but you have to use a separate alter table statement for each column you want to alter.

posted on Monday, May 09, 2005 1:55 PM
Comments
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
x002548
5/6/2008 12:30 PM
Are you smoking something?

http://weblogs.sqlteam.com/brettk/category/72.aspx
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
jdn
5/6/2008 1:08 PM
Sorry, but your link has to do with updating multiple tables within an update statement.

I'm talking about altering multiple columns within a single alter table statement.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Major Singh
5/22/2008 3:51 AM
Yes, You can Add multiple columns with s single alter statement. The statement will be..
ALTER TABLE TABLENAME
ADD TEST1 varchar(100) NULL,
TEST2 varchar(100) NULL,
TEST3 varchar(100) NULL

Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
jdn
5/22/2008 6:23 PM
No, again, I'm talking about altering multiple columns within a single alter statement.

You are talking about adding them. Different thing.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Dercsár
8/26/2008 4:09 AM
jdn is right. You can not modify multiple columns in one statement, which is weird imo.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Carl
5/20/2009 10:27 AM
ALTER TABLE t ALTER COLUMN c1 int null;
ALTER TABLE t ALTER COLUMN c2 int null;
ALTER TABLE t ALTER COLUMN c3 int null;
ALTER TABLE t ALTER COLUMN c4 int null;
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
jdn
5/20/2009 11:19 PM


That's four alter table statements, as I indicated.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Darrick
10/8/2009 11:51 PM
Just came across this post... and I just wonder how the 3 suggested answers never bothered to read the original statement and kept suggesting the same thing as the previous poster :)
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Tilt
10/23/2009 7:21 AM


You, Sir, totally failed at misreading the Question. Instead of making sane and true statements you could have kept these comments a fun read by suggesting a query that updates multiple values in single column. But noooo...
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
ram
3/19/2011 3:39 PM
Thanks
Your help appreciated
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
ASPNETER
4/17/2011 1:41 AM
it is not possible to use Alter Table statement for altering multiple columns. Personally i do not accept those silly explanation about this serious limitation of SQL Server.
Therefor i consider this as a bug!
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
GiBi
6/21/2011 4:00 AM
This is funny; I had a problem with adding 2 columns to a table, I misread the title and kept reading, and I found my answer in Major Singh's post.
By the way, I was writing a similar statement WITH parenthesis enclosing the list of fields; I took them out, as in the above example, and it worked.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Rob
8/9/2011 6:16 PM
I too found my answer in Major Singh's post. For some reason this post came up top in Google when I was trying to find out why my t-sql syntax was not quite right for adding multiple columns to an already existing table using a single alter statement.

BTW - Tilt's response to Darrick is priceless. :)
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Mike
8/15/2011 10:29 AM
Thanks !
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Ramu
11/25/2011 1:33 AM
Thanq

Yes, I Can you alter multiple columns within a single alter table statement.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
jdn
11/26/2011 10:13 PM


No, you can't
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Ephraim Kerr
1/12/2012 8:39 AM
Nothing is impossible. Yes you can. Unfortunately you would need to create a cursor from metadata and write an alter statement for each column.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
jdn
1/13/2012 10:13 AM


With only a single alter table statement? I don't think so.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
Prestonean
3/26/2012 7:13 PM
But - you can use excel, list the column names, and do a simple concat formula to make as many ALTER statements as you need very quickly...
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
James
3/27/2012 11:18 AM
If you have the correct permissions you might be able to do an update statement on the columns table in the information_schema schemata instead.
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
James
3/27/2012 11:20 AM
Oh I see, this is MSSQL, lol. Don't you like money?
Gravatar
# re: T-SQL: Can you alter multiple columns within a single alter table statement?
RIck
5/17/2012 2:37 AM


Some of us work for a living

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 2 and 3 and type the answer here: