Solved

Adding multiple columns to a table

Posted on 2006-06-15
5
8,360 Views
Last Modified: 2008-03-03
is there a way to add multiple columns to a table with one alter statement? does Sql Server even support such?
0
Comment
Question by:crishna1
5 Comments
 
LVL 5

Accepted Solution

by:
bwdowhan earned 400 total points
ID: 16913358
Yes you can,

Alter table my_table add
   [field1] [int] NULL,
   [field2] [varchar(30)] NULL,
   [field3} [int] NULL
0
 
LVL 5

Expert Comment

by:bwdowhan
ID: 16913368
oops... the last line should be [field3] [int] NULL

I mistype the closing square bracket as a closing curly bracket.
0
 
LVL 20

Assisted Solution

by:Sirees
Sirees earned 50 total points
ID: 16913395
Yes

alter  table tablename
add  Col1 varchar(10) ,  
     Col2 varchar(10)
0
 

Author Comment

by:crishna1
ID: 16913794
is this a new feature in 2005 or has it been there always? i thought Sql Server did'nt allow that earlier, i might be wrong.
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 50 total points
ID: 16914830
That has been there for quite a while.  You can *add* several columns at once, but you can only *alter* one column at a time; perhaps that is what you were thinking of.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop to go backward 90 days 2 18
SQL Server 2012 r2 - Query results have 2 seperate results instead of 1 2 22
CPU high usage when update statistics 2 28
SQL view 2 26
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question