...bringing you notes from the field...

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

 


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

No comments posted yet.