表名:unit(单位)
字段:id(主键),name(单位名称)
写一个sql语句实现如此啊功能:
   现在有个id=6,看下他存在(select id from unit)中不,存在返回true,不存在返回false

解决方案 »

  1.   

    create table tb([id] int, [name] varchar(10) , [age] int, [shid] int)
    insert into tb values(1 , 'aaa' , 12 , 77 )
    insert into tb values(2 , 'bbb' , 16 , 77 )
    insert into tb values(3 , 'cccc', 17 , 79 )
    insert into tb values(4 , 'dddd', 18 , 79 )
    goif exists (select 1 from tb where id = 6) 
       print '存在'
    else
       print '不存在' /*
    不存在
    */
    drop table tb