Praveen ND
Praveen ND

Reputation: 560

How can I restrict a column to have only a fixed number of duplicate values

Lets say I have a table tblPerson with below values. And In Name field I don't want the names to get repeated more than 2 times.

ID  Name
1   JOHN HONAY
2   PETER CAM
3   JOHN HONAY

So If I try to insert a new row in tblPerson with Name as "JOHN HONAY". It should throw error. How can I achieve this. Can I do something during the creation of table itself?

Upvotes: 1

Views: 157

Answers (1)

Abdelrahman M. Allam
Abdelrahman M. Allam

Reputation: 922

I think of

  • On insert/ on update Triggers to check how many times the value is exists in database
  • Make your BL (Business logic) check for the duplicate

Upvotes: 2

Related Questions