Sunday, 27 August 2017

If exists () in sql server

IF EXISTS condition in SQL Server (Transact-SQL) with syntax and examples. The SQL Server (Transact-SQL) EXISTS condition is used in combination with a sub query and is considered to be met if the sub query returns at least one row. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
The IF EXISTS () structure uses the presence of any rows returned from a SQL SELECT statement as a condition. Because it looks for any row, the SELECT statement should select all columns (*). This method is faster than checking an @@rowcount >0 condition because the total number of rows isn’t required.
Syntax of EXISTS ()

See the example
SELECT *
FROM Books
WHERE EXISTS
(SELECT * FROM Books_Audit );
See the output


No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts