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 Trigger

Create Trigger

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelp
5 Posts 3 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.
  • Z Offline
    Z Offline
    zafax_
    wrote on last edited by
    #1

    hi dearest brothers/sisters i have created trigger in MSSQL SERVER. CREATE TRIGGER IDx on Table2 after INSERT AS insert into Table2 (RefNo) select RefNo from Table1 i need Table2 Foreign key RefNo to be filled no of times which means eg. table2 may need RefNo to be filled in three rows. currently i get single row others kept NULL values help me plz thanks

    so much of happy ending...

    M M 2 Replies Last reply
    0
    • Z zafax_

      hi dearest brothers/sisters i have created trigger in MSSQL SERVER. CREATE TRIGGER IDx on Table2 after INSERT AS insert into Table2 (RefNo) select RefNo from Table1 i need Table2 Foreign key RefNo to be filled no of times which means eg. table2 may need RefNo to be filled in three rows. currently i get single row others kept NULL values help me plz thanks

      so much of happy ending...

      M Offline
      M Offline
      Mohsiul Haque
      wrote on last edited by
      #2

      try this Overview of SQL Server database Triggers[^]

      Z 1 Reply Last reply
      0
      • Z zafax_

        hi dearest brothers/sisters i have created trigger in MSSQL SERVER. CREATE TRIGGER IDx on Table2 after INSERT AS insert into Table2 (RefNo) select RefNo from Table1 i need Table2 Foreign key RefNo to be filled no of times which means eg. table2 may need RefNo to be filled in three rows. currently i get single row others kept NULL values help me plz thanks

        so much of happy ending...

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Triggers are EVIL. Although this is a valid use of a trigger I would suggest using a normal stored proc and surrounding the inserts with a transaction. Begin Tran insert parent record get scope_identity for the inserted record begin a loop insert the number of records in the child tables end the loop commit the transaction return the id to the calling method

        Never underestimate the power of human stupidity RAH

        Z 1 Reply Last reply
        0
        • M Mohsiul Haque

          try this Overview of SQL Server database Triggers[^]

          Z Offline
          Z Offline
          zafax_
          wrote on last edited by
          #4

          Thanks Mohsiul Haque . its really helpful and learned some.

          so much of happy ending...

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Triggers are EVIL. Although this is a valid use of a trigger I would suggest using a normal stored proc and surrounding the inserts with a transaction. Begin Tran insert parent record get scope_identity for the inserted record begin a loop insert the number of records in the child tables end the loop commit the transaction return the id to the calling method

            Never underestimate the power of human stupidity RAH

            Z Offline
            Z Offline
            zafax_
            wrote on last edited by
            #5

            Thanks to Mycroft Holmes . its really helpful !

            so much of happy ending...

            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