ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Difference between IF EXISTS and IF NOT EXISTS in SQL Server<p>Hi&nbsp;chetan,</p> <p>Basically <strong>IF EXISTS</strong> returns true if the query return 1 or more rows.</p> <p><strong>IF NOT EXISTS</strong>&nbsp;returns false if the query return 1 or more rows.</p> <p>Both statements will return a boolean true/false result.</p> <p><strong>EXISTS</strong> returns true if the result set IS NOT empty.</p> <p><strong>NOT EXISTS</strong>&nbsp;returns true if the result set IS empty.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-Microsoft-Northwind-and-Pubs-Sample-databases-in-SQL-Server-Management-Studio.aspx" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">-- IF EXISTS IF EXISTS (SELECT * FROM Customers WHERE CustomerID =&#39;ALFKI&#39;) BEGIN SELECT &#39;Exist&#39; END ELSE BEGIN SELECT &#39;Not Exist&#39; END GO -- IF NOT EXISTS IF NOT EXISTS (SELECT * FROM Customers WHERE CustomerID =&#39;ALFKI&#39;) BEGIN SELECT &#39;Not Exist&#39; END ELSE BEGIN SELECT &#39;Exist&#39; END</pre> <p>In both the cases the output will be&nbsp;<strong>Exist</strong>.</p>https://www.aspforums.net:443/Threads/191256/Difference-between-IF-EXISTS-and-IF-NOT-EXISTS-in-SQL-Server/https://www.aspforums.net:443/Threads/191256/Difference-between-IF-EXISTS-and-IF-NOT-EXISTS-in-SQL-Server/Tue, 23 Jul 2019 01:06:22 GMT