Insert multiple rows WITHOUT repeating the "INSERT INTO ..." part of the statement? Insert multiple rows WITHOUT repeating the "INSERT INTO ..." part of the statement? sql-server sql-server

Insert multiple rows WITHOUT repeating the "INSERT INTO ..." part of the statement?


Your syntax almost works in SQL Server 2008 (but not in SQL Server 20051):

CREATE TABLE MyTable (id int, name char(10));INSERT INTO MyTable (id, name) VALUES (1, 'Bob'), (2, 'Peter'), (3, 'Joe');SELECT * FROM MyTable;id |  name---+---------1  |  Bob       2  |  Peter     3  |  Joe       

1 When the question was answered, it was not made evident that the question was referring to SQL Server 2005. I am leaving this answer here, since I believe it is still relevant.


INSERT INTO dbo.MyTable (ID, Name)SELECT 123, 'Timmy'UNION ALLSELECT 124, 'Jonny'UNION ALLSELECT 125, 'Sally'

For SQL Server 2008, can do it in one VALUES clause exactly as per the statement in your question (you just need to add a comma to separate each values statement)...


If your data is already in your database you can do:

INSERT INTO MyTable(ID, Name)SELECT ID, NAME FROM OtherTable

If you need to hard code the data then SQL 2008 and later versions let you do the following...

INSERT INTO MyTable (Name, ID)VALUES ('First',1),('Second',2),('Third',3),('Fourth',4),('Fifth',5)