比如我有一个表A  字段有A_1,就把他看成只有一个字段把
我现在要添加一行数据,xx
如何判断表A中存在同样的数据

解决方案 »

  1.   


    --如果存在
    if exists(select 1 from A where A_1='XX')
    begin
           
    end
      

  2.   

    楼上正解
    --不存在
    if not exists(select * from tableName)
    begin
    print 1
    end
      

  3.   


    if exists(select 1 from t1 where id='2')
       print '不能添加'
      

  4.   

    if   not   exists(select   *   from   tableName where colname=@name) 
    begin 
    insert into tab(..) select ... 
    end
      

  5.   

    if not exists(select 1 from t1 where id=2) 
        insert into t1 values(xx)
      

  6.   

    if   not   exists(select   *   from   tableName where colname=@name) 
    begin 
    insert into tab(..) select ... 
    end
    else
    print "can not add"
    end if
      

  7.   

    declare @name char
    if       not       exists(select       *       from       tableName   where   colname=@name)   
    begin   
    insert   into   tab(a1)   select  id from a
    end 
    else 
     begin
    print  'can not add'
    end