<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iDevForFun &#187; Sql</title>
	<atom:link href="http://www.idevforfun.com/index.php/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.idevforfun.com</link>
	<description>.NET Development</description>
	<lastBuildDate>Fri, 13 Jan 2012 20:04:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Insert Multiple Rows With a Single Insert</title>
		<link>http://www.idevforfun.com/index.php/2011/06/08/insert-multiple-rows-with-a-single-insert/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=insert-multiple-rows-with-a-single-insert</link>
		<comments>http://www.idevforfun.com/index.php/2011/06/08/insert-multiple-rows-with-a-single-insert/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 16:24:07 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.idevforfun.com/?p=166</guid>
		<description><![CDATA[TweetI often have to insert multiple rows of (usually) test data into tables. The simplest but most tedious way is to rewrite the INSERT statement over and over with different values &#8230; INSERT INTO User VALUES &#40;'Penny', 'Penny'&#41; INSERT INTO User VALUES &#40;'Sheldon', 'Cooper'&#41; INSERT INTO User VALUES &#40;'Leonard', 'Hofstadter'&#41; INSERT INTO User VALUES &#40;'Howard', ]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton166" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.idevforfun.com%2Findex.php%2F2011%2F06%2F08%2Finsert-multiple-rows-with-a-single-insert%2F&amp;via=Lawnmower_Man&amp;text=Insert%20Multiple%20Rows%20With%20a%20Single%20Insert&amp;related=&amp;lang=en&amp;count=vertical&amp;counturl=http%3A%2F%2Fwww.idevforfun.com%2Findex.php%2F2011%2F06%2F08%2Finsert-multiple-rows-with-a-single-insert%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.idevforfun.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>I often have to insert multiple rows of (usually) test data into tables. The simplest but most tedious way is to rewrite the INSERT statement over and over with different values &#8230;<br />
<br/></p>

<div class="wp_codebox"><table><tr id="p1664"><td class="code" id="p166code4"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Penny'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Penny'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Sheldon'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Cooper'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Leonard'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Hofstadter'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Howard'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Walowitz'</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Rajesh'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Koothrappali'</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><br/></p>
<p>Its not a big deal but as a developer I hate writing the same statement over and over &#8230; it just goes against my grain. Its also more of an overhead to repeatedly call insert for each row. Here&#8217;s a better way &#8230;<br />
<br/></p>

<div class="wp_codebox"><table><tr id="p1665"><td class="code" id="p166code5"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Penny'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Penny'</span> <span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Sheldon'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Cooper'</span> <span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Leonard'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Hofstadter'</span> <span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Howard'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Walowitz'</span> <span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span> 
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Rajesh'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Koothrappali'</span></pre></td></tr></table></div>

<p><br/><br />
This inserts the same data as the first example but uses only one insert so has less overhead. If you happen to be running SQL Server 2008 there&#8217;s a new syntax to achieve the same although the above example will still work. In SQL Server 2008 you can use this syntax &#8230;<br />
<br/></p>

<div class="wp_codebox"><table><tr id="p1666"><td class="code" id="p166code6"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> User
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Penny'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Penny'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Sheldon'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Cooper'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Leonard'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Hofstadter'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Howard'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Walowitz'</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Rajesh'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Koothrappali'</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.idevforfun.com/index.php/2011/06/08/insert-multiple-rows-with-a-single-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Search</title>
		<link>http://www.idevforfun.com/index.php/2010/03/30/sql-search/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-search</link>
		<comments>http://www.idevforfun.com/index.php/2010/03/30/sql-search/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 17:55:07 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.idevforfun.com/?p=91</guid>
		<description><![CDATA[TweetEver wanted to be able to search your sql databases for procedure names, table names etc as you would with a file search? Well now you can with this handy little tool from Redgate. Its a free download and has to be one of the handiest Sql tools I have come across especially when working ]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton91" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.idevforfun.com%2Findex.php%2F2010%2F03%2F30%2Fsql-search%2F&amp;via=Lawnmower_Man&amp;text=SQL%20Search&amp;related=&amp;lang=en&amp;count=vertical&amp;counturl=http%3A%2F%2Fwww.idevforfun.com%2Findex.php%2F2010%2F03%2F30%2Fsql-search%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.idevforfun.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Ever wanted to be able to search your sql databases for procedure names, table names etc as you would with a file search? Well now you can with this handy little tool from Redgate. Its a free download and has to be one of the handiest Sql tools I have come across especially when working with multiple large databases. </p>
<p><a href="http://www.red-gate.com/products/SQL_Search/index.htm?utm_source=sqlsearchui&#038;utm_medium=textad&#038;utm_content=recommend_sql_search&#038;utm_campaign=sqlsearch" target="_blank">Download SQL search</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idevforfun.com/index.php/2010/03/30/sql-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

