Posted By

pauliehaha on 08/04/09


Tagged


Versions (?)

Trigger to Update the OrderIndex of a specific id


 / Published in: SQL
 

  1. SET ANSI_NULLS ON
  2. GO
  3. SET QUOTED_IDENTIFIER ON
  4. GO
  5. CREATE TRIGGER dbo.Update_OrderIndex
  6. ON dbo.cmspage
  7. AFTER INSERT
  8. AS
  9. BEGIN
  10. SET NOCOUNT ON;
  11. DECLARE @Num int
  12. SET @Num = (SELECT MAX(OrderIndex) + 1
  13. FROM dbo.cmspage
  14. WHERE applicationid IN (
  15. SELECT applicationid FROM inserted
  16. ));
  17. UPDATE dbo.cmspage
  18. SET OrderIndex = @Num
  19. WHERE id IN (
  20. SELECT id FROM inserted
  21. );
  22. END
  23. GO

Report this snippet  

You need to login to post a comment.