这个要在插入前就要作检查,写一个存储过程吧
create procedure [dbo].[checkRepetition]
@InsValue varchar(6),@getvalue int output
as
if exists(select 数值 from tablename where 类型=@InsValues)
begin
select top 1 @getvalue=数值 from tablename where 类型=@InsValues order by 数值 DESC
set @getvalue=@getvalue+1
end
else
set @getvalue=1
return @getvalue
Insert TableName Select * From
( Select 'D' As ID,3 As Name
Union All Select 'D' ,4 ) A
Where Not Exists (Select * From TableName Where 类型='A' And 值 In (3,4))
Insert TableName Select * From
( Select 'D' As 类型,3 As 值
Union All Select 'D' ,4 ) A
Where Not Exists (Select * From TableName Where 类型='D' And 值 In (3,4))
Insert TableName Select * From
( Select 'D' As ID,3 As Name
Union All Select 'D' ,4 ) A
Where Not Exists (Select * From TableName Where 类型='D' And 值 In (3,4))