Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:37:17+00:00 2026-06-13T09:37:17+00:00

I am creating stored procedures that will be called from my C# application and

  • 0

I am creating stored procedures that will be called from my C# application and will enter master/detail information into SQL Server. On the Header table I have TransactionId as an Identity column so that I get a unique ID every time I insert. When I call my stored procedure for the detail table, I would like to use the PK ID from the Header and insert it into the FK of the detail. What is the best way to ensure that I get back the ID that was just created in the Header table?

CREATE TABLE [dbo].[Header835]
(
   [TRANSACTIONID] [int] IDENTITY(1, 1) NOT NULL
   , [FILENAME] [varchar](80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
   , [TRADINGPARTNERNAME] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
   , [ISACRTL] [numeric](18, 0) NOT NULL
   , [STCRTL] [numeric](18, 0) NOT NULL
   , CONSTRAINT [PK_Header835] PRIMARY KEY CLUSTERED
   (
      [TRANSACTIONID] ASC
   ) WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:37:18+00:00Added an answer on June 13, 2026 at 9:37 am

    You’ll wan to use SCOPE_IDENTITY()

    DECLARE @headerTransactionId INT;
    
    INSERT INTO dbo.Header835(Filename, TradingPartnerName, IsACrtl, StCrtl)
    SELECT 'myFile.txt', 'Joe', 103, 123;
    
    SELECT @headerTransactionId = SCOPE_IDENTITY();    
    

    SQL Fiddle Example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating stored procedures for inserting and updating data in my SQL Server
I'm creating a stored procedure that will create 3 triggers (insert, update, delete) given
I am creating a stored procedure that will take in one parameter: @CommonImportID This
I am using SQL Server 2005. I want to create a stored procedure that
I have a stored procedure for SQL Server 2000 that can only have a
I am making the transition from DataTableAdapters in MSVS to creating Stored Procedures in
I am creating a ASP.NET application that is pretty much self contained, it will
Okay basically I am creating a stored procedure that will return data for our
I'm finding that there are several points in the stored procedures that I'm creating
I am new to creating stored procedures and I saw this sql below in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.