<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sql on Ravindra Devrani</title><link>https://ravindradevrani.com/tags/sql/</link><description>Recent content in Sql on Ravindra Devrani</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 09 Mar 2026 16:08:51 +0530</lastBuildDate><atom:link href="https://ravindradevrani.com/tags/sql/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Backup SQL Server Running in Docker on Linux</title><link>https://ravindradevrani.com/posts/sql_server_backup_in_docker_in_linux/</link><pubDate>Mon, 09 Mar 2026 16:08:51 +0530</pubDate><guid>https://ravindradevrani.com/posts/sql_server_backup_in_docker_in_linux/</guid><description>&lt;ul>
&lt;li>
&lt;p>I am using mssql server in docker container.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>I am using vscode extension named &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-mssql.mssql">SQL Server (mssql)&lt;/a> by &lt;strong>microsoft&lt;/strong>. This extension gives you the feature of creating and exporting the backup&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Connect to the database. It should look like this:
&lt;img src="https://ravindradevrani.com/images/mssql_vscode.jpg" alt="mssql vscode">&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Create a backup by using that extension.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://ravindradevrani.com/images/mssql_backup.jpg" alt="mssql backup">&lt;/p>
&lt;p>&lt;strong>Note:&lt;/strong> I have saved backup inside the folder &lt;code>/var/opt/mssql/data/&lt;/code>&lt;/p>
&lt;ul>
&lt;li>To find the exact name:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>docker exec &amp;lt;container_name&amp;gt; ls /var/opt/mssql/data/*.bak
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>Copy backup from docker to host machine:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>docker cp &amp;lt;container_name&amp;gt;:/var/opt/mssql/data/your_backup.bak ~/Documents/your_backup.bak
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>How to run Mysql in Docker?</title><link>https://ravindradevrani.com/posts/mysql-in-docker/</link><pubDate>Mon, 22 Dec 2025 18:31:32 +0530</pubDate><guid>https://ravindradevrani.com/posts/mysql-in-docker/</guid><description>&lt;p>Execute the command below.&lt;/p>
&lt;p>For bash:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sh" data-lang="sh">&lt;span style="display:flex;">&lt;span>docker run -d &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span> --name mysql-dev &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span> -p 3306:3306 &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span> -e MYSQL_ROOT_PASSWORD&lt;span style="color:#f92672">=&lt;/span>p@55w0rd &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span> -v mysql-data:/var/lib/mysql &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span> mysql:8.0.44-debian
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>For powershell:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ps1" data-lang="ps1">&lt;span style="display:flex;">&lt;span>docker run -d `
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --name mysql-dev `
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> -p &lt;span style="color:#ae81ff">3306&lt;/span>&lt;span style="color:#960050;background-color:#1e0010">:&lt;/span>&lt;span style="color:#ae81ff">3306&lt;/span> `
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> -e MYSQL_ROOT_PASSWORD=p@55w0rd `
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> -v mysql-data&lt;span style="color:#960050;background-color:#1e0010">:&lt;/span>/var/lib/mysql `
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> mysql&lt;span style="color:#960050;background-color:#1e0010">:&lt;/span>&lt;span style="color:#ae81ff">8.0&lt;/span>.&lt;span style="color:#ae81ff">44&lt;/span>-debian
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>📢 For mac silicon specific:&lt;/p>
&lt;p>&lt;code>mysql:8.0.44-debian&lt;/code> does not support ARM architectureUse &amp;ndash; so use &lt;code>mysql:latest&lt;/code> instead of &lt;code>mysql:8.0.44-debian&lt;/code> or check &lt;a href="https://hub.docker.com/">official docker hub&lt;/a> for suitable image.&lt;/p></description></item><item><title>How to run Sql Server 2025 in Docker</title><link>https://ravindradevrani.com/posts/sql-server-in-docker/</link><pubDate>Thu, 04 Dec 2025 11:00:49 +0530</pubDate><guid>https://ravindradevrani.com/posts/sql-server-in-docker/</guid><description>&lt;!-- raw HTML omitted -->
&lt;p>To be honest, since I have started using docker I have never installed any database in my machine. I use multiple databases and keeping each database up and running takes a toll on resources of your machine. And&amp;hellip; you can not install some database like &amp;ldquo;sql server&amp;rdquo; on &amp;ldquo;mac&amp;rdquo;, then docker is only option for you. Any way, I think it is enough introduction. Let&amp;rsquo;s get started.&lt;/p></description></item><item><title>How to run PostgreSql in Docker</title><link>https://ravindradevrani.com/posts/postgres-in-docker/</link><pubDate>Tue, 02 Dec 2025 11:02:49 +0530</pubDate><guid>https://ravindradevrani.com/posts/postgres-in-docker/</guid><description>&lt;!-- raw HTML omitted -->
&lt;p>To be honest, since I have started using docker I have never installed any database in my machine. I use multiple databases and keeping each database up and running takes a toll on resources of your machine. And&amp;hellip; you can not install some database like &amp;ldquo;sql server&amp;rdquo; on &amp;ldquo;mac&amp;rdquo;, then docker is only option for you. Any way, I think it is enough introduction. Let&amp;rsquo;s get started.&lt;/p></description></item><item><title>Inserting bulk records (1 million) in SQL Server</title><link>https://ravindradevrani.com/posts/bulk-insert-in-sql-server-with-recursive-cte/</link><pubDate>Wed, 19 Mar 2025 17:25:31 +0530</pubDate><guid>https://ravindradevrani.com/posts/bulk-insert-in-sql-server-with-recursive-cte/</guid><description>&lt;h2 id="creating-a-database">Creating a database&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sql" data-lang="sql">&lt;span style="display:flex;">&lt;span>USE master
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">DROP&lt;/span> &lt;span style="color:#66d9ef">DATABASE&lt;/span> &lt;span style="color:#66d9ef">IF&lt;/span> &lt;span style="color:#66d9ef">EXISTS&lt;/span> BookMillion
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">CREATE&lt;/span> &lt;span style="color:#66d9ef">DATABASE&lt;/span> BookMillion
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>USE [BookMillion]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">CREATE&lt;/span> &lt;span style="color:#66d9ef">TABLE&lt;/span> [dbo].[Book](
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Id] [int] &lt;span style="color:#66d9ef">IDENTITY&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>,&lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#66d9ef">NOT&lt;/span> &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Title] [nvarchar](&lt;span style="color:#ae81ff">100&lt;/span>) &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Author] [nvarchar](&lt;span style="color:#ae81ff">100&lt;/span>) &lt;span style="color:#66d9ef">NOT&lt;/span> &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Country] [nvarchar](&lt;span style="color:#ae81ff">100&lt;/span>) &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[ImageLink] [nvarchar](&lt;span style="color:#ae81ff">100&lt;/span>) &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[&lt;span style="color:#66d9ef">Language&lt;/span>] [nvarchar](&lt;span style="color:#ae81ff">20&lt;/span>) &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Link] [nvarchar](&lt;span style="color:#ae81ff">200&lt;/span>) &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Pages] [int] &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[&lt;span style="color:#66d9ef">Year&lt;/span>] [int] &lt;span style="color:#66d9ef">NULL&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	[Price] [int] &lt;span style="color:#66d9ef">NULL&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	&lt;span style="color:#66d9ef">CONSTRAINT&lt;/span> PK_Book_Id &lt;span style="color:#66d9ef">PRIMARY&lt;/span> &lt;span style="color:#66d9ef">KEY&lt;/span> (Id)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="bulk-insert-using-recursive-cte">Bulk insert using recursive cte&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sql" data-lang="sql">&lt;span style="display:flex;">&lt;span>USE [BookMillion]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">WITH&lt;/span> Numbers &lt;span style="color:#66d9ef">AS&lt;/span> (
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">SELECT&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span> &lt;span style="color:#66d9ef">AS&lt;/span> N
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">UNION&lt;/span> &lt;span style="color:#66d9ef">ALL&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">SELECT&lt;/span> N &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">FROM&lt;/span> Numbers
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">WHERE&lt;/span> N &lt;span style="color:#f92672">&amp;lt;&lt;/span> &lt;span style="color:#ae81ff">1000000&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">insert&lt;/span> &lt;span style="color:#66d9ef">into&lt;/span> Book (Title,Author,Country,[&lt;span style="color:#66d9ef">Language&lt;/span>],ImageLink,Link,Pages,Price,[&lt;span style="color:#66d9ef">Year&lt;/span>])
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">select&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#39;Book&amp;#39;&lt;/span>&lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#66d9ef">cast&lt;/span>(N &lt;span style="color:#66d9ef">as&lt;/span> varchar),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#39;Author&amp;#39;&lt;/span>&lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#66d9ef">cast&lt;/span>(N &lt;span style="color:#66d9ef">as&lt;/span> varchar),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#39;Country&amp;#39;&lt;/span>&lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#66d9ef">cast&lt;/span>(N &lt;span style="color:#66d9ef">as&lt;/span> varchar),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#39;Language&amp;#39;&lt;/span>&lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#66d9ef">cast&lt;/span>(N &lt;span style="color:#66d9ef">as&lt;/span> varchar),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#39;ImageLink&amp;#39;&lt;/span>&lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#66d9ef">cast&lt;/span>(N &lt;span style="color:#66d9ef">as&lt;/span> varchar),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#39;Link&amp;#39;&lt;/span>&lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#66d9ef">cast&lt;/span>(N &lt;span style="color:#66d9ef">as&lt;/span> varchar),
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">ABS&lt;/span>(CHECKSUM(NEWID())) &lt;span style="color:#f92672">%&lt;/span> &lt;span style="color:#ae81ff">901&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">100&lt;/span>, &lt;span style="color:#75715e">-- Pages between 100-1000
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">ABS&lt;/span>(CHECKSUM(NEWID())) &lt;span style="color:#f92672">%&lt;/span> &lt;span style="color:#ae81ff">901&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">100&lt;/span>, &lt;span style="color:#75715e">-- Price between 100-1000
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">ABS&lt;/span>(CHECKSUM(NEWID())) &lt;span style="color:#f92672">%&lt;/span> &lt;span style="color:#ae81ff">825&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">1200&lt;/span> &lt;span style="color:#75715e">-- Year between 1200-2024
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">from&lt;/span> Numbers
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">option&lt;/span> (maxrecursion &lt;span style="color:#ae81ff">0&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">GO&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Covering Indexes In Sql Server</title><link>https://ravindradevrani.com/posts/covering-indexes/</link><pubDate>Sat, 01 Mar 2025 15:20:01 +0530</pubDate><guid>https://ravindradevrani.com/posts/covering-indexes/</guid><description>&lt;h2 id="table-structure-and-total-records">Table structure and total records&lt;/h2>
&lt;p>Let&amp;rsquo;s look at our table structure as shown in the left panel of the picture&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;p>&lt;strong>Note:&lt;/strong> There is a &lt;code>non-clustered index&lt;/code> on the &lt;code>Title&lt;/code> column of the &lt;code>Book&lt;/code> table, which has a total of 1 million records.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sql" data-lang="sql">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">select&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Id,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Title,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Author,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Price
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">from&lt;/span> Book &lt;span style="color:#66d9ef">where&lt;/span> title&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#39;The Divine Comedy&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;img src="https://ravindradevrani.com/images/need_for_covering_index.jpg" alt="query_execution_plan">&lt;/p>
&lt;p>As you have noticed in the execution plan, there is a key lookup. Since index is only available for the &lt;code>Title&lt;/code> column, &lt;code>Title&lt;/code> is retrieved from the non-clustered index. However, other columns like &lt;code>Id&lt;/code>, &lt;code>Author&lt;/code> and &lt;code>Price&lt;/code> are not present in the non-clustered index, so they will be retrieved from the clustered index (the &lt;code>Book&lt;/code> table). This results in an additional &lt;code>key lookup&lt;/code> step and may decrease the performance. It&amp;rsquo;s like, you are looking for records in two places (non clustered index and clustered index).&lt;/p></description></item><item><title>What Makes My Query Non Sargable?</title><link>https://ravindradevrani.com/posts/what-makes-your-query-non-sargable/</link><pubDate>Mon, 24 Feb 2025 15:51:23 +0530</pubDate><guid>https://ravindradevrani.com/posts/what-makes-your-query-non-sargable/</guid><description>&lt;!-- raw HTML omitted -->
&lt;p>A query is &lt;strong>SARGable (Search ARGument able)&lt;/strong> if a database engine can take advantage of index.&lt;/p>
&lt;h2 id="what-makes-a-query-non-sargable">What makes a query non SARGable?&lt;/h2>
&lt;p>These are the few factors that makes a query non sargable.&lt;/p>
&lt;h3 id="1-put-a-column-inside-a-function-in-the-whereclause">1. Put a column inside a function in the where clause.&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sql" data-lang="sql">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">select&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> s.SalesOrderID,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> s.SalesPersonID,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> s.OrderDate,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> s.SalesOrderNumber
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">from&lt;/span> Sales.SalesOrderHeader s
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">where&lt;/span> &lt;span style="color:#66d9ef">YEAR&lt;/span>(s.OrderDate) &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">2011&lt;/span>; &lt;span style="color:#75715e">-- Row Retrieved: 1607 and Row read : 31465
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Note:&lt;/strong> I have created covering index on the &lt;code>OrderDate&lt;/code>:&lt;/p></description></item><item><title>SQL Server: Table Scan, Clustured Index Scan, Index Seek, RID Lookup, Key Lookup</title><link>https://ravindradevrani.com/posts/table-scan-index-scan-index-seek-rid-lookup-key-lookup/</link><pubDate>Mon, 24 Feb 2025 13:40:51 +0530</pubDate><guid>https://ravindradevrani.com/posts/table-scan-index-scan-index-seek-rid-lookup-key-lookup/</guid><description>&lt;!-- raw HTML omitted -->
&lt;p>Initially, it was not intended to be an article. I was tinkering around sql and documenting few things, then I thought, it could turnout to a nice article. I have wrote lots of article and created lots of videos on c#, .net core and angular. But it is my first article on the SQL.&lt;/p>
&lt;p>In this blog post, we are going to explore few terms of execution plan, like table scan, clustered index scan, index seek, RID lookup and key lookup.&lt;/p></description></item></channel></rss>