if(object_id('testa','U') is not null)
drop table testa;
create table testa (
id int not null identity(1,1) primary key,
val varchar(200) not null
constraint testa$BPK_AK_Key unique nonclustered(val));
declare @v varchar(200)=newid();
if ((
select count(1) from testa where val=@v)=0)
insert into testa(val) select @v;
else
return
select count(1) from testa;
select top 10 * from testa;
truncate table testa;
declare @v varchar(200)=newid();
if ((
select count(1) from testa where val=@v)=0)
insert into testa(val) select @v;
else
return
declare @tb table (v varchar(200));
insert into @tb values
(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid());
select * from @tb;
if ((
select count(1) from testa where val=@v)=0)
insert into testa(val) select newid();
else
return