1

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?

Praveen ND
  • 540
  • 2
  • 10
  • 1
    There is a truly [**ugly** way to do it](http://stackoverflow.com/questions/23510713/enforce-maximum-number-of-child-rows) but I'd generally advise against it. – Damien_The_Unbeliever Jun 17 '16 at 09:28

1 Answers1

2

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
  • Don't forget to include an `update` trigger to handle duplicates created as a result of name changes. – HABO Jun 17 '16 at 13:07