SQL Server - IF EXISTS Statement
IF EXISTS is similar like IF condition.
In IF EXISTS we provide the select statement, if select statement return the row then IF EXISTS consider it as True and if select statement not return row then IF EXISTS consider it as False.
Below is the syntax of IF EXISTS.
Syntax for IF EXISTS
Consider the below result for example.
Check that if any student of 10th std. belong from Pune city or not using IF EXISTS in SQL server.
Note : When exactly use IF EXISTS statement in SQL Server?
Ans : It is similar like IF statement. We use IF EXISTS when we want to check row availability in table or need to check if any object is available in SQL Server or not.
We can also perform same action using IF condition but IF EXISTS remove the load of writing multiple lines.
Another practical example of IF EXISTS in SQL Server.
IF NOT EXISTS example, in below example we have to check that if Rajesh student is available in system then update city as 'Delhi' else insert new record.