How to avoid Duplicate values for INSERT in SQL?

前端 未结 6 632

I have one table named:

Delegates

This table has four fields:

ID(Auto increment, Primary)
MemberNo, FromYr, ToYr
         


        
6条回答
  •  执念已碎
    2020-11-27 08:17

    Before inserting check if there is a record with the same values:

    if not exists (select * from Delegates d where d.FromYr = @FromYr and d.MemNo = @MemNo)
        INSERT INTO Delegates ([MemNo],[FromYr],[ToYr]) values(@MemNo, @FromYr,@ToYr)
    

提交回复
热议问题