Jump to content

sql_learner

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by sql_learner

  1. sql_learner

    INSERT trigger

    Hello, I am trying to create an insert trigger for the first time and have some difficulty getting the trigger below to work. I am using MS SQL Server 2008 R2 I want to create an INSERT trigger that will prevent the adding of a row with a province that is not BC. Essentially if the province is BC the trigger should allow the update to happen, if the province is not BC the trigger should prevent the row from being added. I know I need to use the inserted virtual table, but I am not sure what I am doing wrong. Any help would be very appreciated, thanks! // code to testinsert Employeesvalues (10, 'Brown', 'Joe', '21 Jump Street', 'Vancouver', 'BC', 'V6R 5Z4', '6045555555','1981-07-23') insert Employeesvalues (11, 'Brown', 'Joe', '21 Jump Street', 'Vancouver', 'ON', 'V6R 5Z4', '6045555555','1981-07-23') go //INSERT TriggerCREATE TRIGGER tr_insert_employeeON Employeesfor insertasif (select province from inserted) <> 'BC' BEGINPRINT 'record will not update if province is not BC'ROLLBACK TRANSACTION END
×
×
  • Create New...