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. Create Complex Trigers need help

Create Complex Trigers need help

Scheduled Pinned Locked Moved Database
help
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.
  • D Offline
    D Offline
    dadax_85
    wrote on last edited by
    #1

    I have three tables 1) AssignProjectUser(ProjectID,UserID) 2) Task(ID,ProjectID) 3) AssingnTaskUser(UserID,TaskID) I will create Trigers that after inserting a assignProjectUser I will select all the task who have the ProjectID inserted in AssignProjectUser and insert list of AssignTaskUser that have the userID same assignProjectUser and TaskID that i have selected Exemple: suppose that I have TASK: 1 1 2 1 3 2 when I insert a assignProjectUser (1,15) the number of task for this Project is 1 and 2 so the trigers will add (1,15) (2,15) I hope that you understand me and really need help as soon thanks DADAX

    E 1 Reply Last reply
    0
    • D dadax_85

      I have three tables 1) AssignProjectUser(ProjectID,UserID) 2) Task(ID,ProjectID) 3) AssingnTaskUser(UserID,TaskID) I will create Trigers that after inserting a assignProjectUser I will select all the task who have the ProjectID inserted in AssignProjectUser and insert list of AssignTaskUser that have the userID same assignProjectUser and TaskID that i have selected Exemple: suppose that I have TASK: 1 1 2 1 3 2 when I insert a assignProjectUser (1,15) the number of task for this Project is 1 and 2 so the trigers will add (1,15) (2,15) I hope that you understand me and really need help as soon thanks DADAX

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      CREATE TRIGGER trg_AssignProjectUser ON [dbo].[AssignProjectUser]
      FOR INSERT
      AS

      INSERT INTO AssignTaskUser (UserID,TaskID)
      SELECT inserted.userid,task.id
      FROM task INNER JOIN inserted on task.projectid = inserted.projectid

      ---------- There go my people. I must find out where they are going so I can lead them. - Alexander Ledru-Rollin

      D 1 Reply Last reply
      0
      • E Eric Dahlvang

        CREATE TRIGGER trg_AssignProjectUser ON [dbo].[AssignProjectUser]
        FOR INSERT
        AS

        INSERT INTO AssignTaskUser (UserID,TaskID)
        SELECT inserted.userid,task.id
        FROM task INNER JOIN inserted on task.projectid = inserted.projectid

        ---------- There go my people. I must find out where they are going so I can lead them. - Alexander Ledru-Rollin

        D Offline
        D Offline
        dadax_85
        wrote on last edited by
        #3

        thanks thanks DADAX

        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