当前位置: 代码迷 >> Sql Server >> 简单有关问题,关于insert如何判定插入重复
  详细解决方案

简单有关问题,关于insert如何判定插入重复

热度:73   发布时间:2016-04-27 21:29:45.0
简单问题,关于insert怎么判定插入重复。
现在写了一个存储过程,但是给别人操作的时候他们老搞出重复的数据,很麻烦。该怎么解决这个问题.

这个存储过程通过A表的条件引用B表向C表批量插入数据

一次插入数量估计有80条左右,现在想当插入的数据有规定的4个字段和已有数据相等时,放弃插入
这4个字段要同时条件满足~~

求大家帮忙

------解决方案--------------------
CREATE TABLE A
(
ID INT,
StartTime varchar(50)
)
go
create function dbo.fun(@col1 int,@col2 varchar(10))
returns int
as
begin
declare @cnt int
select @cnt = count(*) from A where [email protected] and [email protected]
return(@cnt)
end
go
alter table a add CONSTRAINT esd_check check(dbo.fun(ID,StartTime)=1)
go
INSERT INTO A
SELECT 1, '12:30 ' UNION ALL
SELECT 2, '13:50 ' UNION ALL
SELECT 3, '15:05 ' UNION ALL
SELECT 4, '15:40 '
go
  相关解决方案