Hi,
How to insert multiple records in a single statement? what are the possible ways?
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 5, 2012, 11:12 AM
There are lot of ways in sql server.
1) If you are trying to insert from the selected records then
INSERT INTO tmpProducts(tProductID, tProductName, tManfacturer )
SELECT DISTINCT ProductID, ProductName, Manfacturer FROM Products
2) You can use the derived table to insert multiple records
SELECT * INTO #tmpProducts FROM Products
3) From sql server 2008 onwards
4) Using the union all
INSERT INTO MyTable (FirstCol, SecondCol)
VulpesPosted Apr 5, 2012, 10:54 AM
However, for SQL Server, I'd check the examples in this link:
http://msdn.microsoft.com/en-us/library/ms174335.aspx