IF EXISTS : Exists « Query « SQL Server / T-SQL Tutorial






3>
4> CREATE PROCEDURE spTableExists
5>  @TableName VarChar(128)
6> AS
7>  IF EXISTS(SELECT * FROM sysobjects WHERE name = @TableName)
8>  PRINT @TableName + ' exists'
9> GO
1>
2>
3> drop proc spTableExists;
4> GO
1>
2>








1.10.Exists
1.10.1.The syntax of a subquery that uses the EXISTS operator
1.10.2.EXISTS() returns a row in the outer query when any records are returned by a subquery.
1.10.3.A simple subquery using the EXISTS clause.
1.10.4.NOT EXISTS with correlated subquery
1.10.5.IF EXISTS
1.10.6.A common use for EXISTS is to answer a query such as Show me the titles for which no stores have sales.