Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding multiple columns to a table

Posted on 2006-06-15
5
Medium Priority
?
8,367 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 1600 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 200 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 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 200 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

971 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