Results 1 to 2 of 2

Thread: SQL Stored Procedure Programming (Insert Data)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    SQL Stored Procedure Programming (Insert Data)

    Hi Guys,

    Actually I'm just new in SQL Stored Procedure Programming, and just want to ask this kind of situation.

    I have a two table that I needed to populate in just one click of a button.
    Let's say I have Table1 and Table2. They are related to each other. But I need to populate first Table1 since it's primary id is a foreign key of Table2. Here is how I wrote it:

    Code:
    CREATE PROCEDURE dbo.prEntry
       @Var1 INT,
       @Var2 VARCHAR(255)
    AS
    BEGIN
      INSERT INTO tblTable1
      (
         Field11, 
         Field12
      )
      VALUES
      (
         @Var1,
         @Var2
      )
    
      'Question: What must be the next code to get the Primary Key of tblTable1, to be saved on tblTable2?
    
      INSERT INTO tblTable2
      (
         Field21,
         Field22,
      )
      VALUES
      (
         @Var1,
         @Var2 'Must be the primary key of tblTable1
      )
    Thank you guys for the help!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: SQL Stored Procedure Programming (Insert Data)

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width