I have a table Client. There are two columns Name and FathersName.

Now I need to check these two fields at the time of insert, the combination of these two fields shouldn't be repeated.

The possible solution was by creating the composite key or unique index which I've done already and the same thing wants to do using the trigger.

My Requirement:

Table: Client

After the inserting the row no. 3 the trigger should be worked and delete that record with the message "This record is already exist, can't add".

closed as unclear what you're asking by Tom V, hot2use, mustaccio, Md Haidar Ali Khan, LowlyDBA Oct 11 at 14:03

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Have you tried creating a unique index/constraint spanning these columns? Seems like this would solve the problem you are trying to prevent with a trigger – Mayberg Oct 11 at 5:52
  • Yes, I want to do with trigger and need help on it. Thank you! – user24769 Oct 11 at 5:58
  • these two fields shouldn't be repeated This phrase means these fields must be unique, and unique separately? or the pair only must be unique? refine... need help on it 1) Try and show results 2) Specify DBMS, including version. – Akina Oct 11 at 6:20
  • Thank you for your concern Akina and sorry about that phrase, actually I need the unique value of that pair and don't want to solve by creating the unique index. And want to solve with trigger and learn about it more. DBMS: Microsoft SQL Server 2014 - 12.0.4100.1 (X64) – user24769 Oct 11 at 6:27
  • A unique index (or constraint) is the better solution to ensure that values are not "repeated" – a_horse_with_no_name Oct 11 at 6:49