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. Web Development
  3. ASP.NET
  4. insert query

insert query

Scheduled Pinned Locked Moved ASP.NET
questiondatabasecomtutorial
4 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.
  • R Offline
    R Offline
    Ramkumar_S
    wrote on last edited by
    #1

    Hi All, I have 2 table with Primary and foreign key constrains. where primary key is a identity column. if I insert any value in primary table..child table foreign key value should be inserted automatically.. Is there any way of using it with out triggers? how to do the same for delete? What is the traditional method...? Sorry if this is a very basic question!!!

    Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

    D 1 Reply Last reply
    0
    • R Ramkumar_S

      Hi All, I have 2 table with Primary and foreign key constrains. where primary key is a identity column. if I insert any value in primary table..child table foreign key value should be inserted automatically.. Is there any way of using it with out triggers? how to do the same for delete? What is the traditional method...? Sorry if this is a very basic question!!!

      Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      You could create a stored procedure to create both the parent and child record, then standardize on that for creating parent records in your application. Delete would be handled through a foreign key constraint with "cascade delete" option. This means that when the parent record is deleted, then all of the child records would be deleted.

      R 1 Reply Last reply
      0
      • D David Mujica

        You could create a stored procedure to create both the parent and child record, then standardize on that for creating parent records in your application. Delete would be handled through a foreign key constraint with "cascade delete" option. This means that when the parent record is deleted, then all of the child records would be deleted.

        R Offline
        R Offline
        Ramkumar_S
        wrote on last edited by
        #3

        Thanks for your time. Do u have any sample stored Procedure or Article related to Insert(with pk as identity column). goggled it..but could not find proper solution.

        Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

        P 1 Reply Last reply
        0
        • R Ramkumar_S

          Thanks for your time. Do u have any sample stored Procedure or Article related to Insert(with pk as identity column). goggled it..but could not find proper solution.

          Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com

          P Offline
          P Offline
          PunkIsNotDead
          wrote on last edited by
          #4

          Do you mean, like using SCOPE_IDENTITY()? It stores the last inserted primary key value in the current context

          DECLARE @Last_PK_Table1 AS INT
          INSERT INTO Table1(field1, field2) VALUES ('Field1', 'Field2')
          SET @Last_PK_Table1 = SCOPE_IDENTITY()
          INSERT INTO Table2(Table1_PK, OtherField, OtherField2) VALUES (@Last_PK_Table1, 'field1', 'field testing')

          thankx

          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