Please visit my New Blog http://www.sqlserverdba.co.cc/

July 13, 2008

How to insert multple rows/records using single/one INSERT command

Filed under: DBA Programming — wwwtuneinin @ 4:20 pm

In SQL 2000/2005 there is no direct feature for this. Below is the workaround.

INSERT INTO tblSuppServers (ServerName,Type)
(SELECT ‘LAB1′,’Dev’)
UNION
(SELECT ‘LAB2′,’Dev’)
UNION
(SELECT ‘LAB3′,’Dev’)
GO

For SQL 2008:
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES (’First’,1),
(’Second’,2),
(’Third’,3),
(’Fourth’,4),
(’Fifth’,5)

Ref:
http://blog.sqlauthority.com/2008/07/02/sql-server-2008-insert-multiple-records-using-one-insert-statement-use-of-row-constructor/
http://www.daniweb.com/forums/thread34491.html

© 2007 Informe.com. Get Free Blog Hosting
Software tags powered by Software Informer
Powered by WordPress