22,207
社区成员
发帖
与我相关
我的任务
分享
-- =========================================
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb(id int ,b1 int ,b2 int )
go
insert into tb
select 1,2,3 union all
select 2,3,4
go
select * from tb
declare @c1 int ,@c2 int ,@id int
set @c1=3 set @c2=5 set @id=3
if not exists(select 1 from tb where b1=@c1 and b2=@c2)
begin
insert tb
values(@id,@c1,@c2)
end
else print '已有相同记录,拒绝插入@'
select * from tb
/*------------
1 2 3
2 3 4
1 2 3
2 3 4
3 3 5
-------*/
--换情况
select * from tb
declare @c1 int ,@c2 int ,@id int
set @c1=3 set @c2=4 set @id=3
if not exists(select 1 from tb where b1=@c1 and b2=@c2)
begin
insert tb
values(@id,@c1,@c2)
end
else
print '已有相同记录,拒绝插入@'
select * from tb
/*------------
1 2 3
2 3 4
1 2 3
2 3 4
-------*/
INSERT A
SELECT * FROM A1 t
WHERE NOT EXISTS (SELECT * FROM A WHERE B1=t.C1 AND B2=t.C2)
INSERT A
SELECT * FROM A1 t
WHERE EXISTS (SELECT * FROM A WHERE B1<>t.C1 AND B2<>t.C2)
insert into a
select * from a1
where not exists (
select 1
from a
where b1=a1.c1
and b2=a1.c2)
declare @a varchar(100),@a1 varchar(100)
set @a='a,s,d,s,e' set @a1='a,s,d,s,e'
if(select CHARINDEX(@a1,@a)>0)
begin
insert 表
values(@a1)
insert into a select * from a1 where checksum(c1,c2) not in(select checksum(b1,b2) from a)