<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>sql-server-2000 &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/sql-server-2000/</link>
	<description>Feed of posts on WordPress.com tagged "sql-server-2000"</description>
	<pubDate>Mon, 30 Nov 2009 12:48:34 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[... may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.]]></title>
<link>http://scmay.wordpress.com/2009/11/26/may-cause-cycles-or-multiple-cascade-paths-specify-on-delete-no-action-or-on-update-no-action-or-modify-other-foreign-key-constraints/</link>
<pubDate>Thu, 26 Nov 2009 00:20:13 +0000</pubDate>
<dc:creator>scmay</dc:creator>
<guid>http://scmay.wordpress.com/2009/11/26/may-cause-cycles-or-multiple-cascade-paths-specify-on-delete-no-action-or-on-update-no-action-or-modify-other-foreign-key-constraints/</guid>
<description><![CDATA[Chances are, you are here because you have googled for the above mentioned error from SQL Server. In]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Chances are, you are here because you have googled for the above mentioned error from SQL Server.</p>
<p>In case you did not understand what it means, I&#8217;ve found a simple yet effective explanation in this <a href="http://lists.evolt.org/archive/Week-of-Mon-20030421/139403.html">link</a></p>
<p>I quote</p>
<blockquote><p>CREATE TABLE foo (<br />
    fooid int IDENTITY,<br />
    foovalue varchar(47)<br />
    )</p>
<p>CREATE TABLE bar (<br />
    barid int IDENTITY,<br />
    barvalue varchar(47),<br />
    fooid int<br />
    CONSTRAINT fk_bar_foo FOREIGN KEY(fooid)<br />
        REFERENCES foo(fooid)<br />
            ON UPDATE<br />
                CASCADE<br />
            ON DELETE<br />
                CASCADE<br />
    )</p>
<p>CREATE TABLE baz (<br />
    bazid int IDENTITY,<br />
    bazvalue varchar(47),<br />
    barid int<br />
    CONSTRAINT fk_baz_bar FOREIGN KEY(barid)<br />
        REFERENCES bar(barid)<br />
            ON UPDATE<br />
                CASCADE<br />
            ON DELETE<br />
                CASCADE<br />
    )
</p></blockquote>
<blockquote><p>SQL Server will say, hey, if we delete a row from foo, well, we could delete<br />
multiple rows from bar, and then we&#8217;ll have to delete multiple rows from<br />
baz, and that could go on forever! So let&#8217;s issue a warning about &#8220;cycles or<br />
multiple cascade paths&#8221; and disallow it.</p></blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Sql Server , donde esta el log de errores]]></title>
<link>http://margotu.wordpress.com/2009/11/18/sql-server-donde-esta-el-log-de-errores/</link>
<pubDate>Wed, 18 Nov 2009 10:37:52 +0000</pubDate>
<dc:creator>Javier Aparicio</dc:creator>
<guid>http://margotu.wordpress.com/2009/11/18/sql-server-donde-esta-el-log-de-errores/</guid>
<description><![CDATA[Siempre es curioso encontrarse con funcionalidades no documentadas en SQL Server. Aunque uno no pued]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Siempre es curioso encontrarse con funcionalidades no documentadas en SQL Server. Aunque uno no pueda fiarse mucho de ellas (al no estar documentadas, el equipo de desarrollo podría cambiarlas o directamente eliminarlas sin tener que rendir cuentas a nadie), en alguna ocasión te puede sacar de un apuro.</p>
<p><!--more--></p>
<p>El caso es que hoy me he encontrado con una forma fácil de conocer la ruta del log de errores de nuestra instancia. Sí, igual alguno puede conocer la forma por la cual podemos obtener algo similar leyendo del registro, mediante el procedimiento almacenado extendido xp_instance_regread (el cual tampoco está documentado) y filtrando por la clave correcta. Algo como:</p>
<p>DECLARE @DirLog nvarchar(512)</p>
<p>EXEC master.dbo.xp_instance_regread N&#8217;HKEY_LOCAL_MACHINE&#8217; , N&#8217;SOFTWARE\Microsoft\MSSQLServer\CPE&#8217; , N&#8217;ErrorDumpDir&#8217; , @DirLog OUTPUT</p>
<p>PRINT @DirLog</p>
<p>Teniendo en cuenta que lo anterior nos muestra la ruta de la carpeta LOG de nuestra instancia, no habría mayor problema en usar este método si conocemos la clave del registro donde buscar. Lo cual en algunas ocasiones puede ser bastante complicado.</p>
<p>Sin embargo, con este nuevo método que he encontrado, simplemente ejecutando</p>
<p>SELECT SERVERPROPERTY(&#8216;ErrorLogFileName&#8217;)</p>
<p>Tenemos no sólo la ruta completa, sino también el nombre del archivo de log de nuestra instancia.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Replace multiple space with single space.]]></title>
<link>http://sqlreference.wordpress.com/2009/11/16/replace-multiple-space-with-single-space/</link>
<pubDate>Mon, 16 Nov 2009 09:16:10 +0000</pubDate>
<dc:creator>suniljk</dc:creator>
<guid>http://sqlreference.wordpress.com/2009/11/16/replace-multiple-space-with-single-space/</guid>
<description><![CDATA[CREATE TABLE #temp1 (longtextwithspace VARCHAR(8000)) INSERT #temp1 SELECT &#8216;THIS IS TO SHOW HO]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>CREATE TABLE #temp1 (longtextwithspace VARCHAR(8000))<br />
INSERT #temp1<br />
SELECT &#8216;THIS IS TO     SHOW    HOW TO      REPLACE MULTIPLE      SPACE WITH    A   SINGLE    SPACE       WHICH MAKES           IT A MEANING   FULL    STATEMENT,  USING A    SINGLE QUERY &#8216;<br />
SELECT * FROM #temp1<br />
SELECT REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(longtextwithspace)),&#8217;  &#8216;,&#8217; &#8216;+char(3)),char(3)+&#8217; &#8216;,&#8221;),char(3),&#8221;) from #temp1</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Partitioned view]]></title>
<link>http://sqlreference.wordpress.com/2009/11/16/partitioned-view/</link>
<pubDate>Mon, 16 Nov 2009 07:47:03 +0000</pubDate>
<dc:creator>suniljk</dc:creator>
<guid>http://sqlreference.wordpress.com/2009/11/16/partitioned-view/</guid>
<description><![CDATA[This is the only way we can handle the very large tables in sql 2000. The basic is splitting the hug]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is the only way we can handle the very large tables in sql 2000. The basic is splitting the huge table into different small idential tables based on date of any column value.<br />
We have to put the check condition while creating the table itself.</p>
<p>CREATE TABLE [dbo].[sample_tab1](<br />
	[MsgId] [int] NOT NULL ,<br />
	[PtId] [tinyint] NOT NULL CHECK ([PtId] = 1),<br />
	[TimeCreated] [datetime] NOT NULL ,<br />
	CONSTRAINT [PK_sample_tab] PRIMARY KEY  CLUSTERED<br />
	(<br />
		[MsgId],<br />
		[PtId]<br />
	)  ON [Primary] ,</p>
<p>) ON [Primary]<br />
GO</p>
<p>CREATE TABLE [dbo].[sample_tab2](<br />
	[MsgId] [int] NOT NULL ,<br />
	[PtId] [tinyint] NOT NULL CHECK ([PtId] = 2),<br />
	[TimeCreated] [datetime] NOT NULL ,<br />
	CONSTRAINT [PK_sample_tab] PRIMARY KEY  CLUSTERED<br />
	(<br />
		[MsgId],<br />
		[PtId]<br />
	)  ON [Primary] ,</p>
<p>) ON [Primary]<br />
GO</p>
<p>Remember its always put the constraint while you create the table itself (aviod using alter table to add constraint).</p>
<p>Now Create a View with Union all.</p>
<p>create view VW_sample_tab<br />
as<br />
 select * from sample_tab1<br />
 union all<br />
 select * from sample_tab2<br />
GO</p>
<p>Now do the query with partition key as condition. it will be always index seek.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to find last stats update date]]></title>
<link>http://sqlreference.wordpress.com/2009/11/15/how-to-find-last-stats-update-date/</link>
<pubDate>Sun, 15 Nov 2009 08:08:15 +0000</pubDate>
<dc:creator>suniljk</dc:creator>
<guid>http://sqlreference.wordpress.com/2009/11/15/how-to-find-last-stats-update-date/</guid>
<description><![CDATA[SELECT O.NAME AS TableName, i.name as IndexName, STATS_DATE(i.id,i.indid)as StatsDate FROM sysindexe]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>SELECT O.NAME AS TableName, i.name as IndexName, STATS_DATE(i.id,i.indid)as StatsDate FROM sysindexes i<br />
INNER JOIN sysobjects O<br />
ON i.id=O.id<br />
AND i.rows&#62;0 AND O.XTYPE=&#8217;U&#8217; AND O.NAME =&#8217;table name&#8217;<br />
ORDER BY O.NAME</p>
<p>This will give when was the last statistics updated on the table for all the indexes.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Como fazer conexão JDBC no SQL Server 2000 no Linux com o SQuirreL SQL Client]]></title>
<link>http://ricardospinoza.wordpress.com/2009/10/26/como-fazer-conexao-jdbc-no-sql-server-2000-no-linux-com-o-squirrel-sql-client/</link>
<pubDate>Mon, 26 Oct 2009 10:22:47 +0000</pubDate>
<dc:creator>ricardospinoza</dc:creator>
<guid>http://ricardospinoza.wordpress.com/2009/10/26/como-fazer-conexao-jdbc-no-sql-server-2000-no-linux-com-o-squirrel-sql-client/</guid>
<description><![CDATA[Tutorial passo a passo de como fazer conexão JDBC no SQL Server 2000 no Linux com o SQuirreL SQL Cli]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Tutorial passo a passo de como fazer conexão JDBC no SQL Server 2000 no Linux com o SQuirreL SQL Client.</p>
<h1><span style="text-decoration:underline;">Instalação Java 2</span></h1>
<p><span style="text-decoration:underline;"> </span></p>
<p>Primeiramente você precisa ser instalado Java 2 JRE, caso não tenha, siga o tutorial: <a href="http://www.jsk.com.br/java-linux.htmlT" target="_blank">http://www.jsk.com.br/java-linux.htmlT</a> se estiver usando Debian ou alguma distribuição baseada no Debian como o Ubuntu, logue como superusuário e digite <strong>apt-get install sun-java5-jre</strong></p>
<p>Baixe os drives do JDBC para o SQL Server 2000 no endereço:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&#38;displaylang=en" target="_blank">http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&#38;displaylang=en</a></p>
<p>ou diretamente em</p>
<p><a href="http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/jorm/jorm/externals/jdbc/msbase.jar" target="_blank">http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/jorm/jorm/externals/jdbc/msbase.jar</a></p>
<p><a href="http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/jorm/jorm/externals/jdbc/mssqlserver.jar" target="_blank">http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/jorm/jorm/externals/jdbc/mssqlserver.jar</a></p>
<p><a href="http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/jorm/jorm/externals/jdbc/msutil.jar" target="_blank">http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/jorm/jorm/externals/jdbc/msutil.jar</a></p>
<p>salve os arquivos <em>msbase</em>,<em> mssqlserver </em>e<em> msutil</em> em diretorio, no meu caso crie um diretório em <strong>/lib/sqlserver</strong></p>
<p>Torne-se Root, digite na linha de comando:</p>
<p><em><strong>su</strong></em></p>
<p>informe a senha do super-usuário.</p>
<p>Dê permissão de leitura e execução dos arquivos jars  (logado com o super-usuário):</p>
<p><strong>chmod +rx /lib/sqlserver/*.jar</strong></p>
<p><strong><br />
</strong></p>
<h1><span style="text-decoration:underline;">Adicionando repositórios no source list</span></h1>
<p>Ainda como super-usuário abra o arquivo de source list:</p>
<p><strong><em>gedit /etc/apt/sources.list </em></strong></p>
<p>adicione no <em>source list </em>os seguintes repositórios:</p>
<p><strong><em>deb http://www.repositorios.pr.gov.br/celepar/ lenny main contrib non-free</em></strong></p>
<p><strong><em>deb http://www.repositorios.pr.gov.br/celepar-backports/ lenny main contrib non-free</em></strong></p>
<p><strong><em>deb http://www.repositorios.pr.gov.br/debian lenny main/ contrib non-free</em></strong></p>
<p><strong><em>deb http://www.repositorios.pr.gov.br/debian-security/ lenny/updates main contrib non-free</em></strong></p>
<p><strong><em>deb http://www.repositorios.pr.gov.br/debian-multimedia/ lenny main</em></strong></p>
<p><strong><em>deb http://www.repositorios.pr.gov.br/debian-backports/ lenny-backports main contrib non-free</em></strong></p>
<p><strong><em> </em></strong></p>
<p>salve o arquivo.</p>
<h1>Instalando SQuirrel SQL Client</h1>
<p>atualize sua lista de repositórios com o comando:</p>
<p><strong><em>apt-get update </em></strong></p>
<p>Procure pelo nome o pacote do cliente sql squirrel-xxx</p>
<p><strong><em>apt-cache search squirrel </em></strong></p>
<p>No meu caso retornou o seguinte nome:  <em>squirrel-sql-client &#8211; SQuirreL SQL Client</em></p>
<p>instale o pacote squirrel-sql-client com o comando:</p>
<p><strong><em>apt-get install squirrel-sql-client </em></strong></p>
<p>Se necessário, confirme a instalação com  “<strong><em>y</em></strong>” ou “<strong><em>s</em></strong>” dependendo do idioma.</p>
<p>Se tudo correu bem até aqui, você estará o seu cliente sql devidamente instalado.</p>
<h1>Configurando o SQuirrel cliente para acessar o banco SQL Server 2000</h1>
<p>No Gnome entre “Aplicações”, “Programação”,  “SQuirrel SQL Client”</p>
<p><img src="http://ricardospinoza.files.wordpress.com/2009/10/11.png?w=619&#038;h=463" border="0" alt="" width="619" height="463" /></p>
<p><img src="http://ricardospinoza.files.wordpress.com/2009/10/21.png?w=619&#038;h=463" border="0" alt="" width="619" height="463" /></p>
<p><img src="http://ricardospinoza.files.wordpress.com/2009/10/31.png?w=619&#038;h=463" border="0" alt="" width="619" height="463" /></p>
<p>Entre na aba de Alias, crie uma nova conexão, informe a string de conexão do mssqlserver <strong><em>jdbc:microsoft:sqlserver://nomeServidorBD:1433</em></strong></p>
<p>Informe o usuário e  senha do banco de dados, clique em connect</p>
<p><img src="http://ricardospinoza.files.wordpress.com/2009/10/41.png?w=619&#038;h=463" border="0" alt="" width="619" height="463" /></p>
<p><a rel="attachment wp-att-132" href="http://ricardospinoza.wordpress.com/2009/10/26/como-fazer-conexao-jdbc-no-sql-server-2000-no-linux-com-o-squirrel-sql-client/image011/"><img class="aligncenter size-full wp-image-132" title="image011" src="http://ricardospinoza.wordpress.com/files/2009/10/image011.png" alt="image011" width="623" height="465" /></a></p>
<p>O seu cliente sql está configurado e pronto par a uso.</p>
<h1>Links:</h1>
<p>Squirrel SQL Client <a href="http://squirrel-sql.sourceforge.net/" target="_blank">http://squirrel-sql.sourceforge.net/</a></p>
<p>JDBC SQL Server 2000 <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&#38;displaylang=en" target="_blank">http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&#38;displaylang=en</a></p>
<p>Java J2SE <a href="http://www.sun.com/" target="_blank">http://www.sun.com</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Change the Default Backup Directory]]></title>
<link>http://lqqsql.wordpress.com/2009/10/23/change-the-default-backup-directory/</link>
<pubDate>Fri, 23 Oct 2009 19:31:00 +0000</pubDate>
<dc:creator>lqqinspace</dc:creator>
<guid>http://lqqsql.wordpress.com/2009/10/23/change-the-default-backup-directory/</guid>
<description><![CDATA[I have used this on most of my servers so that when I click restore or Backup database it doesn’t go]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>
<div lang="en-GB" style="margin-bottom:0;">I have used this on most of my servers so that when I click restore or Backup database it doesn’t go off to a directory under programme files on the C drive and goes to the root of the backup directory I use.</div>
<h2 class="western"><span lang="en-GB">SQL </span><span lang="en-GB">2005 version</span></h2>
<div lang="en-GB" style="margin-bottom:0;">This part of the script will display the current default backup directory.</div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">DECLARE</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> @BackupDirectory VARCHAR</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">(</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">100</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">)</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">EXEC</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> master</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">..</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">xp_regread @rootkey</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;HKEY_LOCAL_MACHINE&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@key</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@value_name</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;BackupDirectory&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@BackupDirectory</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@BackupDirectory OUTPUT </span></span></span> </div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">SELECT</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> @BackupDirectory </span></span></span><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">as</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> BackupDirectory</span></span></span></div>
<div lang="en-GB" style="margin-bottom:0;">
</div>
<div style="margin-bottom:0;"><span lang="en-GB">This script will set G:\Maintenance\userData as</span><span lang="en-GB"> the new default directory.</span></div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">EXEC</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> master</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">..</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">xp_regwrite </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@rootkey</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;HKEY_LOCAL_MACHINE&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@key</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@value_name</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;BackupDirectory&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@type</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;REG_SZ&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@value</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;G:\Maintenance\userData&#8217;</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div lang="en-GB" style="margin-bottom:0;">
</div>
<h2 class="western"><span lang="en-GB">SQL </span><span lang="en-GB">2000 version</span></h2>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">DECLARE</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> @BackupDirectory VARCHAR</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">(</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">100</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">)</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">EXEC</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> master</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">..</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">xp_regread @rootkey</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;HKEY_LOCAL_MACHINE&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@key</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;SOFTWARE\Microsoft\MsSQLServer\MsSQLServer&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@value_name</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;BackupDirectory&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@BackupDirectory</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@BackupDirectory OUTPUT </span></span></span> </div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">SELECT</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> @BackupDirectory </span></span></span><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">as</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> BackupDirectory</span></span></span></div>
<div lang="en-GB" style="margin-bottom:0;">
</div>
<div style="margin-bottom:0;"><span style="color:blue;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">EXEC</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> master</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">..</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">xp_regwrite </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@rootkey</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;HKEY_LOCAL_MACHINE&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@key</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;SOFTWARE\Microsoft\MsSQLServer\MsSQLServer&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@value_name</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;BackupDirectory&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@type</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;REG_SZ&#8217;</span></span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">,</span></span></span></span><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB"> </span></span></span> </div>
<div style="margin-bottom:0;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">@value</span></span></span><span style="color:grey;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">=</span></span></span></span><span style="color:red;"><span style="font-family:Courier New,monospace;"><span style="font-size:x-small;"><span lang="en-GB">&#8216;G:\Maintenance\userData&#8217;</span></span></span></span></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Deletion of row with delay]]></title>
<link>http://sqlreference.wordpress.com/2009/10/22/deletion-of-row-with-delay/</link>
<pubDate>Thu, 22 Oct 2009 07:04:31 +0000</pubDate>
<dc:creator>suniljk</dc:creator>
<guid>http://sqlreference.wordpress.com/2009/10/22/deletion-of-row-with-delay/</guid>
<description><![CDATA[DECLARE @counter tinyint SET @counter=1 WHILE @counter BEGIN SET ROWCOUNT 5000 DELETE FROM TABLE NAM]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>DECLARE @counter tinyint<br />
SET @counter=1<br />
WHILE @counter<br />
BEGIN<br />
SET ROWCOUNT 5000<br />
DELETE FROM TABLE NAME WHERE CONDITION<br />
SELECT @counter= count(*) FROM TABLE NAME WHERE CONDITION<br />
WAITFOR DELAY &#8216;000:00:02&#8242; &#8212; Delay will be 2 sec between each execution<br />
END</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Scripting Role and User Permissions]]></title>
<link>http://ctrlshiftb.wordpress.com/2009/10/05/scripting-role-and-user-permissions/</link>
<pubDate>Mon, 05 Oct 2009 16:56:51 +0000</pubDate>
<dc:creator>Ron</dc:creator>
<guid>http://ctrlshiftb.wordpress.com/2009/10/05/scripting-role-and-user-permissions/</guid>
<description><![CDATA[I recently had to copy a large number of databases to a development environment. There was several h]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I recently had to copy a large number of databases to a development environment. There was several hundred gigabytes of files, so I went with stop sql services, copy, restart services and attach new databases route.</p>
<p>Before copying the files, I migrated the users. After attaching the database files to the new instance, I ran the orphaned user scripts. Everything seemed to have swimmingly.</p>
<p>A couple of hours later, a developer called me up and said that they were running into permission errors executing stored procedures. There were a lot of scripts out there for user permissions, but none of them seemed to fit my specific needs, especially since this was SQL 2000. So, on that note, here is my addition to that myriad of scripts for SQL Server permissions.</p>
<pre class="brush: sql;">
/* SQL 2005/2008 */
DECLARE
 @Login varchar(50),
 @Role varchar(50);

SET @Login = NULL;
SET @Role = NULL;

SELECT
 perm.state_desc
 + SPACE(1)
 + perm.permission_name
 + ' on ['
 + s.name
 + '].['
 + o.name
 + '] to ['
 + prin.name
 + '];'
 + CHAR(10)
 + 'GO'
 + CHAR(10)
 COLLATE LATIN1_General_CI_AS
FROM
 sys.database_permissions perm
INNER JOIN
 sys.objects o ON
 perm.major_id = o.OBJECT_ID
INNER JOIN
 sys.schemas s ON
 o.SCHEMA_ID = s.SCHEMA_ID
INNER JOIN sys.database_principals prin ON
 perm.grantee_principal_id = prin.principal_id
WHERE
 ((prin.type = 'U' AND prin.name = @Login) OR @Login IS NULL) AND
 ((prin.type = 'R' AND prin.name = @Role) OR @Role IS NULL);

/* SQL 2000 */
DECLARE
 @Login varchar(50),
 @Role varchar(50),
 @ObjectName varchar(50);

SET @Login = NULL;
SET @Role = NULL;
SET @ObjectName = '[admin_getStoreOrderTimes]';

SELECT
 CASE ProtectType
 WHEN 204 THEN 'GRANT_W_GRANT'
 WHEN 205 THEN 'GRANT'
 WHEN 206 THEN 'DENY' END
 + SPACE(1)
 + CASE Action
 WHEN 26 THEN 'REFERENCES'
 WHEN 178 THEN 'CREATE FUNCTION'
 WHEN 193 THEN 'SELECT'
 WHEN 195 THEN 'INSERT'
 WHEN 196 THEN 'DELETE'
 WHEN 197 THEN 'UPDATE'
 WHEN 198 THEN 'CREATE TABLE'
 WHEN 203 THEN 'CREATE DATABASE'
 WHEN 207 THEN 'CREATE VIEW'
 WHEN 222 THEN 'CREATE PROCEDURE'
 WHEN 224 THEN 'EXECUTE'
 WHEN 228 THEN 'BACKUP DATABASE'
 WHEN 233 THEN 'CREATE DEFAULT'
 WHEN 235 THEN 'BACKUP LOG'
 WHEN 236 THEN 'CREATE RULE' END
 + SPACE(1)
 + 'ON'
 + SPACE(1)
 + '['
 + USER_NAME(o.uid)
 + '].['
 + OBJECT_NAME(o.id)
 + ']'
 + SPACE(1)
 + 'TO'
 + SPACE(1)
 + '['
 + u.name
 + '];'
 + CHAR(10)
 + 'GO'
 + CHAR(10)
FROM
 sysusers u
INNER JOIN
 sysprotects p ON
 u.uid = p.uid
INNER JOIN
 sysobjects o ON
 p.id = o.id
WHERE
 ((IsLogin = 1 AND u.name = @Login) OR @Login IS NULL) AND
 (((u.IsSQLRole = 1 OR u.IsAppRole = 1) AND u.name = @Role) OR @Role IS NULL) AND
 (OBJECT_NAME(o.id) = @ObjectName OR @ObjectName IS NULL) AND
 u.name NOT IN ('public','db_owner','db_accessadmin','db_securityadmin','db_ddladmin',
 'db_backupoperator','db_datareader','db_datawriter','db_denydatareader',
 'db_denydatawriter','guest');
</pre>
</pre>
<p>~<strong>Ron</strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Script Column Default Values]]></title>
<link>http://ctrlshiftb.wordpress.com/2009/10/01/script-column-default-values/</link>
<pubDate>Thu, 01 Oct 2009 07:04:07 +0000</pubDate>
<dc:creator>Ron</dc:creator>
<guid>http://ctrlshiftb.wordpress.com/2009/10/01/script-column-default-values/</guid>
<description><![CDATA[Another database developer had copied several database from our model office back to our development]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Another database developer had copied several database from our model office back to our development environment. When we started to wire up out applications I noticed that there were no indexes, defaults, keys, or constraints of any kind. Just heaps.</p>
<p>Adding these constraints is fairly straigtforward, and there are many tools out there to do that. But I could not find a tool that would script just the default constraints without also dropping and/or creating the table. It took a couple of days to get the databases moved over in the first place, but there were over a thousand default constraints, which could also take several days if done manually.</p>
<p>I was sure that there was a way to script this, but after over an hour of searching I decided that I burned enough time and that I would write one myself. I don&#8217;t know how often anyone would come across this issue, but here it is anyways.</p>
<pre class="brush: sql;">
SELECT
    'ALTER TABLE dbo.' + OBJECT_NAME(s.id) + ' ADD CONSTRAINT DF_' + OBJECT_NAME(s.id) + '_' + sc.name + ' DEFAULT ' + c.text + ' FOR ' + sc.name
FROM
    dbo.sysconstraints s
INNER JOIN syscolumns sc
	ON s.id = sc.id AND
	   s.colid = sc.colid
INNER JOIN dbo.syscomments c
    ON s.constid = c.id
WHERE
    s.status &#38; 5 = 5
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[DB User Already Exists in the Current Database]]></title>
<link>http://khanderkar.wordpress.com/2009/09/15/db-user-already-exists-in-the-current-database/</link>
<pubDate>Tue, 15 Sep 2009 12:57:52 +0000</pubDate>
<dc:creator>khanderkar</dc:creator>
<guid>http://khanderkar.wordpress.com/2009/09/15/db-user-already-exists-in-the-current-database/</guid>
<description><![CDATA[On Old Server Database is configured for custom User &amp; has DB Owner rights You export the databa]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>On Old Server Database is configured for custom User &#38; has DB Owner rights You export the database &#38; import it on New Server Create the same DB username &#38; configure this DBuser to be a DB Owner</p>
<p><strong>You receive following error:</strong></p>
<p> Microsoft SQL Server Management Studio</p>
<p>Create failed for User &#8216;DB User’.  (Microsoft.SqlServer.Smo)</p>
<p>User, group, or role &#8216; DB User &#8216; already exists in the current database. (Microsoft SQL Server, Error: 15023)</p>
<p><strong>Solution :</strong></p>
<p>EXEC sp_change_users_login &#8216;Auto_Fix&#8217;, &#8216;DB User&#8217;</p>
<p><strong>Other info :</strong></p>
<p>First, make sure that this is the problem. This will lists the orphaned users:</p>
<p>EXEC sp_change_users_login &#8216;Report&#8217;</p>
<p>If you already have a login id and password for this user, fix it by doing:</p>
<p>EXEC sp_change_users_login &#8216;Auto_Fix&#8217;, &#8216;user&#8217;</p>
<p>If you want to create a new login id and password for this user, fix it by doing:</p>
<p>EXEC sp_change_users_login &#8216;Auto_Fix&#8217;, &#8216;user&#8217;, &#8216;login&#8217;, &#8216;password</p>
<p><strong> Source :</strong></p>
<p><a href="http://stupidprogrammer.com/2009/02/20/user-already-exists-in-the-current-database/">http://stupidprogrammer.com/2009/02/20/user-already-exists-in-the-current-database/</a></p>
<p><strong> </strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Debug Stored Procedures in SQL 2000 with Visual Studio]]></title>
<link>http://ctrlshiftb.wordpress.com/2009/09/01/bebug-stored-procedures-in-sql-2000-with-visual-studio/</link>
<pubDate>Tue, 01 Sep 2009 18:43:00 +0000</pubDate>
<dc:creator>Ron</dc:creator>
<guid>http://ctrlshiftb.wordpress.com/2009/09/01/bebug-stored-procedures-in-sql-2000-with-visual-studio/</guid>
<description><![CDATA[Before I forget this again &#8230; if you are not a member of the sysadmin role you need to run this]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Before I forget this again &#8230; if you are not a member of the sysadmin role you need to run this to debug SQL 2000 stored procedures in Visual Studio.</p>
<pre class="brush: sql;">
USE [master];
GO

GRANT EXECUTE ON sp_sdidebug TO [User\Group\Role];
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Difference between Clustered and Non Clustered Index in SQL Server 2005]]></title>
<link>http://dotnetfreak.wordpress.com/2009/08/12/difference-between-clustered-and-non-clustered-index-in-sql-server-2005/</link>
<pubDate>Wed, 12 Aug 2009 01:37:43 +0000</pubDate>
<dc:creator>dotnetfreak</dc:creator>
<guid>http://dotnetfreak.wordpress.com/2009/08/12/difference-between-clustered-and-non-clustered-index-in-sql-server-2005/</guid>
<description><![CDATA[Clustered Index Leaf node contains the actual data pages. The data row of the table are sorted and s]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong><span style="text-decoration:underline;">Clustered Index</span></strong></p>
<ol>
<li>Leaf node contains the actual data pages.</li>
<li>The data row of the table are sorted and stored in the table based on their clustered index key (i.e. based on the index column(s)).</li>
<li>You can have only one clustered index per table.</li>
<li>The RowLocator in Clustered Index is the clustered Index key.</li>
</ol>
<p><strong><span style="text-decoration:underline;">Non Clustered Index</span></strong></p>
<ol>
<li>Leaf node contains index pages instead of data pages.</li>
<li>You can have up to 249 Non Clustered Index per table.</li>
<li>The data row of the table are not sorted and stored in the table based on their clustered index key (i.e. based on the index column(s)).</li>
<li>The row locator in Non Clustered Index is a pointer to the row. Row locator is built based on the following.<br />
<strong>ROW ID (RowLocator)= file identifier + page number + row number on the page</strong></li>
<li>You can have the functionality of Non key Columns (Included Columns) in case of Non Clustered Index.</li>
<li>Non key columns are stored only at the leaf level whereas Key columns (Non Clustered Index Key columns) are stored at all the levels of non clustered index.</li>
</ol>
<p><strong><span style="text-decoration:underline;">What are Heaps?</span></strong></p>
<ol>
<li>Heaps are tables without clustered index.</li>
<li>Data Rows are not stored in a particular order.</li>
<li>Sequences of the Data pages are not ordered as well as they are not linked in a linked list.</li>
</ol>
<p><strong><span style="text-decoration:underline;">Examples</span></strong></p>
<p><strong><span style="text-decoration:underline;">Clustered Index Example</span></strong></p>
<p>Clustered can be created in the following ways</p>
<ol>
<li>Create Table with Primary key – this will by default create clustered index based on the primary key defined.</li>
<li>Create clustered Index using the CREATE CLUSTERED INDEX command<strong>.</strong></li>
</ol>
<p>–create table with primary key<br />
CREATE TABLE Employee (empno NUMERIC (10) PRIMARY KEY, EmpName Varchar(10));</p>
<p>–check the existence of Index for the table</p>
<p>SELECT * FROM SYS.INDEXES WHERE OBJECT_ID = (SELECT OBJECT_ID FROM SYS.OBJECTS WHERE NAME=‘EMPLOYEE’);</p>
<p>–create table without primary key</p>
<p>CREATE TABLE Employee2 (empno NUMERIC (10), EmpName Varchar(10));</p>
<p>–Create Clustered Index using Clustered Index  Command</p>
<p>CREATE CLUSTERED INDEX IDX_CLUST_EMP ON Employee2 (empno);</p>
<p>–check the existence of Index for the table</p>
<p>SELECT * FROM SYS.INDEXES WHERE OBJECT_ID = (SELECT OBJECT_ID FROM SYS.OBJECTS WHERE NAME=‘Employee2′);</p>
<p><strong><span style="text-decoration:underline;"><br />
Non Clustered Index Example<br />
</span></strong><br />
– Adding a column the existing employee table</p>
<p>ALTER TABLE EMPLOYEE<br />
ADD TAX_ID NUMERIC(10);</p>
<p>–create non clustered index on TAX_ID column<br />
CREATE INDEX IDX_NON_CLUST ON EMPLOYEE (TAX_ID);</p>
<p>–check the existence of Index for the table<br />
SELECT * FROM SYS.INDEXES WHERE OBJECT_ID = (SELECT OBJECT_ID FROM SYS.OBJECTS WHERE NAME=‘EMPLOYEE’);</p>
<p>This is a very basic and a quick information on the differences between Clustered and Non Clustered Indexes in SQL Server.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[An Introduction to Clustered and Non-Clustered Index Data Structures]]></title>
<link>http://dotnetfreak.wordpress.com/2009/08/12/an-introduction-to-clustered-and-non-clustered-index-data-structures/</link>
<pubDate>Wed, 12 Aug 2009 01:26:34 +0000</pubDate>
<dc:creator>dotnetfreak</dc:creator>
<guid>http://dotnetfreak.wordpress.com/2009/08/12/an-introduction-to-clustered-and-non-clustered-index-data-structures/</guid>
<description><![CDATA[Part I: Non-Clustered Index Creating a Table To better explain SQL Server non-clustered indexes; let]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Part I: Non-Clustered Index</p>
<p><strong>Creating a Table</strong></p>
<p>To better explain SQL Server non-clustered indexes; let’s start by creating a new table and populating it with some sample data using the following scripts. I assume you have a database you can use for this. If not, you will want to create one for these examples.</p>
<p>Create Table DummyTable1<br />
(<br />
EmpId Int,<br />
EmpName Varchar(8000)<br />
)</p>
<p>When you first create a new table, there is no index created by default. In technical terms, a table without an index is called a “heap”. We can confirm the fact that this new table doesn’t have an index by taking a look at the sysindexes system table, which contains one for this table with an of indid = 0. The sysindexes table, which exists in every database, tracks table and index information. “Indid” refers to Index ID, and is used to identify indexes. An indid of 0 means that a table does not have an index, and is stored by SQL Server as a heap.</p>
<p>Now let’s add a few records in this table using this script:</p>
<p>Insert Into DummyTable1 Values (4, Replicate (&#8216;d&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (6, Replicate (&#8216;f&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (1, Replicate (&#8216;a&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (3, Replicate (&#8216;c&#8217;,2000))<br />
GO</p>
<p>Now, let’s view the contests of the table by executing the following command in Query Analyzer for our new table.</p>
<p>Select EmpID From DummyTable1<br />
GO</p>
<table border="0" cellspacing="0" cellpadding="0" width="78">
<tbody>
<tr>
<td width="76">
<p align="right"><strong>Empid</strong></p>
</td>
</tr>
<tr>
<td>
<p align="right">4</p>
</td>
</tr>
<tr>
<td>
<p align="right">6</p>
</td>
</tr>
<tr>
<td>
<p align="right">1</p>
</td>
</tr>
<tr>
<td>
<p align="right">3</p>
</td>
</tr>
</tbody>
</table>
<p>As you would expect, the data we inserted earlier has been displayed. Note that the order of the results is in the same order that I inserted them in, which is in no order at all.</p>
<p>Now, let’s execute the following commands to display the actual page information for the table we created and is now stored in SQL Server.</p>
<p>dbcc ind(dbid, tabid, -1) – This is an undocumented command.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>Declare @DBID Int, @TableID Int<br />
Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable1&#8242;)</p>
<p>DBCC ind(@DBID, @TableID, -1)<br />
GO</p>
<p>This script will display many columns, but we are only interested in three of them, as shown below.</p>
<table border="0" cellspacing="0" cellpadding="0" width="339">
<tbody>
<tr>
<td width="109" valign="bottom"><strong>PagePID</strong></td>
<td width="101" valign="bottom">
<p align="right"><strong>IndexID</strong></p>
</td>
<td width="123" valign="bottom">
<p align="right"><strong>PageType</strong></p>
</td>
</tr>
<tr>
<td valign="top">26408</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26255</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26409</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
</tbody>
</table>
<p>Here’s what the information displayed means:</p>
<p>PagePID is the physical page numbers used to store the table. In this case, three pages are currently used to store the data.</p>
<p>IndexID is the type of index,</p>
<p>Where:</p>
<p>0 – Datapage</p>
<p>1 – Clustered Index</p>
<p>2 – Greater and equal to 2 is an Index page (Non-Clustered Index and ordinary index),</p>
<p>PageType tells you what kind of data is stored in each database,</p>
<p>Where:</p>
<p>10 – IAM (Index Allocation MAP)</p>
<p>1 – Datapage</p>
<p>2 – Index page</p>
<p>Now, let us execute DBCC PAGE command. This is an undocumented command.</p>
<p>DBCC page(dbid, fileno, pageno, option)</p>
<p>Where:</p>
<p>dbid = database id.</p>
<p>Fileno = fileno of the page.  Usually it will be 1, unless we use more than one file for a database.</p>
<p>Pageno = we can take the output of the dbcc ind page no.</p>
<p>Option = it can be 0, 1, 2, 3. I use 3 to get a display of the data.  You can try yourself for the other options.</p>
<p>Run this script to execute the command:</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(@DBID, 1, 26408, 3)<br />
GO</p>
<p>The output will be page allocation details.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>dbcc page(@DBID, 1, 26255, 3)<br />
GO</p>
<p>The data will be displayed in the order it was entered in the table. This is how SQL stores the data in pages.  Actually, 26255 &#38; 26409 both display the data page.</p>
<p>I have displayed the data page information for page 26255 only. This is how MS SQL stores the contents in data pages as such column name with its respective value.</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId          = 4</p>
<p>EmpName    = ddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId            = 6</p>
<p>EmpName      = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId           = 1</p>
<p>EmpName     = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
<p>This displays the exact data storage in SQL, without any index on table. Now, let’s go and create a unique non-clustered index on the EmpID column.</p>
<p><strong>Creating a Non-Clustered Index</strong><strong> </strong></p>
<p>Now, we will create a unique non-clustered index on the empid column to see how it affects the data, and how the data is stored in SQL Server.</p>
<p>CREATE UNIQUE NONCLUSTERED INDEX DummyTable1_empid<br />
ON DummyTable1 (empid)<br />
GO</p>
<p>Now, execute the DBCC ind (dbid, tabid, -1)</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>Declare @DBID Int, @TableID Int<br />
Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable1&#8242;)<br />
DBCC ind(@DBID, @TableID, -1)<br />
GO</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="382">
<tbody>
<tr>
<td width="127" valign="bottom"><strong>PagePID</strong></td>
<td width="113" valign="bottom">
<p align="right"><strong>IndexID</strong></p>
</td>
<td width="136" valign="bottom">
<p align="right"><strong>PageType</strong></p>
</td>
</tr>
<tr>
<td valign="top">26408</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26255</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26409</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26411</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="bottom">
<p align="right">2</p>
</td>
</tr>
</tbody>
</table>
<p>Now, we see two more rows than before, which now contains index page details. Page 26408 displays the page allocation details, and pages 26255 and 26409 display the data page details, as before.</p>
<p>In regard to the new pages, page 26411 displays the page allocation details of an index page and page 26410 displays the index page details.</p>
<p>MS SQL generates a page (pagetype = 10) for an index and explains the page allocation details for an index. It shows the number of index page have been occupied for an index.</p>
<p>Let us see what would be the output for page 26411, that is page type = 10</p>
<p>IAM: Single Page Allocations @0&#215;308A608E</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Slot 0 = (1:26410)</p>
<p>Let us view page 26410 to see the index page details.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(10, 1, 26410, 3)<br />
GO</p>
<p>SQL populates the index column data in order. The last column (<strong>?</strong>) is pointed to the row locator.</p>
<p>Here are the results, using two different methods:</p>
<p><strong>Method I</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="472">
<tbody>
<tr>
<td width="76" valign="bottom"><strong>FileID</strong></td>
<td width="95" valign="bottom"><strong>PageID</strong></td>
<td width="80" valign="bottom"><strong>EMPID</strong></td>
<td width="213" valign="bottom">
<p align="right"><strong>?</strong></p>
</td>
</tr>
<tr>
<td valign="bottom">1</td>
<td valign="top">26410</td>
<td valign="bottom">1</td>
<td valign="top">0&#215;8F66000001000200</td>
</tr>
<tr>
<td valign="bottom">1</td>
<td valign="top">26410</td>
<td valign="bottom">3</td>
<td valign="top">0&#215;2967000001000000</td>
</tr>
<tr>
<td valign="bottom">1</td>
<td valign="top">26410</td>
<td valign="bottom">4</td>
<td valign="top">0&#215;8F66000001000000</td>
</tr>
<tr>
<td valign="bottom">1</td>
<td valign="top">26410</td>
<td valign="bottom">6</td>
<td valign="top">0&#215;8F66000001000100</td>
</tr>
</tbody>
</table>
<p>The row location display in one of two ways:</p>
<ul>
<li>If the table      does not have a clustered index, the row locator will be combination of      fileno, pageno and the no of rows in a page.</li>
<li>If the table      does have clustered index, the row location will be clustered index key      value.</li>
</ul>
<p>Non-clustered indexes are particularly handy when we want to return a single row from a table.</p>
<p>For example, to search for employee ID (empid = 3) in a table that has a non-clustered index on the empid column, SQL Server looks through the index to find an entry that lists the exact page and row in the table where the matching empid can be found, and then goes directly to that page and row. This greatly speeds up accessing the record in question.</p>
<p>Select EmpID, EmpName From DummyTable1 WHERE EMPID = 3</p>
<p>Now, let’s insert some more rows in our table and view the data page storage of our non-clustered index.</p>
<p>Insert Into DummyTable1 Values (10, Replicate (&#8216;j&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (2, Replicate (&#8216;b&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (5, Replicate (&#8216;e&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (8, Replicate (&#8216;h&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (9, Replicate (&#8216;i&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable1 Values (7, Replicate (&#8216;g&#8217;,2000))<br />
GO</p>
<p>Now, let’s view the data in our table.</p>
<p>Execute:</p>
<p>Select EmpID From DummyTable1</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="76">
<tbody>
<tr>
<td width="74" valign="bottom">
<p align="right"><strong>EmpID</strong></p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">4</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">6</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">3</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">2</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">5</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">8</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">9</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">7</p>
</td>
</tr>
</tbody>
</table>
<p>As you may notice above, the data is still in the order we entered it, and not in any particular order. This is because adding the non-clustered index didn’t change how the data was stored and ordered on the data pages.</p>
<p>Now, let’s view the results of the DBCC IND command. In order to find out what happened when the new data was added to the table.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>Declare @DBID Int, @TableID Int<br />
Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable1&#8242;)<br />
DBCC ind(@DBID, @TableID, -1)<br />
GO</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="311">
<tbody>
<tr>
<td width="103" valign="bottom"><strong>PagePID</strong></td>
<td width="96" valign="bottom">
<p align="right"><strong>IndexID</strong></p>
</td>
<td width="106" valign="bottom">
<p align="right"><strong>PageType</strong></p>
</td>
</tr>
<tr>
<td valign="top">26408</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26255</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26409</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26412</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26413</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26411</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="bottom">
<p align="right">2</p>
</td>
</tr>
</tbody>
</table>
<p>Let us execute the page 26410 again and get the index page details.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>dbcc page(10, 1, 26410, 3)<br />
GO</p>
<p>SQL Server populates the index column data in order.  The last column (<strong>?</strong>) is pointed to the row locator.</p>
<p>Here are the results:</p>
<p><strong>Method I</strong><strong> </strong></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="77" valign="bottom">
<p align="right"><strong>FileID</strong></p>
</td>
<td width="86" valign="bottom"><strong>PageID</strong></td>
<td width="79" valign="bottom">
<p align="right"><strong>EMPID</strong></p>
</td>
<td width="238" valign="bottom"><strong>?</strong></td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">
<p align="right">0&#215;8F66000001000200</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="top">
<p align="right">0&#215;2C67000001000000</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">3</p>
</td>
<td valign="top">
<p align="right">0&#215;2967000001000000</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">4</p>
</td>
<td valign="top">
<p align="right">0&#215;8F66000001000000</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">5</p>
</td>
<td valign="top">
<p align="right">0&#215;2C67000001000100</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">6</p>
</td>
<td valign="top">
<p align="right">0&#215;8F66000001000100</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">7</p>
</td>
<td valign="top">
<p align="right">0&#215;2D67000001000000</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">8</p>
</td>
<td valign="top">
<p align="right">0&#215;2C67000001000200</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">9</p>
</td>
<td valign="top">
<p align="right">0&#215;2967000001000200</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">10</p>
</td>
<td valign="top">
<p align="right">0&#215;2967000001000100</p>
</td>
</tr>
</tbody>
</table>
<p>As I explained earlier, there are two types of row locations. We have seen <strong>Method I</strong>.  Now, let’s try <strong>Method II</strong> with the help of a clustered and non-clustered index in a table. DummyTable1 already has a non-clustered index. Let’s now add a new column to the DummyTabl1 table and add a clustered index on that column.</p>
<p>Alter Table DummyTable1 Add EmpIndex Int IDENTITY(1,1)<br />
GO</p>
<p>This will link the clustered index key value, instead of <strong>the row locator, and be will the combination of fileno, pageno and no of rows in a page.</strong><strong> </strong></p>
<p>This adds the Empindex column to DummyTable1. I have used an identity column so that we will not have null values on that column.</p>
<p>You can execute the DBCC ind and DBCC page to check if there any change after the new column is added to the table. If you don’t want to check this yourself, I can tell you that adding the new column did not affect the total number of pages currently allocated to the table by SQL Server.</p>
<p>Now, let’s add a unique clustered index on the empindex column and then view the differences in <strong>page 26410.</strong></p>
<p>First, we execute the DBCC ind command.  This displays a new set of pages for dummytable1.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>Declare @DBID Int, @TableID Int<br />
Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable1&#8242;)<br />
DBCC ind(@DBID, @TableID, -1)<br />
GO</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="304">
<tbody>
<tr>
<td width="99" valign="bottom"><strong>PagePID</strong></td>
<td width="92" valign="bottom">
<p align="right"><strong>IndexID</strong></p>
</td>
<td width="107" valign="bottom">
<p align="right"><strong>PageType</strong></p>
</td>
</tr>
<tr>
<td valign="top">26415</td>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26414</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26416</td>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="bottom">
<p align="right">2</p>
</td>
</tr>
<tr>
<td valign="top">26417</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26418</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26420</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26419</td>
<td valign="bottom">
<p align="right">2</p>
</td>
<td valign="bottom">
<p align="right">2</p>
</td>
</tr>
</tbody>
</table>
<p>Pages 26415 and 26420 have page allocation details.  Pages 26414, 26417 and 26418 have data page details.</p>
<p>Now, let’s view pages 26416 and 26419 and see the output.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(10, 1, 26416, 3)<br />
GO</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="414">
<tbody>
<tr>
<td width="71" valign="bottom">
<p align="right"><strong>FileID</strong></p>
</td>
<td width="89" valign="bottom"><strong>PageID</strong></td>
<td width="156" valign="bottom"><strong>ChildPageID</strong></td>
<td width="91" valign="bottom">
<p align="right"><strong>EMPID</strong></p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26416</td>
<td valign="top">26414</td>
<td valign="bottom">
<p align="right">0</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26416</td>
<td valign="top">26417</td>
<td valign="bottom">
<p align="right">5</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26416</td>
<td valign="top">26418</td>
<td valign="bottom">
<p align="right">9</p>
</td>
</tr>
</tbody>
</table>
<p>This displays the output of the clustered index page, which has got a link to data page (ChildPageID).  EMPID is an index column that contains the starting row of the page.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(10, 1, 26419, 3)<br />
GO</p>
<p>Here are the results:</p>
<p><strong>Method II</strong><strong></strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="356">
<tbody>
<tr>
<td width="77" valign="bottom"><strong>FileID</strong></td>
<td width="82" valign="bottom"><strong>PageID</strong></td>
<td width="72" valign="bottom"><strong>EMPID</strong></td>
<td width="117" valign="bottom"><strong>EMPIndex</strong></td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">1</td>
<td valign="top">1</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">2</td>
<td valign="top">2</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">3</td>
<td valign="top">3</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">4</td>
<td valign="top">4</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">5</td>
<td valign="top">5</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">6</td>
<td valign="top">6</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">7</td>
<td valign="top">7</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">8</td>
<td valign="top">8</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">9</td>
<td valign="top">9</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="top">26419</td>
<td valign="top">10</td>
<td valign="top">10</td>
</tr>
</tbody>
</table>
<p>It is interesting to see the differences now. There is a difference between <strong>Method I</strong> and<strong>Method II</strong>.  <strong>Method II</strong> is now linked to a clustered index key.</p>
<p>The main difference between <strong>Method I</strong> and <strong>Method II </strong>is the link to a row in a data page.</p>
<p>Part II: Clustered Index</p>
<p><strong>Creating a Table</strong><strong></strong></p>
<p>To better explain how SQL Server creates clustered indexes; let’s start by creating a new table and populating it with some sample data using the following scripts. You can use the same sample database as before.</p>
<p>Create Table DummyTable2</p>
<p>(<br />
EmpId Int,<br />
EmpName Varchar(8000)<br />
)</p>
<p>As in the previous example, when you first create a new table, there is no index created by default, and a heap is created. As before, we can confirm the fact that this new table doesn’t have an index by taking a look at the sysindexes system table, which contains one for this table with an of indid = 0. The sysindexes table, which exists in every database, tracks table and index information. “Indid” refers to Index ID, and is used to identify indexes. An indid of 0 means that a table does not have an index, and is stored by SQL Server as a heap.</p>
<p>Now let’s add a few records in this table using this script:</p>
<p>Insert Into DummyTable2 Values (4, Replicate (&#8216;d&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable2 Values (6, Replicate (&#8216;f&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable2 Values (1, Replicate (&#8216;a&#8217;,2000))<br />
GO</p>
<p>Insert Into DummyTable2 Values (3, Replicate (&#8216;c&#8217;,2000))<br />
GO</p>
<p>Now, let’s view the contents of the table by executing the following command in Query Analyzer for our new table.</p>
<p>Select EmpID From DummyTable2<br />
GO</p>
<table border="0" cellspacing="0" cellpadding="0" width="64">
<tbody>
<tr>
<td width="71" valign="bottom">
<p align="right"><strong>Empid</strong></p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">4</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">6</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">3</p>
</td>
</tr>
</tbody>
</table>
<p>As you would expect, the data we inserted has been displayed. Note that the order of the results is in the same order that I inserted them in, which is in no order at all.</p>
<p>Now, let’s execute the following commands to display the actual page information for the table we created and is now stored in SQL Server.</p>
<p>DBCC ind(dbid, tabid, -1) – It is an undocumented command.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>Declare @DBID Int, @TableID Int<br />
Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable2&#8242;)<br />
DBCC ind(@DBID, @TableID, -1)<br />
GO</p>
<p>This script will display many columns, but we are only interested in three of them, as shown below.</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="325">
<tbody>
<tr>
<td width="103" valign="bottom"><strong>PagePID</strong></td>
<td width="98" valign="bottom">
<p align="right"><strong>IndexID</strong></p>
</td>
<td width="118" valign="bottom">
<p align="right"><strong>PageType</strong></p>
</td>
</tr>
<tr>
<td valign="top">26408</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26255</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26409</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
</tbody>
</table>
<p>Here’s what the information displayed means:</p>
<p>PagePID is the physical page numbers used to store the table. In this case, three pages are currently used to store the data.</p>
<p>IndexID is the type of index,</p>
<p>Where:</p>
<p>0 – Datapage</p>
<p>1 – Clustered Index</p>
<p>2 – Greater and equal to 2 is an Index page (Non-Clustered Index and ordinary index)</p>
<p>PageType tells you what kind of data is stored in each database</p>
<p>Where:</p>
<p>10 – IAM (Index Allocation MAP)</p>
<p>1 – Datapage</p>
<p>2 – Index page</p>
<p>Now, let us execute DBCC PAGE command.</p>
<p>DBCC page(dbid, fileno, pageno, option)</p>
<p>Where:</p>
<p>dbid = database id.</p>
<p>Fileno = fileno of the page.  Usually it will be 1, unless we use more than one file for a database.</p>
<p>Pageno = we can take the output of the dbcc ind page no.</p>
<p>Option = it can be 0, 1, 2, 3. I use 3 to get a display of the data.  You can try yourself for the other options.</p>
<p>Run this script to execute the command:</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(@DBID, 1, 26408, 3)<br />
GO</p>
<p>The output will be page allocation details.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(@DBID, 1, 26255, 3)<br />
GO</p>
<p>The output will display the data however it was entered in the table. This is how SQL stores the data in pages. Actually, 26255 &#38; 26409 will display the data page.</p>
<p>I have displayed the data page information for page 26255 only. This is how MS-SQL stores the contents in data pages as such column name with its respective value.</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId          = 4</p>
<p>EmpName    = dddddddddddddddddddddddddddddddddddddddddddddddd<br />
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId           = 6</p>
<p>EmpName     = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId           = 1</p>
<p>EmpName     = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
<p>This displays the exact data storage in SQL without any index on table. Now, let’s go and create a Unique Clustered Index on EmpID column.</p>
<p><strong>Create a Clustered Index</strong><strong></strong></p>
<p>Now, let us create a unique clustered index on empid column to see how it affects the data that is stored in SQL Server.</p>
<p>CREATE UNIQUE CLUSTERED INDEX DummyTable2_EmpIndex<br />
ON DummyTable2 (EmpID)<br />
GO</p>
<p>Execute:</p>
<p>Select EmpID From DummyTable2</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="64">
<tbody>
<tr>
<td width="71" valign="bottom">
<p align="right"><strong>Empid</strong></p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">3</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">4</p>
</td>
</tr>
<tr>
<td valign="bottom">
<p align="right">6</p>
</td>
</tr>
</tbody>
</table>
<p>Now, execute the DBCC ind (dbid, tabid, -1)</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>Declare @DBID Int, @TableID Int</p>
<p>Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable2&#8242;)</p>
<p>DBCC ind(@DBID, @TableID, -1)<br />
GO</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="328">
<tbody>
<tr>
<td width="106" valign="bottom"><strong>PagePID</strong></td>
<td width="107" valign="bottom">
<p align="right"><strong>IndexID</strong></p>
</td>
<td width="109" valign="bottom">
<p align="right"><strong>PageType</strong></p>
</td>
</tr>
<tr>
<td valign="top">26411</td>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="bottom">
<p align="right">10</p>
</td>
</tr>
<tr>
<td valign="top">26410</td>
<td valign="bottom">
<p align="right">0</p>
</td>
<td valign="bottom">
<p align="right">1</p>
</td>
</tr>
<tr>
<td valign="top">26412</td>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="bottom">
<p align="right">2</p>
</td>
</tr>
</tbody>
</table>
<p><strong> </strong>MS SQL generates a page (pagetype = 10) for an index and explains the page allocation details for an index. It shows the number of index page have been occupied for an index.</p>
<p>Now, let us view the page 26410 and 26412 and see the page details.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page(10, 1, 26412, 3)<br />
GO</p>
<p>Here are the results:</p>
<table border="0" cellspacing="0" cellpadding="0" width="426">
<tbody>
<tr>
<td width="71" valign="bottom">
<p align="right"><strong>FileID</strong></p>
</td>
<td width="114" valign="bottom">
<p align="right"><strong>PageID</strong></p>
</td>
<td width="137" valign="bottom">
<p align="right"><strong>ChildPageID</strong></p>
</td>
<td width="97" valign="bottom"><strong>EMPID</strong></td>
</tr>
<tr>
<td valign="bottom">
<p align="right">1</p>
</td>
<td valign="bottom">
<p align="right">26412</p>
</td>
<td valign="bottom">
<p align="right">26410</p>
</td>
<td valign="bottom">0</td>
</tr>
</tbody>
</table>
<p>The output display many columns, but we are only interested in four of them as shown above.</p>
<p>This will display the output of the index page, which has got link to data page (ChildPageID).  EMPID is an index column will contain the starting row of the page.</p>
<p>Now, let us view the page 26410 and see the page details.</p>
<p>DBCC TRACEON (3604)<br />
GO</p>
<p>DBCC page (10, 1, 26410, 3)<br />
GO</p>
<p>Here are the results:</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId            = 1</p>
<p>EmpName          = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId            = 2</p>
<p>EmpName          = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb<br />
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb<br />
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb<br />
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb<br />
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb</p>
<p>Record Type = PRIMARY_RECORD</p>
<p>EmpId            = 3</p>
<p>EmpName          = cccccccccccccccccccccccccccccccccccccccccccccccc<br />
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc<br />
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc<br />
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc<br />
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</p>
<p>Though I have added disorder records, SQL has displayed the data page in sequence because we have got a clustered index on empid. This is absolutely great!  Adding a clustered index to the table has physically reordered the data pages, putting them in physical order based on the indexed column.</p>
<p>Now, let’s insert some more rows in our table and view the data and index page storage of our clustered index.</p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Insert Into DummyTable2 Values (10, Replicate (&#8216;j&#8217;,2000))<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Insert Into DummyTable2 Values (2, Replicate (&#8216;b&#8217;,2000))<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Insert Into DummyTable2 Values (5, Replicate (&#8216;e&#8217;,2000))<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Insert Into DummyTable2 Values (8, Replicate (&#8216;h&#8217;,2000))<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Insert Into DummyTable2 Values (9, Replicate (&#8216;i&#8217;,2000))<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Insert Into DummyTable2 Values (7, Replicate (&#8216;g&#8217;,2000))<br />
GO</span></p>
<p>Now, execute the DBCC ind (dbid, tabid, -1)</p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">DBCC TRACEON (3604)<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Declare @DBID Int, @TableID Int</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Select @DBID = db_id(), @TableID = object_id(&#8216;DummyTable2&#8242;)</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">DBCC ind(@DBID, @TableID, -1)<br />
GO</span></p>
<p>Here are the results:</p>
<table id="table16" style="width:342px;border-collapse:collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height:12.75pt;">
<td style="width:115px;height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="font-weight:bold;"><strong>PagePID</strong></p>
</td>
<td style="width:110px;height:12.75pt;padding:.75pt .75pt 0;" align="right" valign="bottom">
<p style="font-weight:bold;"><strong>IndexID</strong></p>
</td>
<td style="width:111px;height:12.75pt;padding:.75pt .75pt 0;" align="right" valign="bottom">
<p style="font-weight:bold;"><strong>PageType</strong></p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26411</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">1</p>
</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">10</p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26410</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">0</p>
</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">1</p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26412</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">1</p>
</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">2</p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26255</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">0</p>
</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">1</p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26408</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">0</p>
</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">1</p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26409</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">0</p>
</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="text-align:right;" align="right">1</p>
</td>
</tr>
</tbody>
</table>
<p>Now, we see few more rows than before. Page 26411 displays the page allocation details, and pages 26408, 26409, 26410 and 26255 display the data page details, as before.</p>
<p>In regard to the new pages, page 26411 displays the page allocation details of an index page and 26412 displays the index page details.</p>
<p>MS-SQL generates a page (pagetype = 10) for an index and explains the page allocation details for an index.  It shows the number of index page have been occupied for an index.</p>
<p>Let us see what would be the output for page 26411, that is page type = 10.</p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">DBCC TRACEON (3604)<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">dbcc page(10, 1, 26411, 3)<br />
GO</span></p>
<p>Here are the results:</p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">IAM: Single Page Allocations @0&#215;30A5C08E</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Slot 0 = (1:26410)</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Slot 1 = (1:26412)</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Slot 2 = (1:26255)</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Slot 3 = (1:26408)</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Slot 4 = (1:26409)</span></p>
<p>Let us view page 26412 to see the index page details.</p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">DBCC TRACEON (3604)<br />
GO</span></p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">DBCC page(10, 1, 26412, 3)<br />
GO</span></p>
<p>Here are the results:</p>
<table id="table17" style="width:379px;border-collapse:collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height:12.75pt;">
<td width="71" valign="bottom">
<p style="font-weight:bold;"><strong>FileID</strong></p>
</td>
<td style="width:85px;height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="font-weight:bold;"><strong>PageID</strong></p>
</td>
<td style="width:126px;height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="font-weight:bold;"><strong>ChildPageID</strong></p>
</td>
<td style="width:91px;height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">
<p style="font-weight:bold;"><strong>EMPID</strong></p>
</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">1</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26412</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26410</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">0</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">1</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26412</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26408</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">4</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">1</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26412</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26255</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">6</td>
</tr>
<tr style="height:12.75pt;">
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="bottom">1</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26412</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">26409</td>
<td style="height:12.75pt;padding:.75pt .75pt 0;" valign="top">9</td>
</tr>
</tbody>
</table>
<p>This helps us to get an idea to decide the need of clustered index. It is really useful to have a clustered index when retrieve many rows of data, ranges of data, and when BETWEEN is used in the WHERE clause. Because, the leaf level of the clustered index is the data. It should be used to save many I/Os. So, it is better to use clustered indexes to solve queries asking for ranges of data, not one row.</p>
<p>For example, to search for an employee ID (empid between 3 and 9) in a table that has a clustered index on the empid column.</p>
<p style="font-family:'Courier New', Courier, mono;font-size:small;color:#0033ff;text-align:left;"><span style="color:#0000ff;">Select EmpID, EmpName From DummyTable1 WHEREEMPID Between 3 And 9</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Best way of writing stored Procedures]]></title>
<link>http://dotnetfreak.wordpress.com/2009/08/11/best-way-of-writing-stored-procedures/</link>
<pubDate>Tue, 11 Aug 2009 01:19:05 +0000</pubDate>
<dc:creator>dotnetfreak</dc:creator>
<guid>http://dotnetfreak.wordpress.com/2009/08/11/best-way-of-writing-stored-procedures/</guid>
<description><![CDATA[The writing of stored procedures is a very common task in todays database world. Not only by databas]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="margin:.6em 0;padding:0;">The writing of stored procedures is a very common task in todays database world. Not only by database developers, but also application developers are writing the procedures. DBA&#8217;s also need to write procedures. In fact, I have faced a very common question in my interviews: &#8221; How many stored procedures have you written?&#8221;</p>
<p style="margin:.6em 0;padding:0;">Since the world is going for fat servers (a server which runs an application where most of the program code resides on it rather than on the client computers), stored procedures are gaining more and more importance. Here is my humble try to give some tips to write good procedures. I hope this will add value for novice as well as experienced programmers.</p>
<p style="margin:.6em 0;padding:0;"><strong>1. Keywords</strong> &#8211; Use SQL keywords in capital letters to increase readability. Also use proper indentation to increase readability.</p>
<p style="margin:.6em 0;padding:0;"><strong>2. SQL-92</strong> &#8211; Always try to use ANSI 92 syntax. Till now the old syntax is working the old syntax will be deprecated in the next release of MS SQL server.<br />
As an example, for joining, use</p>
<div id="highlighter_659019" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">employee e1 </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">INNER</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">JOIN</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">employee _dtl e2</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">ON</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">e1</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">.</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">id </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">e2</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">.</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">id</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;">Instead of</p>
<div id="highlighter_555642" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">employee e1</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">,</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">employee_dtl e2</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">WHERE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">e1</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">.</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">id </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">e2</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">.</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">id</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;"><strong>3. Variables</strong> &#8211; Use as few as possible variables. It frees spaces in cache.</p>
<p style="margin:.6em 0;padding:0;"><strong>4. Dynamic Queries</strong> &#8211; Try to minimize the usage of dynamic queries. If you are using a dynamic query like: SELECT * FROM mydb.dbo.emp where empid = @eid then there is no problem. You can supply a value for the @eid parameter and there is no recompilation of the execution plan in the database cache. But if you are using a SQL query like SELECT * FROM emp where empid = &#8221; + @eid and supply a parameter (say 100), then the cache will keep the execution plan for the value of 100 only. If the id changes (to say 101), it will recompile the statement. Hence, this approach is slower than the previous one. (You can get the exact value of the SQL statement from Profiler)</p>
<p style="margin:.6em 0;padding:0;"><strong>5. Fully Qualified Names</strong> &#8211; Always use the fully qualified name when calling stored procedures. This would be the format database_name.schema_name.table_name. For example, use EXEC master.dbo.Your_Proc_name instead of EXEC Your_Proc_name This is a very common mistake, which causes an extra trip to the procedure cache to get the execution plan for execution. Also try to use the schema name while creating a procedure. Like: CREATE PROCEDURE dbo.Your_Proc_name instead of CREATE PROCEDURE Your_Proc_name</p>
<p style="margin:.6em 0;padding:0;"><strong>6.SET NOCOUNT OFF</strong> &#8211; This returns the message that shows number of rows affected by SQL statement. This can cause extra network traffic and can have some serious impact on performance when the procedure is called frequently.</p>
<p style="margin:.6em 0;padding:0;"><strong>7. The sp_ prefix</strong> &#8211; Don&#8217;t use the &#8220;sp_&#8221; prefix in a stored procedure name as the &#8220;sp_&#8221; prefix is reserved for system stored procedures. Any stored procedure that has the &#8220;sp_&#8221; prefix will cause an extra lookup in the MASTER database If a stored procedure uses same name in both the user database and a system database, the stored procedure in the user database will never get executed.</p>
<p style="margin:.6em 0;padding:0;"><strong>8. sp_executeSQL and the KEEPFIXED PLAN options</strong> &#8211; Both sp_executesql and the KEEPFIXED PLAN option avoid the recompilation of a stored procedure. If you want to provide parameterized dynamic SQL, then go for sp_executesql instead of EXEC(proc_name). Here the execution plan for the procedure is stored with the variable name in cache memory. When the variable values are supplied, then the values are simply mapped to the query, hence no need for a recompilation.</p>
<p style="margin:.6em 0;padding:0;">Use the OPTION KEEPFIXED PLAN hint while selecting records from temporary tables. If the query contains this hint, then its plan is not recompiled. For more information about procedure recompilation, please go through the following article:<a style="text-decoration:none;color:#225588;" href="http://technet.microsoft.com/en-us/library/cc966425.aspx">http://technet.microsoft.com/en-us/library/cc966425.aspx</a></p>
<div id="highlighter_867836" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">CREATE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">PROCEDURE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">my_proc</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">AS</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">CREATE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">TABLE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">#t </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">(</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">a </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">int</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">)</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">#t</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">INSERT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">#t </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">from</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">retest</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#ff00ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">COUNT</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">(</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">)</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">#t </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">WHERE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">a </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">37</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">OPTION</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">(</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">KEEPFIXED PLAN</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">)</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;">As an example of sp_executesql, we can write:</p>
<div id="highlighter_22750" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#880000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">sp_executesql</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">N</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:red!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">'SELECT * FROM mydb.dbo.emp where empid = @eid'</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">,</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">N</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:red!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">'@eid int'</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">,</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@eid</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">40</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;"><strong>9. SELECT vs SET</strong> &#8211; A single SELECT statement can assign values to different variables and is much faster than multiple SET statements assigning values to multiple different variables.</p>
<div id="highlighter_168827" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var1</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var1</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">+</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">1</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">,</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var2</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var2</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">- 1</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;">instead of</p>
<div id="highlighter_78312" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SET</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var1</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var1</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">+</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">1</code></span></span></div>
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SET</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var2</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">@Var2</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">- 1</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;"><strong>10. WHERE clauses</strong> &#8211; In a WHERE clause, the various operators used directly affect how fast a query can run. Here are the conditional operators used in the WHERE clause, ordered by their performance.</p>
<p style="margin:.6em 0;padding:0;">=, &#62;, &#60;, &#62;=, &#60;=, &#60;&#62;, !=, !&#62;, !&#60;</p>
<p style="margin:.6em 0;padding:0;">for details, refer to the article: <a style="text-decoration:none;color:#225588;" href="http://msdn.microsoft.com/en-us/library/ms190276.aspx">http://msdn.microsoft.com/en-us/library/ms190276.aspx</a></p>
<p style="margin:.6em 0;padding:0;"><strong>11. More WHERE clause hints</strong> &#8211; Avoid unnecessary conditions in the WHERE Clause. You can easily use the first example instead of the second one. The second example uses one extra OR condition which can be avoided using the first example.</p>
<div id="highlighter_258428" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_name </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">table_name </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">WHERE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#ff00ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">LOWER</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">(</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_name</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">)</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:red!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">'edu'</code></span></span></div>
</div>
</div>
<div id="highlighter_632833" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_name </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">table_name </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">WHERE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_name </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:red!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">'EDU'</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">OR</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_name </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">=</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:red!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">'edu'</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;">Also, try to avoid IN. While checking the existence of some values, then use EXISTS instead of IN. Because IN counts the NULL values also, hence slower than EXISTS. Since EXISTS returns Boolean(Yes/No) but IN returns all values hence result set for IN is heavier than EXISTS.</p>
<div id="highlighter_991520" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">employee </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">WHERE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_no </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">NOT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">IN</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">(</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_no </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">from</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_detail</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">)</code></span></span></div>
</div>
</div>
<div id="highlighter_984408" style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#e7e5dc!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:relative!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:467px;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;max-height:300px;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:1em 0!important;padding:1px!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">
<div style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:#ffffff!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;display:block!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 .5em !important;"><span style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:url('http://www.sqlservercentral.com/shared/syntaxhighlighter/styles/wrapping.png');background-repeat:no-repeat!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;text-indent:-1.5em!important;background-position:0 1.1em!important;border:0 !important initial !important initial!important;margin:0!important;padding:0 0 0 1.5em !important;"><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">*</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">employee </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">WHERE</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">NOT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">EXISTS</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">(</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">SELECT</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_no </code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#0000ff!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">FROM</code> <code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#000000!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">emp_detail</code><code style="outline-width:0!important;outline-style:initial!important;outline-color:initial!important;background-image:none!important;background-repeat:initial!important;background-attachment:initial!important;background-color:initial!important;text-align:left!important;float:none!important;vertical-align:baseline!important;position:static!important;left:auto!important;top:auto!important;right:auto!important;bottom:auto!important;height:auto!important;width:auto!important;line-height:1.1em!important;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace!important;font-weight:normal!important;font-style:normal!important;font-size:1em!important;color:#808080!important;background-position:initial initial!important;border:0 !important initial !important initial!important;margin:0!important;padding:0!important;">)</code></span></span></div>
</div>
</div>
<p style="margin:.6em 0;padding:0;"><strong>12. CAST and CONVERT</strong> &#8211; Try to use CAST instead of CONVERT. CAST is ANSI-92 standard but CONVERT works in MS SQL server only. Also, Convert may be deprecated in future MS SQL releases. It is better to use CONVERT only when you need to format the DATETIME datatype with the style option. CAST cannot do this.</p>
<p style="margin:.6em 0;padding:0;"><strong>13. Avoid DISTINCT and ORDER BY</strong> &#8211; If you don&#8217;t need the DISTINCT/ORDER BY clause, then try to avoid so. Unnecessary DISTINCT or ORDER BY clauses cause extra work for the database engine. Hence making performance slower.</p>
<p style="margin:.6em 0;padding:0;"><strong>14. Avoid using cursors</strong> &#8211; Try to use temporary table/table variables with identity column and then iterate all the tables using WHILE loop and a looping counter, which will map with the identity column. For details, refer my previous article.<a style="text-decoration:none;color:#225588;" href="http://www.sqlservercentral.com/articles/Stored+Procedures/64523/">http://www.sqlservercentral.com/articles/Stored+Procedures/64523/</a></p>
<p style="margin:.6em 0;padding:0;"><strong>15.SELECT statements</strong> &#8211; Try to use only the required number of columns in the SELECT clause instead of using *. Using * returns all columns, which unnecessarily create a fat recordset.</p>
<p style="margin:.6em 0;padding:0;"><strong>16.Subquery vs JOINs</strong> &#8211; This is a famous debate in many online forums. In fact most sub queries can be expressed as an equivalent form of JOIN. I have a good rule of thumb: subquery is faster when we have to retrieve data from large number of tables because it becomes tedious to join more tables. JOIN is faster to retrieve data from database when we have less number of tables. But try to avoid correlated sub queries because it makes the query much slower.</p>
<p style="margin:.6em 0;padding:0;"><strong>17. CREATE TABLE vs. SELECT INTO</strong> &#8211; Select * INTO works fine for small tables, but when dealing with large record sets or long-running queries, it creates locks on the system objects within the tempdb database. As a result, other queries and procedures that need to create objects within the tempdb database will have to wait for the long-running query to complete. This is because when an object is created, an exclusive lock is taken against the sysobjects, syscolumns, sysindexes tables.</p>
<p style="margin:.6em 0;padding:0;">Also, SELECT INTO not only copies data but also it copies the table structure, hence it performs slower.</p>
<p style="margin:.6em 0;padding:0;"><strong>18. Try to use table variables instead of Temporary Tables</strong> &#8211; Temp tables can cause stored procedures to recompile. But table variables were designed specifically to guard against stored procedure recompiles during execution.</p>
<p style="margin:.6em 0;padding:0;">If the result set is not containing a huge number of records then you should stick to table variable, otherwise temp table has its advantages. There is a misconception that temp tables always use the tembdb database but table variable do not. Table variables also use tempdb after a certain size. For more information refer to the following article : <a style="text-decoration:none;color:#225588;" href="http://www.sqlservercentral.com/articles/Temporary+Tables/66720/">http://www.sqlservercentral.com/articles/Temporary+Tables/66720/</a></p>
<p style="margin:.6em 0;padding:0;"><strong>19.Use proper indexes</strong> &#8211; You can use the help of the data tuning advisor, but it does not gives the proper result all the time. Index scans are much faster than table scans. So identify the table scans from the execution plans. But when a table returns smaller rows, then it is better to use a table scan. You can see an excellent article on execution plans by G Vijayakumara at the following link:<a style="text-decoration:none;color:#225588;" href="http://www.sqlservercentral.com/articles/Administration/executionplans/1345/">http://www.sqlservercentral.com/articles/Administration/executionplans/1345/</a></p>
<p style="margin:.6em 0;padding:0;"><strong>20. Use Profiler</strong> &#8211; The cachemiss event class indicates that the stored procedure is not in the cache. If the SP:Cachemiss class occurs frequently, it can indicate that more memory should be available to MS SQL server, thereby increasing the size of procedure cache. The cachehit event class indicates that a stored procedure is in the cache.</p>
<p style="margin:.6em 0;padding:0;">Last but not the least, again I am repeating the same advice from my previous article. Keep these guidelines in your mind, but don&#8217;t hesitate to break them if needed. After all, performance is the ultimate goal. If violating the general rule gives you good performance (it may happen based on your database) then don&#8217;t stick with the guidelines.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Use Index and Cursor in SQL Server 2000]]></title>
<link>http://mkansagarfa.wordpress.com/2009/07/31/use-index-and-cursor-in-sql-server-2000-2/</link>
<pubDate>Fri, 31 Jul 2009 15:32:05 +0000</pubDate>
<dc:creator>mkansagarfa</dc:creator>
<guid>http://mkansagarfa.wordpress.com/2009/07/31/use-index-and-cursor-in-sql-server-2000-2/</guid>
<description><![CDATA[Using Index ================ select *from ZIPCodes where StateName = &#8216;New York&#8217; &#8211; ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Using Index<br />
================<br />
select *from ZIPCodes where StateName = &#8216;New York&#8217;</p>
<p>&#8211; Create Index<br />
create nonclustered index idxStateName on ZIPCodes(StateName)<br />
create nonclustered index idxZIPType on ZIPCodes(ZIPType)</p>
<p>&#8211; Use Index<br />
select *from ZIPCodes with(INDEX(idxZIPType)) where ZIPType = &#8216;S&#8217;</p>
<p>&#8211; List of Indexes on Perticular Table<br />
exec sp_helpindex &#8216;ps_client_master&#8217;</p>
<p>&#8211; Drop Index<br />
drop index ps_client_master.ps_client_master_Index_1</p>
<p>Using Cursors<br />
===============</p>
<p>DECLARE @ClientID char(11)</p>
<p>declare cl CURSOR FOR<br />
select int_id from ps_client_master</p>
<p>open cl</p>
<p>FETCH NEXT FROM cl into @ClientID<br />
while @@FETCH_STATUS = 0<br />
begin<br />
print @ClientID<br />
fetch next from cl into @ClientID<br />
end</p>
<p>close cl<br />
DEALLOCATE cl</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Use Index and Cursor in SQL Server 2000]]></title>
<link>http://mkansagarfa.wordpress.com/2009/07/31/use-index-and-cursor-in-sql-server-2000/</link>
<pubDate>Fri, 31 Jul 2009 15:12:37 +0000</pubDate>
<dc:creator>mkansagarfa</dc:creator>
<guid>http://mkansagarfa.wordpress.com/2009/07/31/use-index-and-cursor-in-sql-server-2000/</guid>
<description><![CDATA[Using Index ================ select *from ZIPCodes where StateName = &#8216;New York&#8217; &#8211; ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Using Index<br />
================<br />
select *from ZIPCodes where StateName = &#8216;New York&#8217;</p>
<p>&#8211; Create Index<br />
create nonclustered index idxStateName on ZIPCodes(StateName)<br />
create nonclustered index idxZIPType on ZIPCodes(ZIPType)</p>
<p>&#8211; Use Index<br />
select *from ZIPCodes with(INDEX(idxZIPType)) where ZIPType = &#8216;S&#8217;</p>
<p>&#8211; List of Indexes on Perticular Table<br />
exec sp_helpindex &#8216;ps_client_master&#8217;</p>
<p>&#8211; Drop Index<br />
drop index ps_client_master.ps_client_master_Index_1</p>
<p>Using Cursors<br />
===============</p>
<p>DECLARE @ClientID char(11)</p>
<p>declare cl CURSOR FOR<br />
select int_id from ps_client_master</p>
<p>open cl</p>
<p>FETCH NEXT FROM cl into @ClientID<br />
while @@FETCH_STATUS = 0<br />
begin<br />
print @ClientID<br />
fetch next from cl into @ClientID<br />
end</p>
<p>close cl<br />
DEALLOCATE cl</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
