Exists 和 Not Exists

 只注重子查询是否有返回行,如有返回结果为真,否则为假,并不适用子查询的结果,仅用于测试子查询是否有返回结果。

语法:

if exists (子查询)
        begin
            语句块
        end
    例子:
        if exists (select *from sysdatanases where name=’e_makcd’)
        begin
            drop database e_makcd
        end
        create database e_makcd
        (             )
        go

通常使用 not exists 子查询的结果取返值

exists : 查到为真否则为假

not exists : 查到为假,否则为真

原文地址:https://www.cnblogs.com/xiaowie/p/8675306.html