<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Insert Multiple Records Using One Insert Statement &#8211; Use of UNION ALL</title>
	<atom:link href="http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Mon, 13 Feb 2012 15:11:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: James</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-250613</link>
		<dc:creator><![CDATA[James]]></dc:creator>
		<pubDate>Thu, 09 Feb 2012 17:09:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-250613</guid>
		<description><![CDATA[Remove the last &quot;UNION ALL&quot;. 
If you look at the example, there&#039;s no &quot;UNION ALL&quot; after the final entry. I haven&#039;t tried it but this is my guess as to why you might be getting errors.]]></description>
		<content:encoded><![CDATA[<p>Remove the last &#8220;UNION ALL&#8221;.<br />
If you look at the example, there&#8217;s no &#8220;UNION ALL&#8221; after the final entry. I haven&#8217;t tried it but this is my guess as to why you might be getting errors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deepak</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-244101</link>
		<dc:creator><![CDATA[Deepak]]></dc:creator>
		<pubDate>Thu, 26 Jan 2012 15:46:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-244101</guid>
		<description><![CDATA[INSERT INTO checkmultipleinsert(id , name)
VALUES (1 , &#039;A&#039;) , (2 , &#039;B&#039;) , (3 ,&#039;C&#039;);
 
this query genrate an error:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near &#039;,&#039;.
 
I have sql2008 pls reply]]></description>
		<content:encoded><![CDATA[<p>INSERT INTO checkmultipleinsert(id , name)<br />
VALUES (1 , &#8216;A&#8217;) , (2 , &#8216;B&#8217;) , (3 ,&#8217;C');</p>
<p>this query genrate an error:</p>
<p>Msg 102, Level 15, State 1, Line 2<br />
Incorrect syntax near &#8216;,&#8217;.</p>
<p>I have sql2008 pls reply</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rosemarie</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-235155</link>
		<dc:creator><![CDATA[Rosemarie]]></dc:creator>
		<pubDate>Wed, 11 Jan 2012 07:43:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-235155</guid>
		<description><![CDATA[This page really great...

Please give me a script that once i entered four digit numbers i can insert it to the database as many as i can instead of inserting it one by one.. i have here the script but i dont know how to insert it even 100 times in one click.

$sqllucky = &quot;INSERT INTO lucky (userid,lucky1,lucky2,lucky3,lucky4,ldate) VALUES (&#039;$userid&#039;,&#039;$lucky1&#039;,&#039;$lucky2&#039;,&#039;$lucky3&#039;,&#039;$lucky4&#039;,now())&quot;;
$luckyresult = connect($sqllucky);

that snippet can inserted one by one what if i want to insert 10 times...please help me...]]></description>
		<content:encoded><![CDATA[<p>This page really great&#8230;</p>
<p>Please give me a script that once i entered four digit numbers i can insert it to the database as many as i can instead of inserting it one by one.. i have here the script but i dont know how to insert it even 100 times in one click.</p>
<p>$sqllucky = &#8220;INSERT INTO lucky (userid,lucky1,lucky2,lucky3,lucky4,ldate) VALUES (&#8216;$userid&#8217;,'$lucky1&#8242;,&#8217;$lucky2&#8242;,&#8217;$lucky3&#8242;,&#8217;$lucky4&#8242;,now())&#8221;;<br />
$luckyresult = connect($sqllucky);</p>
<p>that snippet can inserted one by one what if i want to insert 10 times&#8230;please help me&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Lane</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-232541</link>
		<dc:creator><![CDATA[Justin Lane]]></dc:creator>
		<pubDate>Fri, 06 Jan 2012 17:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-232541</guid>
		<description><![CDATA[Wow, in my tests the 2008 method is actually about 2 x slower than the Table Variable method.  AND it is limited to 1000 rows.]]></description>
		<content:encoded><![CDATA[<p>Wow, in my tests the 2008 method is actually about 2 x slower than the Table Variable method.  AND it is limited to 1000 rows.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Lane</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-232525</link>
		<dc:creator><![CDATA[Justin Lane]]></dc:creator>
		<pubDate>Fri, 06 Jan 2012 17:08:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-232525</guid>
		<description><![CDATA[Pinal,

Hmmm I just noticed the update you wrote at the top.
(ie 2008 method of Row Construction).  

I wonder how my method compares in performance.

I might give it some testing.]]></description>
		<content:encoded><![CDATA[<p>Pinal,</p>
<p>Hmmm I just noticed the update you wrote at the top.<br />
(ie 2008 method of Row Construction).  </p>
<p>I wonder how my method compares in performance.</p>
<p>I might give it some testing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Lane</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-232520</link>
		<dc:creator><![CDATA[Justin Lane]]></dc:creator>
		<pubDate>Fri, 06 Jan 2012 16:58:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-232520</guid>
		<description><![CDATA[FYI - I have done extensive research regarding this original post, and according to my research the fastest way to insert bulk data via SQL is to use a Table Variable as follows...

DECLARE @TblVar table (FirstCol nvarchar(50), SecondCol int)

INSERT INTO @TblVar
         VALUES (&#039;First&#039;,1);

INSERT INTO @TblVar
         VALUES (&#039;Second&#039;,2);
 
INSERT INTO MyTable (FirstCol, SecondCol)
        SELECT * from @TblVar

Sure it is not a single statement.  But... it was about 4 times faster than the UNION ALL method.

For large numbers of records I got better performance by grouping 1000 records at a time (ie repeating the SQL above for every 1000 records).  I ran each group of 1000 records as a separate script.

I welcome any feedback...]]></description>
		<content:encoded><![CDATA[<p>FYI &#8211; I have done extensive research regarding this original post, and according to my research the fastest way to insert bulk data via SQL is to use a Table Variable as follows&#8230;</p>
<p>DECLARE @TblVar table (FirstCol nvarchar(50), SecondCol int)</p>
<p>INSERT INTO @TblVar<br />
         VALUES (&#8216;First&#8217;,1);</p>
<p>INSERT INTO @TblVar<br />
         VALUES (&#8216;Second&#8217;,2);</p>
<p>INSERT INTO MyTable (FirstCol, SecondCol)<br />
        SELECT * from @TblVar</p>
<p>Sure it is not a single statement.  But&#8230; it was about 4 times faster than the UNION ALL method.</p>
<p>For large numbers of records I got better performance by grouping 1000 records at a time (ie repeating the SQL above for every 1000 records).  I ran each group of 1000 records as a separate script.</p>
<p>I welcome any feedback&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-231043</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Wed, 04 Jan 2012 06:19:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-231043</guid>
		<description><![CDATA[No, Union all cannot be used to delete rows from a table]]></description>
		<content:encoded><![CDATA[<p>No, Union all cannot be used to delete rows from a table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karthick prabhu</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-230996</link>
		<dc:creator><![CDATA[karthick prabhu]]></dc:creator>
		<pubDate>Wed, 04 Jan 2012 04:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-230996</guid>
		<description><![CDATA[Is This Works for Delete?]]></description>
		<content:encoded><![CDATA[<p>Is This Works for Delete?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajeev</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-227784</link>
		<dc:creator><![CDATA[Rajeev]]></dc:creator>
		<pubDate>Thu, 29 Dec 2011 05:20:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-227784</guid>
		<description><![CDATA[Select AcType, MainCode, Balance from Master where AcType between &#039;01&#039; and &#039;07&#039; and Balance&gt;100000

Union

Select AcType, &quot;~&quot;, SUM(Balance) from Master where AcType between &#039;01&#039; and &#039;07&#039; and Balance&gt;100000

Group by AcType
Order by AcType



Result will be

                         Head Office
           Wednesday, December 7, 2011

07/12/2011 3:51:32 PM User : RAJEEV  Station : GFL  Page : 1
----------------------------------------------------
AcType MainCode             Balance
----------------------------------------------------
01     00101086GP                193,104.78
01     ~                                   193,104.78
04     00100427Y5                276,045.42
04     00100620Y1                255,202.44
04     00100751IA                128,244.86
04     00101157IA                462,052.60
04     ~                                1,121,545.32
05     00100865GP                190,150.05
05     00101298GP                166,621.25
05     ~                         356,771.30
07     001000000107              167,489.78
07     001000000307              155,108.62
07     001000000407              431,436.82
07     001000000507              316,170.47
07     001000000907              239,352.41
07     001000001107              154,044.20
07     001000001307              267,387.29
07     001000001407              990,851.57
07     001000001607              263,150.63
07     ~                       2,984,991.79
 ====================  (End of Report)


---- &gt; Now I want to do as follows

                
                    Head Office
       Wednesday, December 7, 2011

07/12/2011 3:51:32 PM User : RAJEEV  Station : GFL  Page : 1
----------------------------------------------------
AcType MainCode             Balance
----------------------------------------------------
01     00101086GP                193,104.78
01     ~                         193,104.78
04     00100427Y5                276,045.42
04     00100620Y1                255,202.44
04     00100751IA                128,244.86
04     00101157IA                462,052.60
04     ~                       1,121,545.32
05     00100865GP                190,150.05
05     00101298GP                166,621.25
05     ~                         356,771.30
07     001000000107              167,489.78
07     001000000307              155,108.62
07     001000000407              431,436.82
07     001000000507              316,170.47
07     001000000907              239,352.41
07     001000001107              154,044.20
07     001000001307              267,387.29
07     001000001407              990,851.57
07     001000001607              263,150.63
07     ~                       2,984,991.79
	Grand Total	       4,656,413.19  &lt;---- &quot;GRAND TOTAL&quot;	

 ====================  (End of Report)]]></description>
		<content:encoded><![CDATA[<p>Select AcType, MainCode, Balance from Master where AcType between &#8217;01&#8242; and &#8217;07&#8242; and Balance&gt;100000</p>
<p>Union</p>
<p>Select AcType, &#8220;~&#8221;, SUM(Balance) from Master where AcType between &#8217;01&#8242; and &#8217;07&#8242; and Balance&gt;100000</p>
<p>Group by AcType<br />
Order by AcType</p>
<p>Result will be</p>
<p>                         Head Office<br />
           Wednesday, December 7, 2011</p>
<p>07/12/2011 3:51:32 PM User : RAJEEV  Station : GFL  Page : 1<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
AcType MainCode             Balance<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
01     00101086GP                193,104.78<br />
01     ~                                   193,104.78<br />
04     00100427Y5                276,045.42<br />
04     00100620Y1                255,202.44<br />
04     00100751IA                128,244.86<br />
04     00101157IA                462,052.60<br />
04     ~                                1,121,545.32<br />
05     00100865GP                190,150.05<br />
05     00101298GP                166,621.25<br />
05     ~                         356,771.30<br />
07     001000000107              167,489.78<br />
07     001000000307              155,108.62<br />
07     001000000407              431,436.82<br />
07     001000000507              316,170.47<br />
07     001000000907              239,352.41<br />
07     001000001107              154,044.20<br />
07     001000001307              267,387.29<br />
07     001000001407              990,851.57<br />
07     001000001607              263,150.63<br />
07     ~                       2,984,991.79<br />
 ====================  (End of Report)</p>
<p>&#8212;- &gt; Now I want to do as follows</p>
<p>                    Head Office<br />
       Wednesday, December 7, 2011</p>
<p>07/12/2011 3:51:32 PM User : RAJEEV  Station : GFL  Page : 1<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
AcType MainCode             Balance<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
01     00101086GP                193,104.78<br />
01     ~                         193,104.78<br />
04     00100427Y5                276,045.42<br />
04     00100620Y1                255,202.44<br />
04     00100751IA                128,244.86<br />
04     00101157IA                462,052.60<br />
04     ~                       1,121,545.32<br />
05     00100865GP                190,150.05<br />
05     00101298GP                166,621.25<br />
05     ~                         356,771.30<br />
07     001000000107              167,489.78<br />
07     001000000307              155,108.62<br />
07     001000000407              431,436.82<br />
07     001000000507              316,170.47<br />
07     001000000907              239,352.41<br />
07     001000001107              154,044.20<br />
07     001000001307              267,387.29<br />
07     001000001407              990,851.57<br />
07     001000001607              263,150.63<br />
07     ~                       2,984,991.79<br />
	Grand Total	       4,656,413.19  &lt;&#8212;- &quot;GRAND TOTAL&quot;	</p>
<p> ====================  (End of Report)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dilip</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-227311</link>
		<dc:creator><![CDATA[Dilip]]></dc:creator>
		<pubDate>Wed, 28 Dec 2011 09:57:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-227311</guid>
		<description><![CDATA[I&#039;m having 2 tables namely customer,product.The customer table consist 2 field namely custid and custname and product consist 3 fields namely prodid,prodname,date. i need to insert data from both table with single insert command and here when i select custname this particular id will be inserted into product id. Pls help.....]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m having 2 tables namely customer,product.The customer table consist 2 field namely custid and custname and product consist 3 fields namely prodid,prodname,date. i need to insert data from both table with single insert command and here when i select custname this particular id will be inserted into product id. Pls help&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-221977</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 20 Dec 2011 09:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-221977</guid>
		<description><![CDATA[Can you give more information on what you want to do?]]></description>
		<content:encoded><![CDATA[<p>Can you give more information on what you want to do?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sheheryar irfan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-221884</link>
		<dc:creator><![CDATA[sheheryar irfan]]></dc:creator>
		<pubDate>Tue, 20 Dec 2011 06:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-221884</guid>
		<description><![CDATA[how write table of 2 with cursor in MS SQL ?]]></description>
		<content:encoded><![CDATA[<p>how write table of 2 with cursor in MS SQL ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-218527</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 15 Dec 2011 14:38:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-218527</guid>
		<description><![CDATA[Where is the source data coming from? If it is a table, just use this

insert into target_table(cols)
select cols from source_table where ]]></description>
		<content:encoded><![CDATA[<p>Where is the source data coming from? If it is a table, just use this</p>
<p>insert into target_table(cols)<br />
select cols from source_table where</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samyuktha</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213597</link>
		<dc:creator><![CDATA[Samyuktha]]></dc:creator>
		<pubDate>Thu, 08 Dec 2011 19:20:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213597</guid>
		<description><![CDATA[I don&#039;t have any records to insert.I need to insert new rows.How do I enter millions of rows into a table at a time.
Please let me know the Script?
Can we use While loop or something like that.
Please help me out.

Samyuktha]]></description>
		<content:encoded><![CDATA[<p>I don&#8217;t have any records to insert.I need to insert new rows.How do I enter millions of rows into a table at a time.<br />
Please let me know the Script?<br />
Can we use While loop or something like that.<br />
Please help me out.</p>
<p>Samyuktha</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zahid khan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213451</link>
		<dc:creator><![CDATA[zahid khan]]></dc:creator>
		<pubDate>Thu, 08 Dec 2011 13:20:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213451</guid>
		<description><![CDATA[Sorry, I should work, I have check my error msg and it is a primary key violation. 
Dear Reader,
you can use either Pinal&#039;s process ro my process as you like.]]></description>
		<content:encoded><![CDATA[<p>Sorry, I should work, I have check my error msg and it is a primary key violation.<br />
Dear Reader,<br />
you can use either Pinal&#8217;s process ro my process as you like.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zahid khan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213443</link>
		<dc:creator><![CDATA[zahid khan]]></dc:creator>
		<pubDate>Thu, 08 Dec 2011 13:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213443</guid>
		<description><![CDATA[Hi Pinal,

I have tried to use you way of inserting multiple records.
INSERT INTO MyTable (FirstCol, SecondCol)
SELECT &#039;First&#039; ,1
UNION ALL
SELECT &#039;Second&#039; ,2
UNION ALL
SELECT &#039;Third&#039; ,3
UNION ALL
SELECT &#039;Fourth&#039; ,4
UNION ALL
SELECT &#039;Fifth&#039; ,5


Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint &#039;PK_tableName&#039;. Cannot insert duplicate key in object &#039;tableName&#039;.
The statement has been terminated.

I usually use excel formula to create insert into statement. It helps me to upload more than a millions of records in a minute. Those who do insertion in the database quite frequently, they can use my technique that use excel formula.

Zahid]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I have tried to use you way of inserting multiple records.<br />
INSERT INTO MyTable (FirstCol, SecondCol)<br />
SELECT &#8216;First&#8217; ,1<br />
UNION ALL<br />
SELECT &#8216;Second&#8217; ,2<br />
UNION ALL<br />
SELECT &#8216;Third&#8217; ,3<br />
UNION ALL<br />
SELECT &#8216;Fourth&#8217; ,4<br />
UNION ALL<br />
SELECT &#8216;Fifth&#8217; ,5</p>
<p>Msg 2627, Level 14, State 1, Line 1<br />
Violation of PRIMARY KEY constraint &#8216;PK_tableName&#8217;. Cannot insert duplicate key in object &#8216;tableName&#8217;.<br />
The statement has been terminated.</p>
<p>I usually use excel formula to create insert into statement. It helps me to upload more than a millions of records in a minute. Those who do insertion in the database quite frequently, they can use my technique that use excel formula.</p>
<p>Zahid</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeroenkuipertritac</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213368</link>
		<dc:creator><![CDATA[jeroenkuipertritac]]></dc:creator>
		<pubDate>Thu, 08 Dec 2011 10:44:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-213368</guid>
		<description><![CDATA[This is SQL2008 only]]></description>
		<content:encoded><![CDATA[<p>This is SQL2008 only</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samyuktha</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-212958</link>
		<dc:creator><![CDATA[Samyuktha]]></dc:creator>
		<pubDate>Wed, 07 Dec 2011 20:24:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-212958</guid>
		<description><![CDATA[Hi Pinal,

I got a task to do.I need to insert 400,000 rows into Adventure Works DB table inorder to see how Proactive caching works in different scenarios.
My question is how to insert 400,000 rows at a time in a table.
Can you let me know the script to generate it.

Please do help me out.

Thanks in Advance.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I got a task to do.I need to insert 400,000 rows into Adventure Works DB table inorder to see how Proactive caching works in different scenarios.<br />
My question is how to insert 400,000 rows at a time in a table.<br />
Can you let me know the script to generate it.</p>
<p>Please do help me out.</p>
<p>Thanks in Advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Gakenheimer</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-204323</link>
		<dc:creator><![CDATA[Joe Gakenheimer]]></dc:creator>
		<pubDate>Fri, 25 Nov 2011 12:33:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-204323</guid>
		<description><![CDATA[To the last poster, here&#039;s the MSDN link: http://msdn.microsoft.com/en-us/library/dd776382.aspx

INSERT INTO dbo.State(StateName)
VALUES (&#039;Alaska&#039;), (&#039;Arkansas&#039;), (&#039;Alabama&#039;);]]></description>
		<content:encoded><![CDATA[<p>To the last poster, here&#8217;s the MSDN link: <a href="http://msdn.microsoft.com/en-us/library/dd776382.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd776382.aspx</a></p>
<p>INSERT INTO dbo.State(StateName)<br />
VALUES (&#8216;Alaska&#8217;), (&#8216;Arkansas&#8217;), (&#8216;Alabama&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-203892</link>
		<dc:creator><![CDATA[Paul]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 21:34:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-203892</guid>
		<description><![CDATA[this is actually a MUCH faster method:

USE YourDB
GO
INSERT INTO MyTable  (FirstCol, SecondCol)
        VALUES (&#039;First&#039;,1),
                      (&#039;Second&#039;,2),
                      (&#039;Third&#039;,3),
                      (&#039;Fourth&#039;,4),
                      (&#039;Fifth&#039;,5);
GO]]></description>
		<content:encoded><![CDATA[<p>this is actually a MUCH faster method:</p>
<p>USE YourDB<br />
GO<br />
INSERT INTO MyTable  (FirstCol, SecondCol)<br />
        VALUES (&#8216;First&#8217;,1),<br />
                      (&#8216;Second&#8217;,2),<br />
                      (&#8216;Third&#8217;,3),<br />
                      (&#8216;Fourth&#8217;,4),<br />
                      (&#8216;Fifth&#8217;,5);<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jyotsna</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-203642</link>
		<dc:creator><![CDATA[Jyotsna]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 12:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-203642</guid>
		<description><![CDATA[ahhh... i got it!!!
it should be GO;
and not simply GO
:)]]></description>
		<content:encoded><![CDATA[<p>ahhh&#8230; i got it!!!<br />
it should be GO;<br />
and not simply GO<br />
:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jyotsna</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-203638</link>
		<dc:creator><![CDATA[Jyotsna]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 11:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-203638</guid>
		<description><![CDATA[INSERT INTO books(thec_code, room_number, status)
SELECT &#039;C01&#039;,&#039;R115&#039;,&#039;Confirmed&#039;
UNION ALL
SELECT &#039;C02&#039;,&#039;R210&#039;,&#039;Reserved&#039;
UNION ALL
SELECT &#039;C04&#039;,&#039;R375&#039;,&#039;Cancelled&#039;
UNION ALL
SELECT &#039;C04&#039;,&#039;R455&#039;,&#039;Reserved&#039;
GO

It&#039;s not working...
What&#039;s wrong??
:(]]></description>
		<content:encoded><![CDATA[<p>INSERT INTO books(thec_code, room_number, status)<br />
SELECT &#8216;C01&#8242;,&#8217;R115&#8242;,&#8217;Confirmed&#8217;<br />
UNION ALL<br />
SELECT &#8216;C02&#8242;,&#8217;R210&#8242;,&#8217;Reserved&#8217;<br />
UNION ALL<br />
SELECT &#8216;C04&#8242;,&#8217;R375&#8242;,&#8217;Cancelled&#8217;<br />
UNION ALL<br />
SELECT &#8216;C04&#8242;,&#8217;R455&#8242;,&#8217;Reserved&#8217;<br />
GO</p>
<p>It&#8217;s not working&#8230;<br />
What&#8217;s wrong??<br />
:(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samrat</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-195235</link>
		<dc:creator><![CDATA[Samrat]]></dc:creator>
		<pubDate>Mon, 14 Nov 2011 13:16:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-195235</guid>
		<description><![CDATA[remove the last union all]]></description>
		<content:encoded><![CDATA[<p>remove the last union all</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikhil</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-186076</link>
		<dc:creator><![CDATA[Nikhil]]></dc:creator>
		<pubDate>Mon, 31 Oct 2011 20:52:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-186076</guid>
		<description><![CDATA[thanks dude... nice work]]></description>
		<content:encoded><![CDATA[<p>thanks dude&#8230; nice work</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-182941</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Mon, 24 Oct 2011 15:50:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/#comment-182941</guid>
		<description><![CDATA[First result is created and last it is ordered. But there is no gurantee that the order by work correctly. You should always use order by clause when using select statement]]></description>
		<content:encoded><![CDATA[<p>First result is created and last it is ordered. But there is no gurantee that the order by work correctly. You should always use order by clause when using select statement</p>
]]></content:encoded>
	</item>
</channel>
</rss>

