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. insert trigger

insert trigger

Scheduled Pinned Locked Moved Database
database
10 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.
  • M Offline
    M Offline
    Mr Kode
    wrote on last edited by
    #1

    i want to create a trigger to copy value inserted to another column on another table i have tried the following but failed. invoice_summary >> table to copy from Invoice_details >> table to copy to create trigger Insert_InvoiceNum on dbo.invoice_summary for insert AS begin insert into Invoice_details select Invoice_num from inserted go regards

    A A 2 Replies Last reply
    0
    • M Mr Kode

      i want to create a trigger to copy value inserted to another column on another table i have tried the following but failed. invoice_summary >> table to copy from Invoice_details >> table to copy to create trigger Insert_InvoiceNum on dbo.invoice_summary for insert AS begin insert into Invoice_details select Invoice_num from inserted go regards

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      How has it failed?

      Bob Ashfield Consultants Ltd

      M 1 Reply Last reply
      0
      • A Ashfield

        How has it failed?

        Bob Ashfield Consultants Ltd

        M Offline
        M Offline
        Mr Kode
        wrote on last edited by
        #3

        error Server: Msg 170, Level 15, State 1, Procedure Insert_InvoiceNum, Line 5 Line 5: Incorrect syntax near 'inserted'.

        A 1 Reply Last reply
        0
        • M Mr Kode

          error Server: Msg 170, Level 15, State 1, Procedure Insert_InvoiceNum, Line 5 Line 5: Incorrect syntax near 'inserted'.

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          I suspect your InvoiceDetails table has more than 1 column so you need to specify why column to insert the value to insert into Invoice_details**(Invoice_num)** select Invoice_num from inserted

          Bob Ashfield Consultants Ltd

          M 1 Reply Last reply
          0
          • A Ashfield

            I suspect your InvoiceDetails table has more than 1 column so you need to specify why column to insert the value to insert into Invoice_details**(Invoice_num)** select Invoice_num from inserted

            Bob Ashfield Consultants Ltd

            M Offline
            M Offline
            Mr Kode
            wrote on last edited by
            #5

            same error raised incorrect syntax near 'inserted'

            A 1 Reply Last reply
            0
            • M Mr Kode

              same error raised incorrect syntax near 'inserted'

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              can you post your table definitions? It might be a bit more obvious where the problem is.

              Bob Ashfield Consultants Ltd

              1 Reply Last reply
              0
              • M Mr Kode

                i want to create a trigger to copy value inserted to another column on another table i have tried the following but failed. invoice_summary >> table to copy from Invoice_details >> table to copy to create trigger Insert_InvoiceNum on dbo.invoice_summary for insert AS begin insert into Invoice_details select Invoice_num from inserted go regards

                A Offline
                A Offline
                Alsvha
                wrote on last edited by
                #7

                Try placing an end before the "go". Each time you have a BEGIN, you need an END.

                --------------------------- Blogging about SQL, Technology and many other things

                M A 2 Replies Last reply
                0
                • A Alsvha

                  Try placing an end before the "go". Each time you have a BEGIN, you need an END.

                  --------------------------- Blogging about SQL, Technology and many other things

                  M Offline
                  M Offline
                  Mr Kode
                  wrote on last edited by
                  #8

                  it succeeded but the insert value affected all rows i want it to affect 1 row only (new row) hers is trigger syntax create trigger InsertInvoice on dbo.Invoice_Summary for insert As begin insert into Invoice_details.Invoice_num select Invoice_num from Inserted end go example : insert into invoice_summary (P_name) values ('N1') results: the row insert to invoice_summary with Invoice_num 80 problem : all invoice numbers in the invoice_details(invoice_num) is 80 should 1 row only added with that value regards

                  1 Reply Last reply
                  0
                  • A Alsvha

                    Try placing an end before the "go". Each time you have a BEGIN, you need an END.

                    --------------------------- Blogging about SQL, Technology and many other things

                    A Offline
                    A Offline
                    Ashfield
                    wrote on last edited by
                    #9

                    Never overlook the obvious! Good spot.

                    Bob Ashfield Consultants Ltd

                    M 1 Reply Last reply
                    0
                    • A Ashfield

                      Never overlook the obvious! Good spot.

                      Bob Ashfield Consultants Ltd

                      M Offline
                      M Offline
                      Mr Kode
                      wrote on last edited by
                      #10

                      thanks .. but still have problem

                      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