Advertisement
Guest User

Untitled

a guest
Mar 13th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. begin transaction
  2. set nocount on
  3.  
  4. CREATE TABLE joinreason (jrid int, jr_active char(1), jr_par_jrid int)
  5. INSERT joinreason VALUES (1, 'Y', null)
  6. INSERT joinreason VALUES (2, 'Y', 1)
  7. INSERT joinreason VALUES (3, 'Y', null)
  8. go
  9. CREATE TRIGGER [dbo].[trgInsertUpdate]
  10. ON [dbo].[joinreason]
  11. AFTER INSERT, UPDATE
  12. AS
  13. BEGIN
  14. IF UPDATE(jr_active)
  15. BEGIN
  16. UPDATE joinreason
  17. SET jr_active = 'N'
  18. FROM joinreason j
  19. JOIN inserted i ON i.jrid = j.jr_par_jrid
  20. JOIN deleted d ON i.jrid = d.jrid
  21. WHERE d.jr_active = 'Y' AND i.jr_active = 'N'
  22. END
  23. END
  24. go
  25. select * from joinreason
  26. update joinreason set jr_active = 'N' where jrid = 1
  27. select * from joinreason
  28.  
  29. rollback transaction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement