Ask Paula!

...bringing you notes from the field...
posts - 55, comments - 17, trackbacks - 0

My Links

News

Article Categories

Archives

Post Categories

.NET Development

Enterprise Integration

Java Development

Mobile/PDA Development

Professional Affiliations

Can I insert multiple rows with a single insert statement?

Yes! .....(Now, we're not talking about bulk inserts--which is a completely different task... we're just talking about a small number of rows that need to get inserted into a relatively static table)..

Typically folks do something like this to quickly add rows into a reference  table:

INSERT INTO ReasonType
(DisplayName,Description)
VALUES
('Delay','Reason for a project delay')
GO
INSERT into ReasonType
(DisplayName,Description)
VALUES
('Cancellation','Reaon for a project cancellation')
GO

...but it is possible to do this instead...

INSERT INTO ReasonType  (DisplayName, Description)
    SELECT  'Delay' ,'Reason for project delay'
    UNION ALL
SELECT  'Cancellation' ,'Reason for project cancellation'
    UNION ALL

 

Print | posted on Tuesday, January 13, 2009 8:54 AM | Filed Under [ SQL ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: