Trigger or Constraint??

  • Hi,

    I need to know the best practices while using Triggers and Constraints in SQL 2005.

    Problem: I have a table 'Employee' and i have to stop user to enter such employee again who have 'Type' is '1' already in our table.

    like if a record with type = 1 is already exists in employee table, it will stop the user to do so.

    Now i have two options to achieve this. one is 'Trigger' and other is 'Constraint'.

    please guide which is the best in a big DBs.

    Thanks,

    Noman

  • Constraints if possible, triggers only when the constraint can't be implemented. What you have there sounds like a standard unique constraint. If it's not, post more details.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks for prompt response..

    Its not like Unique Constraint...

    i want there is only one row with the Type = 3 and can not insert again with type = 3, but with type = 1 or type = 2 could be multiple in that table.

    Please guide.

    Thanks,

    Noman

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply