<?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>TheUnical Technologies Blog &#187; SQL</title>
	<atom:link href="http://blog.theunical.com/category/databases/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.theunical.com</link>
	<description>TheUnical Technologies Official Blog</description>
	<lastBuildDate>Sun, 05 Feb 2012 21:46:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Pixy-Open-Source Vulnerability Scanner for PHP Applications</title>
		<link>http://blog.theunical.com/databases/db-tool/pixy-open-source-vulnerability-scanner-for-php-applications/</link>
		<comments>http://blog.theunical.com/databases/db-tool/pixy-open-source-vulnerability-scanner-for-php-applications/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 03:05:18 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[DB Tool]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.theunical.com/?p=254938</guid>
		<description><![CDATA[An Open-Source Vulnerability Scanner for PHP Applications. The Secure Systems Lab at the Technical University of Vienna has released the newest version of Pixy, an open-source vulnerability scanner. Here are some of the highlights: Detection of SQL injection and XSS vulnerabilities in PHP source code Automatic resolution of file inclusions Computation of dependence graphs that [...]]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:DontVertAlignCellWithSp /> <w:DontBreakConstrainedForcedTables /> <w:DontVertAlignInTxbx /> <w:Word11KerningPairs /> <w:CachedColBalance /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val=" " /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"   DefSemiHidden="true" DefQFormat="false" DefPriority="99"   LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="9" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> <w:LsdException Locked="false" Priority="39" Name="toc 9" /> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption" /> <w:LsdException Locked="false" Priority="10" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Title" /> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font" /> <w:LsdException Locked="false" Priority="11" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtitle" /> <w:LsdException Locked="false" Priority="22" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Strong" /> <w:LsdException Locked="false" Priority="20" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Emphasis" /> <w:LsdException Locked="false" Priority="59" SemiHidden="false"    UnhideWhenUsed="false" Name="Table Grid" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text" /> <w:LsdException Locked="false" Priority="1" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="No Spacing" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 1" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 1" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 1" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 1" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision" /> <w:LsdException Locked="false" Priority="34" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="List Paragraph" /> <w:LsdException Locked="false" Priority="29" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Quote" /> <w:LsdException Locked="false" Priority="30" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Quote" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 1" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 1" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 1" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 1" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 1" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 2" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 2" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 2" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 2" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 2" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 2" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 2" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 2" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 3" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 3" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 3" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 3" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 3" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 3" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 3" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 3" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 3" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 4" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 4" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 4" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 4" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 4" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 4" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 4" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 4" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 4" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 5" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 5" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 5" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 5" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 5" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 5" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 5" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 5" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 5" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Shading Accent 6" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false"    UnhideWhenUsed="false" Name="Light List Accent 6" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false"    UnhideWhenUsed="false" Name="Light Grid Accent 6" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 1 Accent 6" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium List 2 Accent 6" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false"    UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false"    UnhideWhenUsed="false" Name="Dark List Accent 6" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Shading Accent 6" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful List Accent 6" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false"    UnhideWhenUsed="false" Name="Colorful Grid Accent 6" /> <w:LsdException Locked="false" Priority="19" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis" /> <w:LsdException Locked="false" Priority="21" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis" /> <w:LsdException Locked="false" Priority="31" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference" /> <w:LsdException Locked="false" Priority="32" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Intense Reference" /> <w:LsdException Locked="false" Priority="33" SemiHidden="false"    UnhideWhenUsed="false" QFormat="true" Name="Book Title" /> <w:LsdException Locked="false" Priority="37" Name="Bibliography" /> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading" /> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]><br />
<mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:minor-fareast; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} --></p>
<p><!--[endif]-->An Open-Source Vulnerability Scanner for PHP Applications.</p>
<p>The Secure Systems Lab at the Technical University of Vienna has released the newest version of Pixy, an open-source vulnerability scanner. Here are some of the highlights:</p>
<p>Detection of SQL injection and XSS vulnerabilities in PHP source code</p>
<ol>
<li> Automatic resolution of file inclusions</li>
<li> Computation of dependence graphs that help you understand the causes of reported vulnerabilities</li>
<li> Static analysis engine (flow-sensitive, interprocedural, context-sensitive)</li>
<li> Platform-independent written in Java.</li>
</ol>
<p><a href="http://pixybox.seclab.tuwien.ac.at/">http://pixybox.seclab.tuwien.ac.at</a></p>
<input id="gwProxy" type="hidden" />
<p><!--Session data--></p>
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">Pixy-Open-Source Vulnerability Scanner for PHP Applications</div>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/db-tool/pixy-open-source-vulnerability-scanner-for-php-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List SQL injection tools for exploiting</title>
		<link>http://blog.theunical.com/databases/db-tool/list-sql-injection-tools-for-exploiting/</link>
		<comments>http://blog.theunical.com/databases/db-tool/list-sql-injection-tools-for-exploiting/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 01:39:11 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[DB Tool]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[MS-Sql]]></category>
		<category><![CDATA[SQL Injection]]></category>

		<guid isPermaLink="false">http://blog.theunical.com/?p=254932</guid>
		<description><![CDATA[List SQL injection tools for exploiting. sqlmap SQLInjector Bobcat Automagic HacmeBank Absinthe]]></description>
			<content:encoded><![CDATA[<p>List SQL injection tools for exploiting.</p>
<p><strong><a href="http://sqlmap.sourceforge.net/" target="_blank">sqlmap</a></strong></p>
<p><strong><a href="http://www.databasesecurity.com/dbsec/sqlinjector.zip" target="_blank">SQLInjector</a></strong></p>
<p><strong><a href="http://www.northern-monkee.co.uk/projects/bobcat/bin/BobCat_Alphav0.1.zip" target="_blank">Bobcat</a></strong></p>
<p><strong><a href="http://scoobygang.org/automagic.zip" target="_blank">Automagic</a></strong></p>
<p><strong><a href="http://owasp.net/forums/63/ShowPost.aspx" target="_blank">HacmeBank</a></strong></p>
<p><strong><a href="http://www.0x90.org/releases/absinthe/" target="_blank">Absinthe</a></strong></p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/db-tool/list-sql-injection-tools-for-exploiting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Many different SQL Injections variations</title>
		<link>http://blog.theunical.com/databases/ms-sql-server/many-different-sql-injections-variations/</link>
		<comments>http://blog.theunical.com/databases/ms-sql-server/many-different-sql-injections-variations/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 01:28:30 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[MS-Sql]]></category>

		<guid isPermaLink="false">http://blog.theunical.com/?p=254929</guid>
		<description><![CDATA[SQL Injections variations from my collection.. admin’– ‘ or 0=0 – ” or 0=0 – or 0=0 – ‘ or 0=0 # ” or 0=0 # or 0=0 # ‘ or ‘x’=&#8217;x ” or “x”=”x ‘) or (’x&#8217;=’x ‘ or 1=1– ” or 1=1– or 1=1– ‘ or a=a– ” or “a”=”a ‘) or (’a&#8217;=’a [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Injections variations from my collection..</p>
<p>admin’–</p>
<p>‘ or 0=0 –</p>
<p>” or 0=0 –</p>
<p>or 0=0 –</p>
<p>‘ or 0=0 #</p>
<p>” or 0=0 #</p>
<p>or 0=0 #</p>
<p>‘ or ‘x’=&#8217;x</p>
<p>” or “x”=”x</p>
<p>‘) or (’x&#8217;=’x</p>
<p>‘ or 1=1–</p>
<p>” or 1=1–</p>
<p>or 1=1–</p>
<p>‘ or a=a–</p>
<p>” or “a”=”a</p>
<p>‘) or (’a&#8217;=’a</p>
<p>“) or (”a”=”a</p>
<p>hi” or “a”=”a</p>
<p>hi” or 1=1 –</p>
<p>hi’ or 1=1 –</p>
<p>hi’ or ‘a’=&#8217;a</p>
<p>hi’) or (’a&#8217;=’a</p>
<p>hi”) or (”a”=”a</p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/ms-sql-server/many-different-sql-injections-variations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to retrieve stored procedure return values from TableAdapter</title>
		<link>http://blog.theunical.com/databases/ms-sql-server/how-to-retrieve-stored-procedure-return-values-from-tableadapter/</link>
		<comments>http://blog.theunical.com/databases/ms-sql-server/how-to-retrieve-stored-procedure-return-values-from-tableadapter/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 13:09:44 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Stored Procedures]]></category>
		<category><![CDATA[Technology News]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://blog.theunical.com/technology-news/how-to-retrieve-stored-procedure-return-values-from-tableadapter/</guid>
		<description><![CDATA[If you’ve been wondering why you are not able to access stored procedure return values from TableAdapter, here’s the solution for you. I will use tbTasks table and spInsertTask stored procedure to demonstrate the solution. You can see definitions for both below. CREATE TABLE dbo.tbTasks ( intID INT NOT NULL IDENTITY(1,1), strName VARCHAR(100) NOT NULL, [...]]]></description>
			<content:encoded><![CDATA[<p><span> </span></p>
<p>If you’ve been wondering why you are not able to access stored procedure return values from TableAdapter, here’s the solution for you.</p>
<p>I will use <span><span>tbTasks </span></span>table and <span><span>spInsertTask </span></span>stored procedure to demonstrate the solution.<span> </span>You can see definitions for both below.</p>
<p><span>CREATE</span><span> <span>TABLE</span> dbo<span>.</span>tbTasks</span></p>
<p><span>(</span></p>
<p><span><span> </span>intID <span>INT</span> <span>NOT</span> <span>NULL</span> <span>IDENTITY</span><span>(</span>1<span>,</span>1<span>),</span></span></p>
<p><span><span> </span>strName <span>VARCHAR</span><span>(</span>100<span>)</span> <span>NOT</span> <span>NULL,</span></span></p>
<p><span><span> </span>intPriority <span>INT</span> <span>NOT</span> <span>NULL,</span></span></p>
<p><span><span> </span>dtDueDate <span>DATETIME</span> <span>NOT</span> <span>NULL</span></span></p>
<p><span>)</span></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><span>CREATE</span><span> <span>PROCEDURE</span> dbo<span>.</span>spInsertTask</span></p>
<p><span><span> </span><span>(</span></span></p>
<p><span><span> </span>@strName <span>VARCHAR</span><span>(</span>200<span>),</span></span></p>
<p><span><span> </span>@intPriority <span>INT</span><span>,</span></span></p>
<p><span><span> </span>@dtDueDate <span>DATETIME</span></span></p>
<p><span><span> </span><span>)</span></span></p>
<p><span>AS</span></p>
<p><span> </span></p>
<p><span>INSERT</span><span> <span>INTO</span> tbTasks <span>(</span>strName<span>,</span> intPriority<span>,</span> dtDueDate<span>)</span></span></p>
<p><span>VALUES</span><span> <span>(</span>@strName<span>,</span> @intPriority<span>,</span> @dtDueDate<span>)</span></span></p>
<p><span> </span></p>
<p><span>RETURN</span><span> <span>SCOPE_IDENTITY</span><span>()</span></span></p>
<p><span>GO</span></p>
<p><span> </span></p>
<p>Notice that <span><span>tbTasks </span></span>has an identity column named <span><span>intID</span></span>.<span> </span>Also, stored procedure <span><span>spInsertTask </span></span>returns the new identity column value using <a href="http://msdn2.microsoft.com/en-us/library/ms190315(d=ide).aspx"><span><span>SCOPE_IDENTITY()</span></span></a>.<span> </span>Knowing this new identity value is extremely useful on the client side.</p>
<p>Create a new Typed Dataset called <em>TasksDataset</em> and add <span><span>tbTasks</span></span>.<span> </span>Also, add a new query to <em>tbTasksTableAdapter</em> using <span><span>spInsertTask</span></span> stored procedure.<span> </span>When adding a new query, choose ‘A single value’ option.</p>
<p><img src="http://blog.theunical.com/wp-content/plugins/wp-o-matic/cache/383dd_original.aspx" alt="" /></p>
<p><img src="http://blogs.msdn.com/photos/youngjoo/images/693131/original.aspx" alt="" /></p>
<p>At this point, you probably would expect that following code would assign the new identity value returned by <span><span>spInsertTask</span></span> stored procedure to <span><span>returnValue</span></span> variable.</p>
<p>[ VB ]</p>
<p><span>Dim</span><span> taTasks <span>As</span> <span>New</span> TasksDatasetTableAdapters.tbTasksTableAdapter</span></p>
<p><span>Dim</span><span> TaskName <span>As</span> <span>String</span></span></p>
<p><span>Dim</span><span> TaskPriority <span>As</span> <span>Integer</span></span></p>
<p><span>Dim</span><span> TaskDueDate <span>As</span> <span>Date</span></span></p>
<p><span>Dim</span><span> returnValue <span>As</span> <span>Integer</span></span></p>
<p><span> </span></p>
<p><span>TaskName = <span>&#8220;Test&#8221;</span></span></p>
<p><span>TaskPriority = 1</span></p>
<p><span>TaskDueDate = Now()</span></p>
<p><span> </span></p>
<p><span>returnValue = taTasks.InsertTask(TaskName, TaskPriority, TaskDueDate)</span></p>
<p><span> </span></p>
<p>[C#]</p>
<p><span>TasksDatasetTableAdapters.<span>tbTasksTableAdapter</span> taCustomers = <span>new</span> WindowsApplication1.TasksDatasetTableAdapters.<span>tbTasksTableAdapter</span>();</span></p>
<p><span>String</span><span> taskName;</span></p>
<p><span>int</span><span> taskPriority;</span></p>
<p><span>DateTime</span><span> taskDueDate;</span></p>
<p><span>int</span><span> returnValue;</span></p>
<p><span> </span></p>
<p><span>taskName = <span>&#8220;Test&#8221;</span>;</span></p>
<p><span>taskPriority = 1;</span></p>
<p><span>taskDueDate = System.<span>DateTime</span>.Now;</span></p>
<p><span> </span></p>
<p><span>returnValue = taCustomers.InsertTask(taskName, taskPriority, taskDueDate);</span></p>
<p>However, running above code results in <em>System.InvalidOperationException</em> during run-time for VB and “<em>Cannot implicitly convert type &#8216;int?&#8217; to &#8216;int&#8217;</em>.” compile error for C#.<span> </span>If you look at what actually gets returned by <span><span>tbTasksTableAdapter.InsertTask()</span></span> function, you will understand why above code does not work.<span> </span>You can find the function from the generated Typed Dataset code, <em>TasksDataset.Designer.vb</em> / <em>TasksDataset.Designer.cs</em> in this case.</p>
<p>[ VB ]</p>
<p><span>Public</span><span> <span>Overridable</span> <span>Overloads</span> <span>Function</span> InsertTask(&#8230;) <span>As</span> System.Nullable(<span>Of</span> <span>Integer</span>)</span></p>
<p><span><span> </span>&#8230;</span></p>
<p><span><span> </span>&#8230;</span></p>
<p><span><span> </span><span>Dim</span> returnValue <span>As</span> <span>Object</span></span></p>
<p><span><span> </span><span>Try</span></span></p>
<p><span><span> </span>returnValue = command.ExecuteScalar</span></p>
<p><span><span> </span><span>Finally</span></span></p>
<p><span><span> </span>&#8230;</span></p>
<p><span><span> </span><span>End</span> <span>Try</span></span></p>
<p><span><span> </span><span>If</span> ((returnValue <span>Is</span> <span>Nothing</span>) _</span></p>
<p><span><span> </span><span>OrElse</span> (returnValue.GetType <span>Is</span> <span>GetType</span>(System.DBNull))) <span>Then</span></span></p>
<p><span><span> </span><span>Return</span> <span>New</span> System.Nullable(<span>Of</span> <span>Integer</span>)</span></p>
<p><span><span> </span><span>Else</span></span></p>
<p><span><span> </span><span>Return</span> <span>New</span> System.Nullable(<span>Of</span> <span>Integer</span>)(<span>CType</span>(returnValue, <span>Integer</span>))</span></p>
<p><span><span> </span><span>End</span> <span>If</span></span></p>
<p><span>End</span><span> <span>Function</span></span></p>
<p><em><span>* C# version omitted since there’s no significant difference.</span></em></p>
<p><span>As you can see from above, what gets returned from InsertTask function is actually the return value of </span><span><span>System.Data.SqlClient.SqlCommand.ExecuteScalar()</span></span><span> which is <em>the first column of the first row in the result set, or a null reference if the result set is empty</em>, not the return value of the stored procedure.<span> </span>In this case, </span><span><span>InsertTask</span></span><span> returns null since the stored procedure does not return any result set.</span></p>
<p><span>If you choose ‘No value’ option, </span><span><span>System.Data.SqlClient.SqlCommand.ExecuteNonQuery()</span></span><span> is used instead.<span> </span>And the return value of </span><span><span>ExecuteNonQuery()</span></span><span> is <em>the number of rows affected</em>.<span> </span>Again, this is not the stored procedure return value.</span></p>
<p><span>So, how do you retrieve the stored procedure return value?<span> </span>Although it’s not immediately obvious, there’s an easy way to access it.<span> </span>Let’s look at the definition of the command object for the stored procedure.<span> </span>You can see it from </span><span><span>tbTasksTableAdapter.InitCommandCollection()</span></span><span> in </span><em>TasksDataset.Designer.vb</em> / <em>TasksDataset.Designer.cs</em> file.</p>
<p>[ VB]</p>
<p><span>Private</span><span> <span>Sub</span> InitCommandCollection()</span></p>
<p><span><span> </span><span>Me</span>._commandCollection = <span>New</span> System.Data.SqlClient.SqlCommand(1) {}</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(0) = <span>New</span> System.Data.SqlClient.SqlCommand</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(0).Connection = <span>Me</span>.Connection</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(0).CommandText = <span>&#8220;SELECT intID, strName, intPriority, dtDueDate FROM dbo.tbTasks&#8221;</span></span></p>
<p><span><span> </span><span>Me</span>._commandCollection(0).CommandType = System.Data.CommandType.Text</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1) = <span>New</span> System.Data.SqlClient.SqlCommand</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).Connection = <span>Me</span>.Connection</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).CommandText = <span>&#8220;dbo.spInsertTask&#8221;</span></span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).CommandType = System.Data.CommandType.StoredProcedure</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).Parameters.Add(<span>New</span> System.Data.SqlClient.SqlParameter(<span>&#8220;@RETURN_VALUE&#8221;</span>, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, 10, 0, <span>Nothing</span>, System.Data.DataRowVersion.Current, <span>false</span>, <span>Nothing</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>))</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).Parameters.Add(<span>New</span> System.Data.SqlClient.SqlParameter(<span>&#8220;@strName&#8221;</span>, System.Data.SqlDbType.VarChar, 200, System.Data.ParameterDirection.Input, 0, 0, <span>Nothing</span>, System.Data.DataRowVersion.Current, <span>false</span>, <span>Nothing</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>))</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).Parameters.Add(<span>New</span> System.Data.SqlClient.SqlParameter(<span>&#8220;@intPriority&#8221;</span>, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, 10, 0, <span>Nothing</span>, System.Data.DataRowVersion.Current, <span>false</span>, <span>Nothing</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>))</span></p>
<p><span><span> </span><span>Me</span>._commandCollection(1).Parameters.Add(<span>New</span> System.Data.SqlClient.SqlParameter(<span>&#8220;@dtDueDate&#8221;</span>, System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, 23, 3, <span>Nothing</span>, System.Data.DataRowVersion.Current, <span>false</span>, <span>Nothing</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>, <span>&#8220;&#8221;</span>))</span></p>
<p><span>End</span><span> <span>Sub</span></span></p>
<p><em><span>* C# version omitted since there’s no significant difference.</span></em></p>
<p><span>You can see from above that parameters collection does actually include </span><span><span>@RETURN_VALUE</span></span><span> parameter.<span> </span>It’s the first parameter in the collection.<span> </span>When the stored procedure is executed, return value from the stored procedure is added to this item in the collection.<span> </span>So, all we need to do is to retrieve this value after executing </span><span><span>InsertTask()</span></span><span> function.<span> </span>To do that, I will add some code to the partial class defined in <em>TasksDataset.vb / TasksDataset.cs</em>.</span></p>
<p><span>[ VB ]</span></p>
<p><span>Namespace</span><span> TasksDatasetTableAdapters</span></p>
<p><span><span> </span><span>Partial</span> <span>Public</span> <span>Class</span> tbTasksTableAdapter</span></p>
<p><span><span> </span><span>Public</span> <span>Function</span> GetReturnValue(<span>ByVal</span> commandIndex <span>As</span> <span>Integer</span>) <span>As</span> <span>Object</span></span></p>
<p><span><span> </span><span>Return</span> <span>Me</span>.CommandCollection(commandIndex).Parameters(0).Value</span></p>
<p><span><span> </span><span>End</span> <span>Function</span></span></p>
<p><span><span> </span><span>End</span> <span>Class</span></span></p>
<p><span>End</span><span> <span>Namespace</span></span></p>
<p><span> </span></p>
<p><span>[ C# ]</span></p>
<p><span>namespace</span><span> WindowsApplication1.TasksDatasetTableAdapters {</span></p>
<p><span><span> </span><span>public</span> <span>partial</span> <span>class</span> <span>tbTasksTableAdapter</span></span></p>
<p><span><span> </span>{</span></p>
<p><span><span> </span><span>public</span> <span>object</span> GetReturnValue(<span>int</span> commandIndex)</span></p>
<p><span><span> </span>{</span></p>
<p><span><span> </span><span>return</span> <span>this</span>.CommandCollection[commandIndex].Parameters[0].Value;</span></p>
<p><span><span> </span>}</span></p>
<p><span><span> </span>}</span></p>
<p><span>}</span></p>
<p><span> </span></p>
<p><span>Since Dataset Designer does not generate partial class structure for TableAdapters, you will have to add above code yourself to partial class file.<span> </span>The commandIndex parameter is the index of the command object in </span><span><span>_commandCollection</span></span><span> to retrieve return value from.<span> </span>You can get that information by looking at </span><span><span>tbTasksTableAdapter.InitCommandCollection(). </span></span><span>Now, let’s modify the code that was not running to use this new function.</span></p>
<p>[ VB ]</p>
<p><span>Dim</span><span> taTasks <span>As</span> <span>New</span> TasksDatasetTableAdapters.tbTasksTableAdapter</span></p>
<p><span>Dim</span><span> TaskName <span>As</span> <span>String</span></span></p>
<p><span>Dim</span><span> TaskPriority <span>As</span> <span>Integer</span></span></p>
<p><span>Dim</span><span> TaskDueDate <span>As</span> <span>Date</span></span></p>
<p><span>Dim</span><span> returnValue <span>As</span> <span>Integer</span></span></p>
<p><span> </span></p>
<p><span>TaskName = <span>&#8220;Test&#8221;</span></span></p>
<p><span>TaskPriority = 1</span></p>
<p><span>TaskDueDate = Now()</span></p>
<p><span> </span></p>
<p><span>taTasks.InsertTask(TaskName, TaskPriority, TaskDueDate)</span></p>
<p><span>returnValue = taTasks.GetReturnValue(1)</span></p>
<p><span> </span></p>
<p>[C#]</p>
<p><span>TasksDatasetTableAdapters.<span>tbTasksTableAdapter</span> taCustomers = <span>new</span> WindowsApplication1.TasksDatasetTableAdapters.<span>tbTasksTableAdapter</span>();</span></p>
<p><span>String</span><span> taskName;</span></p>
<p><span>int</span><span> taskPriority;</span></p>
<p><span>DateTime</span><span> taskDueDate;</span></p>
<p><span>int</span><span> returnValue;</span></p>
<p><span> </span></p>
<p><span>taskName = <span>&#8220;Test&#8221;</span>;</span></p>
<p><span>taskPriority = 1;</span></p>
<p><span>taskDueDate = System.<span>DateTime</span>.Now;</span></p>
<p><span> </span></p>
<p><span>taCustomers.InsertTask(taskName, taskPriority, taskDueDate);</span></p>
<p><span>returnValue = (int)taCustomers.GetReturnValue(1);</span></p>
<p>We pass in 1 as a parameter value to <span><span>GetReturnValue()</span></span> since our stored procedure is located at index 1 in <span><span>_commandCollection</span></span>.<span> </span>Above code will correctly retrieve return value from the stored procedure which is the new identity value of <span><span>intID</span></span> column.<span> </span>If you have more than one stored procedures that return something, you can retrieve those return values by calling <span><span>GetReturnValue()</span></span> with correct index.</p>
<p>Typed Dataset simplifies data access layer development significantly by generating necessary code for you based on the information you provide via Dataset Designer.<span> </span>Although generated code covers large number of scenarios, I suggest that you take a close look at generated code and find out how you can extend the functionality of default Typed Dataset.<span> </span>And definitely let us know how we can improve it to make Typed Dataset more powerful and flexible.</p>
<p>Also, don’t forget to let me know if you have better ways to retrieve return values from stored procedures.<span> </span>What I suggest here is just one solution and I am sure that you have other solutions that might be more elegant than this.</p>
<p><strong><em>Young Joo</em></strong></p>
<p><img src="http://blog.theunical.com/wp-content/plugins/wp-o-matic/cache/cf921_aggbug.aspx?PostID=693113" alt="" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/ms-sql-server/how-to-retrieve-stored-procedure-return-values-from-tableadapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sql Injection PHP MySql example</title>
		<link>http://blog.theunical.com/databases/mysql/sql-injection-php-mysql-example/</link>
		<comments>http://blog.theunical.com/databases/mysql/sql-injection-php-mysql-example/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 02:47:09 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[MySql 5.0]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Injection]]></category>

		<guid isPermaLink="false">http://blog.theunical.com/?p=87210</guid>
		<description><![CDATA[What is SQL Injection SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on [...]]]></description>
			<content:encoded><![CDATA[<h2>What is SQL Injection</h2>
<p>SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on your database.</p>
<h2>SQL Injection Example</h2>
<p>Below is a sample string that has been gathered from a normal user and a bad user trying to use SQL Injection. We asked the users for their login, which will be used to run a SELECT statement to get their information.</p>
<div>
<h2>MySQL &amp; PHP Code:</h2>
<pre>// a good user's name
$name = "timmy";
$query = "SELECT * FROM customers WHERE username = '$name'";
echo "Normal: " . $query . "&lt;br /&gt;";

// user input that uses SQL Injection
<span style="color: red;">$name_bad = "' OR 1'"</span>; 

// our MySQL query builder, however, not a very safe one
$query_bad = "SELECT * FROM customers WHERE username = '$name_bad'";

// display what the new query will look like, with injection
echo "Injection: " . $query_bad;</pre>
</div>
<h2>Display:</h2>
<div>Normal: SELECT * FROM customers WHERE username = &#8216;timmy&#8217;<br />
Injection: SELECT * FROM customers WHERE username = &#8221; OR 1&#8221;</div>
<p>The normal query is no problem, as our MySQL statement will just select everything from customers that has a username equal to <em>timmy</em>.</p>
<p><strong>However</strong>, the injection attack has actually made our query behave differently than we intended. By using a single quote (&#8216;) they have ended the string part of our MySQL query</p>
<ul>
<li>username = &#8216; &#8216;</li>
</ul>
<p>and then added on to our WHERE statement with an OR clause of 1 (always true).</p>
<ul>
<li>username = &#8216; &#8216; <strong>OR 1 </strong></li>
</ul>
<p>This OR clause of 1 will always be <em>true</em> and so <strong>every single entry</strong> in the &#8220;customers&#8221; table would be selected by this statement!</p>
<h2>More Serious SQL Injection Attacks</h2>
<p>Although the above example displayed a situation where an attacker could possibly get access to a lot of information they shouldn&#8217;t have, the attacks can be a lot worse. For example an attacker could empty out a table by executing a <em>DELETE</em> statement.</p>
<div>
<h2>MySQL &amp; PHP Code:</h2>
<pre><span style="color: red;">$name_evil = "'; DELETE FROM customers WHERE 1 or username = '"</span>; 

// our MySQL query builder really should check for injection
$query_evil = "SELECT * FROM customers WHERE username = '$name_evil'";

// the new evil injection query would include a DELETE statement
echo "Injection: " . $query_evil;</pre>
</div>
<h2>Display:</h2>
<div>SELECT * FROM customers WHERE username = &#8216; &#8216;; DELETE FROM customers WHERE 1 or username = &#8216; &#8216;</div>
<p>If you were run this query, then the injected DELETE statement would completely empty your &#8220;customers&#8221; table. Now that you know this is a problem, how can you prevent it?</p>
<p><strong>Injection Prevention -mysql_real_escape_string()</strong></p>
<p>Lucky for you, this problem has been known for a while and PHP has a specially-made function to prevent these attacks. All you need to do is use the mouthful of a function <em>mysql_real_escape_string</em>.</p>
<p>What <em>mysql_real_escape_string</em> does is take a string that is going to be used in a MySQL query and return the same string with all SQL Injection attempts safely escaped. Basically, it will replace those troublesome quotes(&#8216;) a user might enter with a MySQL-safe substitute, an escaped quote \&#8217;.</p>
<p>Lets try out this function on our two previous injection attacks and see how it works.</p>
<div>
<h2>MySQL &amp; PHP Code:</h2>
<pre>//NOTE: you must be connected to the database to use this function!
// connect to MySQL

$name_bad = "' OR 1'"; 

<span style="color: red;">$name_bad = mysql_real_escape_string($name_bad);</span>

$query_bad = "SELECT * FROM customers WHERE username = '$name_bad'";
echo "Escaped Bad Injection: &lt;br /&gt;" . $query_bad . "&lt;br /&gt;";

$name_evil = "'; DELETE FROM customers WHERE 1 or username = '"; 

<span style="color: red;">$name_evil = mysql_real_escape_string($name_evil);</span>

$query_evil = "SELECT * FROM customers WHERE username = '$name_evil'";
echo "Escaped Evil Injection: &lt;br /&gt;" . $query_evil;</pre>
</div>
<h2>Display:</h2>
<div>Escaped Bad Injection:<br />
SELECT * FROM customers WHERE username = &#8216;\&#8217; OR 1\&#8221;<br />
Escaped Evil Injection:<br />
SELECT * FROM customers WHERE username = &#8216;\&#8217;; DELETE FROM customers WHERE 1 or username = \&#8221;</div>
<p>Notice that those evil quotes have been escaped with a backslash \, preventing the injection attack.  Now all these queries will do is try to find a username that is just completely ridiculous:</p>
<ul>
<li>Bad: \&#8217; OR 1\&#8217;</li>
<li>Evil: \&#8217;; DELETE FROM customers WHERE 1 or username = \&#8217;</li>
</ul>
<p>And I don&#8217;t think we have to worry about those silly usernames getting access to our MySQL database. So please do use the handy <em>mysql_real_escape_string()</em> function to help prevent SQL Injection attacks on your websites.  You have no excuse not to use it after reading this lesson!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/mysql/sql-injection-php-mysql-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Is SQL Injection? Understanding This Important Threat Vector &#8230;</title>
		<link>http://blog.theunical.com/databases/mysql/what-is-sql-injection-understanding-this-important-threat-vector/</link>
		<comments>http://blog.theunical.com/databases/mysql/what-is-sql-injection-understanding-this-important-threat-vector/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 01:40:45 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[MySql 5.0]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Injection]]></category>

		<guid isPermaLink="false">http://blog.theunical.com/databases/mysql/what-is-sql-injection-understanding-this-important-threat-vector/</guid>
		<description><![CDATA[In August 2009 three people were charged with the theft of 130 million credit card numbers from Heartland Payment Systems, 7-Eleven and a supermarket chain called Hannaford Brothers. It was reportedly the biggest case of identity theft in U.S. history. This theft was carried out using SQL injection techniques. What is SQL injection and why [...]]]></description>
			<content:encoded><![CDATA[<p>In August 2009 three people were charged with the theft of 130 million credit card numbers from Heartland Payment Systems, 7-Eleven and a supermarket chain called Hannaford Brothers. It was reportedly the biggest case of identity theft in U.S. history. This theft was carried out using SQL injection techniques. What is SQL injection and why should you be bothered about it?</p>
<p>We all log into Web sites on a daily basis, be it for shopping, banking or accessing protected content. In most cases usernames are stored in a relational database along with other user details and related information.</p>
<p>The proliferation of databases created to support this growth in websites with protected content has lead to many insecure and vulnerable sites, hastily put on line with little thought to the underlying security requirements. This gaping hole in the security of Web sites is being aggressively exploited by SQL injection attacks.</p>
<p>Even more worrying this attack can be carried out against fully patched databases. It is not a problem with patches, more an issue with the way databases work. This attack can be made against search pages, feedback forms, customer comment forms and any other Web site pages that rely on a database engine. All databases can be vulnerable to this attack including MySQL, SQL Server and Oracle. Despite its name SQL injection is not only specific to Microsoft SQL Server.</p>
<p><strong>Anatomy of a typical SQL injection attack</strong></p>
<p>Probably the most vulnerable page for a SQL injection attack would be the one used to login to a site. The database table that stores a user’s details would normally have at least two columns—one for the username and one for the password. The table would probably be called users or something very similar.</p>
<p>The database will parse the username and password typed into the logon screen and convert it into a string of SQL to send to the database, so the database engine receives a line of SQL similar to this:</p>
<p>SELECT * FROM users WHERE username = ‘Chris Date’ AND password = ‘userspassword’</p>
<p>This is a pretty standard SQL statement and would look more or less the same whichever database you were using to store the user’s data. Hackers are interested in SQL injection attacks as they can manipulate the database by sending it some duff data. Instead of giving a valid username they could type something like this:</p>
<p>SELECT * FROM users WHERE username = ‘ ‘ ‘ AND password = ‘ ‘</p>
<p>The hacker has supplied a ‘ character as the username and a blank as the password. The database, being well behaved, would parse this query but return an error message informing the user that they have made a mistake in the line of code they have just typed in.</p>
<p>Using this chink in the database security armour the hacker will start to dig around a bit more. The error messages returned from the database will start to become increasingly more helpful, and begin to point out the structure of the underlying tables in the database. We can start to fool the database further by adding in other strings to the username.</p>
<p>For example if we type in ‘or email=’345 as our username it will be resolved by the query parser as:</p>
<p>SELECT * FROM users<br />
WHERE username = ‘ ‘or email=’345′ AND password = ‘ ‘</p>
<p>At this point the database may give an error if there is no such column in the users database as email. On the other hand it may not give an error message suggesting that there is a column called e-mail after all. All the hacker needs do is guess the e-mail address for a legitimate user. As most organisations have a standard e-mail address structure it is very easy to get an employee name and then use that as your user name in the SQL injection attack.</p>
<p>As you can see it is scarily easy to build up a picture of a database structure based on some simple fooling of the text entry screen and some intelligent guesses as to the likely structure of a database.</p>
<p><strong>How can SQL injection be avoided?</strong></p>
<p>It is possible to filter out single quotes, double quotes, slash, backslash, semi-colon and extended characters from user input strings, cookie values and parameters from a URL. In addition numeric values can be converted into integers before passing to the database.</p>
<p>Database administrators can take further measures in case they are still attacked. For example the simple measure of deleting all of the extended stored procedures that are not needed such as xp_sendmail and xp_cmdshell can immediately start to secure the database.</p>
<p>SQL injection is not a new attack and is avoidable if you take some basic security measures—whatever database you use.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/mysql/what-is-sql-injection-understanding-this-important-threat-vector/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQL Index Types</title>
		<link>http://blog.theunical.com/databases/ms-sql-server/sql-index-types/</link>
		<comments>http://blog.theunical.com/databases/ms-sql-server/sql-index-types/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 11:30:00 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[MS SQL Server 2000]]></category>
		<category><![CDATA[MS SQL Server 2005]]></category>
		<category><![CDATA[MS SQL Server 2008]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[MySql 5.0]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Sql Indexing]]></category>

		<guid isPermaLink="false">http://rachasatish.wordpress.com/2009/02/15/sql-index-types/</guid>
		<description><![CDATA[Index Types In addition to an index being clustered or nonclustered, it can be configured in other ways: Composite index: An index that contains more than one column. In both SQL Server 2005 and 2008, you can include up to 16 columns in an index, as long as the index doesn&#8217;t exceed the 900-byte limit. [...]]]></description>
			<content:encoded><![CDATA[<div class="Section1">
<h2>Index Types</h2>
<p class="MsoNormal">In addition to an index being clustered or nonclustered, it can be configured in other ways:</p>
<ul type="disc">
<li class="MsoNormal"><strong><span style='font-family:Calibri,sans-serif;'>Composite      index:</span></strong> An index that contains more than one column. In      both SQL Server 2005 and 2008, you can include up to 16 columns in an index,      as long as the index doesn&#8217;t exceed the 900-byte limit. Both clustered and      nonclustered indexes can be composite indexes.</li>
<li class="MsoNormal"><strong><span style='font-family:Calibri,sans-serif;'>Unique      Index:</span></strong> An index that ensures the uniqueness of each value      in the indexed column. If the index is a composite, the uniqueness is      enforced across the columns as a whole, not on the individual columns. For      example, if you were to create an index on the FirstName and LastName      columns in a table, the names together must be unique, but the individual      names can be duplicated.</li>
</ul>
<p class="MsoNormal">A unique index is automatically created when you define a primary key or unique constraint:</p>
<p class="MsoNormal" style='margin-left:1in;text-indent:-.25in;'><span style='font-size:10pt;font-family:Symbol;'><span>&middot;<span style='font:7pt "Times New Roman";'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span>&nbsp;</p>
<ul type="disc">
<ul type="square">
<li class="MsoNormal"><strong><span style='font-family:Calibri,sans-serif;'>Primary       key:</span></strong> When you define a primary key constraint on one or       more columns, SQL Server automatically creates a unique, clustered index       if a clustered index does not already exist on the table or view.       However, you can override the default behavior and define a unique,       nonclustered index on the primary key.</li>
<li class="MsoNormal"><strong><span style='font-family:Calibri,sans-serif;'>Unique:</span></strong>       When you define a unique constraint, SQL Server automatically creates a       unique, nonclustered index. You can specify that a unique clustered index       be created if a clustered index does not already exist on the table.</li>
</ul>
</ul>
<ul type="disc">
<li class="MsoNormal"><strong><span style='font-family:Calibri,sans-serif;'>Covering      index:</span></strong> A type of index that includes all the columns that      are needed to process a particular query. For example, your query might      retrieve the FirstName and LastName columns from a table, based on a value      in the ContactID column. You can create a covering index that includes all      three columns.</li>
</ul>
<h2>Index Design</h2>
<p class="start">As beneficial as indexes can be, they must be designed carefully. Because they can take up significant disk space, you don&#8217;t want to implement more indexes than necessary. In addition, indexes are automatically updated when the data rows themselves are updated, which can lead to additional overhead and can affect performance. As a result, index design should take into account a number of considerations.</p>
<h3>Database</h3>
<p class="MsoNormal">As mentioned above, indexes can enhance performance because they can provide a quick way for the query engine to find data. However, you must also take into account whether and how much you&#8217;re going to be inserting, updating, and deleting data. When you modify data, the indexes must also be modified to reflect the changed data, which can significantly affect performance. You should consider the following guidelines when planning your indexing strategy:</p>
<ul type="disc">
<li class="MsoNormal">For tables that are heavily updated, use as few      columns as possible in the index, and don&#8217;t over-index the tables.</li>
<li class="MsoNormal">If a table contains a lot of data but data      modifications are low, use as many indexes as necessary to improve query      performance. However, use indexes judiciously on small tables because the      query engine might take longer to navigate the index than to perform a      table scan.</li>
<li class="MsoNormal">For clustered indexes, try to keep the length of      the indexed columns as short as possible. Ideally, try to implement your      clustered indexes on unique columns that do not permit null values. This      is why the primary key is often used for the table&#8217;s clustered index,      although query considerations should also be taken into account when      determining which columns should participate in the clustered index.</li>
<li class="MsoNormal">The uniqueness of values in a column affects      index performance. In general, the more duplicate values you have in a      column, the more poorly the index performs. On the other hand, the more      unique each value, the better the performance. When possible, implement      unique indexes.</li>
<li class="MsoNormal">For composite indexes, take into consideration      the order of the columns in the index definition. Columns that will be      used in comparison expressions in the WHERE clause (such as WHERE      FirstName = &#8216;Charlie&#8217;) should be listed first. Subsequent columns should      be listed based on the uniqueness of their values, with the most unique      listed first.</li>
<li class="MsoNormal">You can also index computed columns if they meet      certain requirements. For example, the expression used to generate the      values must be deterministic (which means it always returns the same      result for a specified set of inputs). For more details about indexing      computed columns, see the topic &#8220;<a href="http://msdn.microsoft.com/en-us/library/ms189292.aspx">Creating      Indexes on Computed Columns</a>&#8221; in SQL Server Books Online.</li>
</ul>
<h3>Queries</h3>
<p class="MsoNormal">Another consideration when setting up indexes is how the database will be queried. As mentioned above, you must take into account the frequency of data modifications. In addition, you should consider the following guidelines:</p>
<ul type="disc">
<li class="MsoNormal">Try to insert or modify as many rows as possible      in a single statement, rather than using multiple queries.</li>
<li class="MsoNormal">Create nonclustered indexes on columns used      frequently in your statement&#8217;s predicates and join conditions.</li>
<li class="MsoNormal">Consider indexing columns used in exact-match      queries.</li>
</ul>
<p class="MsoNormal">&nbsp;</p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/ms-sql-server/sql-index-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL JOINS</title>
		<link>http://blog.theunical.com/databases/mysql/sql-joins/</link>
		<comments>http://blog.theunical.com/databases/mysql/sql-joins/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 06:34:00 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL JOINS]]></category>
		<category><![CDATA[MS-Sql]]></category>

		<guid isPermaLink="false">http://rachasatish.wordpress.com/2009/02/13/sql-joins/</guid>
		<description><![CDATA[&#160; The SQL JOIN clause is used whenever we have to select data from 2 or more tables. To be able to use SQL JOIN clause to extract data from 2 (or more) tables, we need a relationship between certain columns in these tables. We are going to illustrate our SQL JOIN example with the [...]]]></description>
			<content:encoded><![CDATA[<div class="Section1">
<p class="MsoNormal">&nbsp;</p>
<p>The <strong>SQL JOIN</strong> clause is used whenever we have to select data from 2 or more tables.</p>
<p>To be able to use <strong>SQL JOIN</strong> clause to extract data from 2 (or more) tables, we need a relationship between certain columns in these tables.</p>
<p>We are going to illustrate our <strong>SQL JOIN</strong> example with the following 2 tables:</p>
<p><strong>Customers:</strong></p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table3">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">CustomerID<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">FirstName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">LastName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Email<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">DOB<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Phone<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">1<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">John<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">John.Smith@yahoo.com<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">2/4/1968<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">626 222-2222<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">2<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Steven<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Goldfish<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">goldfish@fishhere.net<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">4/4/1974<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">323 455-4545<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">3<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Paula<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Brown<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">pb@herowndomain.org<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/24/1978<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">416 323-3232<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">4<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">James<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">jim@supergig.co.uk<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">20/10/1980<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">416 323-8888<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p><strong>Sales:</strong></p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table2">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">CustomerID<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Date<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">SaleAmount<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">2<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/6/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.22<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">1<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/7/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$99.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">3<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/7/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$122.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">3<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/13/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.00<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">4<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/22/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$555.55<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>As you can see those 2 tables have common field called CustomerID and thanks to that we can extract information from both tables by matching their CustomerID columns.</p>
<p>Consider the following SQL statement:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table4">
<tr>
<td style='padding:3pt;'>
<p class="MsoNormal">SELECT Customers.FirstName, Customers.LastName,   SUM(Sales.SaleAmount) AS SalesPerCustomer<br />   FROM Customers, Sales<br />   WHERE Customers.CustomerID = Sales.CustomerID<br />   GROUP BY Customers.FirstName, Customers.LastName<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>The SQL expression above will select all distinct customers (their first and last names) and the total respective amount of dollars they have spent.<br /> The <strong>SQL JOIN</strong> condition has been specified after the <a href="http://www.sql-tutorial.net/sql-where.asp" title="SQL WHERE">SQL WHERE</a> clause and says that the 2 tables have to be matched by their respective CustomerID columns.</p>
<p>Here is the result of this SQL statement:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table5">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">FirstName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">LastName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">SalesPerCustomers<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">John<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$99.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">Steven<span st</p>
<p>yle='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Goldfish<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.22<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">Paula<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Brown<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$222.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">James<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$555.55<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>The SQL statement above can be re-written using the <strong>SQL JOIN</strong> clause like this:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table6">
<tr>
<td style='padding:3pt;'>
<p class="MsoNormal">SELECT Customers.FirstName, Customers.LastName, SUM(Sales.SaleAmount)   AS SalesPerCustomer<br />   FROM Customers JOIN Sales<br />   ON Customers.CustomerID = Sales.CustomerID<br />   GROUP BY Customers.FirstName, Customers.LastName<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>There are 2 types of SQL JOINS &#8211; <strong>INNER JOINS</strong> and <strong>OUTER JOINS</strong>. If you don&#8217;t put INNER or OUTER keywords in front of the <strong>SQL JOIN</strong> keyword, then <strong>INNER JOIN</strong> is used. In short &#8220;INNER JOIN&#8221; = &#8220;JOIN&#8221; (note that different databases have different syntax for their JOIN clauses).</p>
<p>The <strong>INNER JOIN</strong> will select all rows from both tables as long as there is a match between the columns we are matching on. In case we have a customer in the Customers table, which still hasn&#8217;t made any orders (there are no entries for this customer in the Sales table), this customer will not be listed in the result of our SQL query above.</p>
<p>If the Sales table has the following rows:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table7">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">CustomerID<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Date<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">SaleAmount<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">2<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/6/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.22<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">1<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/6/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$99.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>And we use the same <strong>SQL JOIN</strong> statement from above:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table8">
<tr>
<td style='padding:3pt;'>
<p class="MsoNormal">SELECT Customers.FirstName, Customers.LastName, SUM(Sales.SaleAmount)   AS SalesPerCustomer<br />   FROM Customers JOIN Sales<br />   ON Customers.CustomerID = Sales.CustomerID<br />   GROUP BY Customers.FirstName, Customers.LastName<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>We&#8217;ll get the following result:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table9">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">FirstName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">LastName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">SalesPerCustomers<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">John<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$99.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">Steven<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Goldfish<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.22<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>Even though Paula and James are listed as customers in the Customers table they won&#8217;t be displayed because they haven&#8217;t purchased anything yet.</p>
<p>But what if you want to display all the customers and their sales, no matter if they have ordered something or not? We&#8217;ll do that with the help of <strong>SQL OUTER JOIN</strong> clause.</p>
<p>The second type of <strong>SQL JOIN</strong> is called <strong>SQL OUTER JOIN</strong> and it has 2 sub-types called <strong>LEFT OUTER JOIN</strong> and <strong>RIGHT OUTER JOIN</strong>.</p>
<p>The <strong>LEFT OUTER JOIN</strong> or simply <strong>LEFT JOIN</strong> (you can omit the OUTER keyword in most databases), selects all the rows from the first table listed after the FROM clause, no matter if they have matches in the second table.</p>
<p>If we slightly modify our last SQL statement to:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table10">
<tr>
<td style='padding:3pt;'>
<p class="MsoNormal">SELECT Customers.FirstName, Customers.LastName,   SUM(Sales.SaleAmount) AS SalesPerCustomer<br />   FROM Customers LEFT JOIN Sales<br />   ON Customers.CustomerID = Sales.CustomerID<br />   GROUP BY Customers.FirstName, Customers.LastName<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>and the Sales table still has the following rows:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table11">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">CustomerID<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Date<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">SaleAmount<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">2<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/6/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.22<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">1<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">5/6/2004<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$99.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>The result will be the following:</p>
<table class="MsoNormalTable" border="1" cellpadding="0" width="96%" style='width:96%;' id="Table12">
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">FirstName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">LastName<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">SalesPerCustomers<span style='font-size:12pt;'></s</p>
<p>pan></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">John<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$99.95<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">Steven<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Goldfish<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">$100.22<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">Paula<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Brown<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">NULL<span style='font-size:12pt;'></span></p>
</td>
</tr>
<tr>
<td style='padding:.75pt;'>
<p class="MsoNormal">James<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">Smith<span style='font-size:12pt;'></span></p>
</td>
<td style='padding:.75pt;'>
<p class="MsoNormal">NULL<span style='font-size:12pt;'></span></p>
</td>
</tr>
</table>
<p>As you can see we have selected everything from the Customers (first table). For all rows from Customers, which don&#8217;t have a match in the Sales (second table), the SalesPerCustomer column has amount NULL (NULL means a column contains nothing).</p>
<p>The <strong>RIGHT OUTER JOIN</strong> or just <strong>RIGHT JOIN</strong> behaves exactly as <strong>SQL LEFT JOIN</strong>, except that it returns all rows from the second table (the right table in our <strong>SQL JOIN</strong> statement).</p>
<p><strong>interesting?..</strong>http://www.devshed.com/c/a/MySQL/Understanding-SQL-Joins<span style='color:#1F497D;'>/</span></p>
<p><span style='font-size:11pt;font-family:Calibri,sans-serif;color:#1F497D;'>&nbsp;</span></p>
<p><span style='font-size:11pt;font-family:Calibri,sans-serif;color:#1F497D;'>&nbsp;</span></p>
<p class="MsoNormal">&nbsp;</p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/mysql/sql-joins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three easy ways to optimize your MySQL queries</title>
		<link>http://blog.theunical.com/databases/mysql/three-easy-ways-to-optimize-your-mysql-queries/</link>
		<comments>http://blog.theunical.com/databases/mysql/three-easy-ways-to-optimize-your-mysql-queries/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 05:32:00 +0000</pubDate>
		<dc:creator>Steven Wall</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[MySql 5.0]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[MySql5.1]]></category>
		<category><![CDATA[Sql Optimization]]></category>

		<guid isPermaLink="false">http://rachasatish.wordpress.com/2008/12/15/three-easy-ways-to-optimize-your-mysql-queries/</guid>
		<description><![CDATA[Any database programmer will tell you that in high-traffic database-driven applications, a single badly-designed SQL query can significantly impact the overall performance of your application. Not only does such a query consume more database time than it ideally should, but it can have an exponential effect on the performance of other application components. Optimizing query [...]]]></description>
			<content:encoded><![CDATA[<div class="Section1">
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"> </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">Any database programmer will tell you that in high-traffic database-driven applications, a single badly-designed <a href="http://search.techrepublic.com.com/index.php?c=1&amp;q=sql+optimization" target="_blank">SQL query</a> can significantly impact the overall performance of your application. Not only does such a query consume more database time than it ideally should, but it can have an exponential effect on the performance of other application components. </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">Optimizing query performance is as much a black art as a science, as heavily dependent on the developer&#8217;s intuition as on hard statistical performance data. Fortunately, databases likes <a href="http://search.techrepublic.com.com/index.php?c=1&amp;q=mysql&amp;t=11" target="_blank">MySQL</a> come with some tools to aid the process, and this article discusses three of them briefly: using indexes, analyzing queries with <i><span style="font-style:italic;">EXPLAIN</span></i>, and adjusting MySQL&#8217;s internal configuration. </span></span></p>
<h2><b><span style="font-family:Times New Roman;font-size:180%;"><span style="font-size:18px;">#1: Using indexes</span></span></b></h2>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">MySQL allows you to index database tables, making it possible to quickly seek to records without performing a full table scan first and thus significantly speeding up query execution. You can have up to 16 indexes per table, and MySQL also supports multi-column indexes and full-text search indexes. </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">Adding an index to a table is as simple as calling the <i><span style="font-style:italic;">CREATE INDEX</span></i> command and specifying the field(s) to index. <b><span style="font-weight:bold;">Listing A</span></b> shows you an example:</span></span></p>
<h3><b><span style="font-family:Times New Roman;font-size:130%;"><span style="font-size:13px;">Listing A</span></span></b></h3>
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"><br /><span class="code">mysql&gt; CREATE INDEX idx_username ON users(username);</span><br /><span class="code">Query OK, 1 row affected (0.15 sec)</span><br /><span class="code">Records: 1  Duplicates: 0  Warnings: 0</span> </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">Here, indexing the <i><span style="font-style:italic;">username</span></i> field of the <i><span style="font-style:italic;">users</span></i> table ensures that <i><span style="font-style:italic;">SELECT</span></i> queries which reference this field in their <i><span style="font-style:italic;">WHERE</span></i> or <i><span style="font-style:italic;">HAVING</span></i> clause will run a little faster than in the pre-indexed state. You can check that the index was created (<b><span style="font-weight:bold;">Listing B</span></b>) with the <i><span style="font-style:italic;">SHOW INDEX</span></i> command:</span></span></p>
<h3><b><span style="font-family:Times New Roman;font-size:130%;"><span style="font-size:13px;">Listing B</span></span></b></h3>
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"><br /><span class="code">mysql&gt; SHOW INDEX FROM users;</span><br /><span class="code">&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+</span><br /><span class="code">| Table | Non_unique | Key_name     | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |</span><br /><span class="code">&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+</span><br /><span class="code">| users |          1 | idx_username |            1 | username    | A         |      NULL |     NULL | NULL   | YES  | BTREE      |         |</span><br /><span class="code">&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+</span><br /><span class="code">1 row in set (0.00 sec)</span> </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">It&#8217;s important to note that indexes are a double-edged sword. Indexing every field of a table is usually unnecessary, and is quite likely to slow things down significantly when inserting or updating data because of the additional work MySQL has to do to rebuild the index each time. On the other hand, avoiding indexes altogether isn&#8217;t such a great idea either, because while this will speed up <i><span style="font-style:italic;">INSERTs</span></i>, it will cause <i><span style="font-style:italic;">SELECT</span></i> operations to slow down. There is thus always a trade-off to be made, and it&#8217;s wise to consider what the primary function of the table will be (data retrieval or data edit) when designing the indexing system.</span></span></p>
<h2><b><span style="font-family:Times New Roman;font-size:180%;"><span style="font-size:18px;">#2: Optimizing query performance</span></span></b></h2>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">When analyzing query performance, it&#8217;s also useful to consider the <i><span style="font-style:italic;">EXPLAIN</span></i> keyword. This keyword, when placed in front of a <i><span style="font-style:italic;">SELECT</span></i> query, describes how MySQL intends to execute the query and the number of rows it will need to process to successfully deliver a result set. To illustrate, consider the following simple example (<b><span style="font-weight:bold;">Listing C</span></b>):</span></span></p>
<h3><b><span style="font-family:Times New Roman;font-size:130%;"><span style="font-size:13px;">Listing C</span></span></b></h3>
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"><br /><span class="code">mysql&gt; EXPLAIN SELECT city.name, city.district FROM city, country WHERE city.countrycode = country.code AND country.code = &#8216;IND&#8217;;</span><br /><span class="code">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</span><br /><span class="code">| id | select_type | table   | type  | possible_keys | key     | key_len | ref  | rows | Extra       |</span><br /><span class="code">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</span><br /><span class="code">|  1 | SIMPLE      | country | const | PRIMARY       | PRIMARY | 3       | const |    1 | Using index |</span><br /><span class="code">|  1 | SIMPLE      | city    | ALL   | NULL          | NULL    | NULL    | NULL | 4079 | Using where |</span><br /><span class="code">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</span><br /><span class="code">2 rows in set (0.00 sec)</span> </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">Here, the query is structured as a join between two tables and the <i><span style="font-style:italic;">EXPLAIN</span></i> keyword describes how MySQL will process the join. It should be clear the current design will require MySQL to process only one record in the <i><span style="font-style:italic;">country</span></i> table (which is indexed) but all 4079 records in the <i><span style="font-style:italic;">city</span></i> table (which isn&#8217;t). This then suggests scope for improvement using other optimization tricks &#8211; for example, adding an index to the <i><span style="font-style:italic;">city</span></i> table as follows (<b><span style="font-weigh</p>
<p>t:bold;">Listing D</span></b>):</span></span></p>
<h3><b><span style="font-family:Times New Roman;font-size:130%;"><span style="font-size:13px;">Listing D</span></span></b></h3>
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"><br /><span class="code">mysql&gt; <b><span style="font-weight:bold;">CREATE INDEX idx_ccode ON city(countrycode);</span></b></span><b><span style="font-weight:bold;"><br /></span></b><span class="code">Query OK, 4079 rows affected (0.15 sec)</span><br /><span class="code">Records: 4079  Duplicates: 0  Warnings: 0</span> </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">And now, when you re-run the query with <i><span style="font-style:italic;">EXPLAIN</span></i>, you&#8217;ll see a noticeable improvement (<b><span style="font-weight:bold;">Listing E</span></b>):</span></span></p>
<h3><b><span style="font-family:Times New Roman;font-size:130%;"><span style="font-size:13px;">Listing E</span></span></b></h3>
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"><br /><span class="code">mysql&gt; EXPLAIN SELECT city.name, city.district FROM city, country WHERE city.countrycode = country.code AND country.code = &#8216;IND&#8217;;</span><br /><span class="code">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</span><br /><span class="code">| id | select_type | table   | type  | possible_keys | key       | key_len | ref   | rows | Extra       |</span><br /><span class="code">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</span><br /><span class="code">|  1 | SIMPLE      | country | const | PRIMARY       | PRIMARY   | 3       | const |    1 | Using index |</span><br /><span class="code">|  1 | SIMPLE      | city    | ref   | idx_ccode     | idx_ccode | 3       | const |  333 | Using where |</span><br /><span class="code">+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</span><br /><span class="code">2 rows in set (0.01 sec)</span> </span></span></p>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">As this illustrates, MySQL now only needs to scan 333 records in the <i><span style="font-style:italic;">city</span></i> table to produce a result set &#8212; a reduction of almost 90 percent! Naturally, this translates into faster query execution time and more efficient usage of database resources.</span></span></p>
<h2><b><span style="font-family:Times New Roman;font-size:180%;"><span style="font-size:18px;">#3: Adjusting internal variables</span></span></b></h2>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">MySQL is so open that it&#8217;s fairly easy to further fine-tune its default settings to obtain greater performance and stability. Some of the key variables that should be optimized are listed below.</span></span></p>
<ul type="disc">
<li class="MsoNormal"><b><span style="font-family:Calibri;font-size:85%;"><span style="font-weight:bold;font-size:11px;">Altering Index Buffer Size      (key_buffer)<br />     </span></span></b>This variable controls the size of the buffer used when      handling table indices (both read and write operations). The MySQL manual      recommends that this variable be increased &#8220;to as much as you can      afford&#8221; to ensure you get the best performance on indexed tables, and      recommends a value equivalent to about 25 percent of the total system memory.      This is one of the more important MySQL configuration variables and if      you&#8217;re interested in optimizing and improving performance, trying      different values for the <i><span style="font-style:italic;">key_buffer_size</span></i>      variable is a good place to start.</li>
<li class="MsoNormal"><b><span style="font-family:Calibri;font-size:85%;"><span style="font-weight:bold;font-size:11px;">Altering Table Buffer Size      (read_buffer_size)<br />     </span></span></b>When a query requires a table to be scanned      sequentially, MySQL allocates a memory buffer to this query. The <i><span style="font-style:italic;">read_buffer_size</span></i> variable controls      the size of this buffer. If you find that sequential scans are proceeding      slowly, you can improve performance by increasing this value, and hence      the size of the memory buffer.</li>
<li class="MsoNormal"><b><span style="font-family:Calibri;font-size:85%;"><span style="font-weight:bold;font-size:11px;">Setting The Number Of Maximum      Open Tables (table_cache)<br />     </span></span></b>This variable controls the maximum number of tables      MySQL can have open at any one time, and thus controls the server&#8217;s      ability to respond to incoming requests. This variable is closely related      to the <i><span style="font-style:italic;">max_connections</span></i>      variables &#8212; increasing this value allows MySQL to keep a larger number of      tables open, just as increasing <i><span style="font-style:italic;">max_connections</span></i>      increases the number of allowed connections. Consider altering this value      if you have a high-volume server which receives queries on multiple      different databases and tables.</li>
<li class="MsoNormal"><b><span style="font-family:Calibri;font-size:85%;"><span style="font-weight:bold;font-size:11px;">Deciding A Time Limit For Long      Queries (long_query_time)<br />     </span></span></b>MySQL comes with a so-called &#8220;slow query log&#8221;,      which automatically logs all queries that do not end within a particular      time limit. This log is useful to track inefficient or misbehaving      queries, and to find targets for optimization algorithms. The <i><span style="font-style:italic;">long_query_time</span></i> variable controls this      maximum time limit, in seconds.</li>
</ul>
<p><span style="font-family:Times New Roman;font-size:100%;"><span style="font-size:12px;">The previous discussion should give you some insight into three tools you can use to analyze and optimize your SQL queries, and help you squeeze better performance out of your application. Go on and try them out &#8212; and happy optimizing!</span></span></p>
<p class="MsoNormal"><span style="font-family:Calibri;font-size:85%;"><span style="font-size:11px;"> </span></span></p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.theunical.com/databases/mysql/three-easy-ways-to-optimize-your-mysql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

