Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Can we pass parameters into trigerrs?

Can we pass parameters into trigerrs?

Scheduled Pinned Locked Moved Database
databasequestionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lavanya_satheesh
    wrote on last edited by
    #1

    I have written an update trigger. It is given below: CREATE TRIGGER Trg_OnUpdateJSComman ON [dbo].[JSComman] FOR UPDATE AS begin declare @uid bigint update JSCvs set LastUpdated=getdate() where (UID=@uid) end if any updates happen in the JSComman table this trigger will have to execute. but i need to pass the uid into the trigger for this to execute. is it possible to pass parameters into the trigger? Thanks in advance. Lavanya:)

    P 1 Reply Last reply
    0
    • L lavanya_satheesh

      I have written an update trigger. It is given below: CREATE TRIGGER Trg_OnUpdateJSComman ON [dbo].[JSComman] FOR UPDATE AS begin declare @uid bigint update JSCvs set LastUpdated=getdate() where (UID=@uid) end if any updates happen in the JSComman table this trigger will have to execute. but i need to pass the uid into the trigger for this to execute. is it possible to pass parameters into the trigger? Thanks in advance. Lavanya:)

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You shouldn't need to pass a parameter into a trigger. As a simplification, it has access to the INSERTED and DELETED tables, so you could write the above trigger as: UPDATE JSCvs SET LastUpdated = GETDATE() WHERE UID = (SELECT UID FROM INSERTED) Whenever you do an update, the tables INSERTED and DELETED store copies of the modification. Deleted stores the old version, and Inserted stores the updated version. I hope that helps.

      Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that." Deja View - the feeling that you've seen this post before.

      L 1 Reply Last reply
      0
      • P Pete OHanlon

        You shouldn't need to pass a parameter into a trigger. As a simplification, it has access to the INSERTED and DELETED tables, so you could write the above trigger as: UPDATE JSCvs SET LastUpdated = GETDATE() WHERE UID = (SELECT UID FROM INSERTED) Whenever you do an update, the tables INSERTED and DELETED store copies of the modification. Deleted stores the old version, and Inserted stores the updated version. I hope that helps.

        Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that." Deja View - the feeling that you've seen this post before.

        L Offline
        L Offline
        lavanya_satheesh
        wrote on last edited by
        #3

        Thank you. I solved the problem. :rose:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups