News

Copyright © 2008-2018 Paula DiTallo

Tag Cloud



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

 

Tuesday, January 13, 2009 8:54 AM

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Comment:
Verification: