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. how to write insert querry for two tables

how to write insert querry for two tables

Scheduled Pinned Locked Moved Database
tutorial
2 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
    developerit
    wrote on last edited by
    #1

    i have to insert into two tables 1st table orders orderno int primary key autoincrement, username nvarchar(50) , shopname nvarchar(50), email nvarchar(100) 2nd table is Orderdetails serialno int primarykey autoincrement, orderno int foreignkey, categorynamee nvarchar(50), itemkey nvarchar(50), itemkeyname nvarchar(50), currentqty decimal, salesprice decimal, quantity int, total decimal can you give example which helps me

    A 1 Reply Last reply
    0
    • D developerit

      i have to insert into two tables 1st table orders orderno int primary key autoincrement, username nvarchar(50) , shopname nvarchar(50), email nvarchar(100) 2nd table is Orderdetails serialno int primarykey autoincrement, orderno int foreignkey, categorynamee nvarchar(50), itemkey nvarchar(50), itemkeyname nvarchar(50), currentqty decimal, salesprice decimal, quantity int, total decimal can you give example which helps me

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

      I am assuming you are using SQL 2005 or better. Firstly, you need to insert into the order table and get the order number by using scope_identity. Then use this to insert into the order details. The whole lot needs wrapping in a single transaction (clue - the bold words should be used for searching)

      Bob Ashfield Consultants Ltd

      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