--如果存在 if exists(select 1 from A where A_1='XX') begin
end
楼上正解 --不存在 if not exists(select * from tableName) begin print 1 end
if exists(select 1 from t1 where id='2') print '不能添加'
if not exists(select * from tableName where colname=@name) begin insert into tab(..) select ... end
if not exists(select 1 from t1 where id=2) insert into t1 values(xx)
if not exists(select * from tableName where colname=@name) begin insert into tab(..) select ... end else print "can not add" end if
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
--如果存在
if exists(select 1 from A where A_1='XX')
begin
end
--不存在
if not exists(select * from tableName)
begin
print 1
end
if exists(select 1 from t1 where id='2')
print '不能添加'
begin
insert into tab(..) select ...
end
insert into t1 values(xx)
begin
insert into tab(..) select ...
end
else
print "can not add"
end if
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