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 7190437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:30:57+00:00 2026-05-28T19:30:57+00:00

This question is very similar to the question asked here so I hope this

  • 0

This question is very similar to the question asked here so I hope this isn’t too redundant.

I am new to T-SQL and I am trying to understand if there is a different/better approach to inserting records into two tables.

For example I have a form with name and address, in my DB this is represented with two tables ( client and address) on the most basic level if I wanted to insert the following:

Name fields (first, middle last age) to name table and address (street number, street name, city, state, zip) to address table with name being the primary table could someone point me in the right direction as to the best way to do this in SQL Server / T-sql? Or would it be the same as within MySQL syntax by inserting the person first and then selecting the last inserted user getting the id and then adding the address and id (as the fk) to the address table?

I’d also appreciate any links or additional reading on the best approach.

Cheers (and thanks in advance)

  • 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-05-28T19:30:59+00:00Added an answer on May 28, 2026 at 7:30 pm

    You need to do two inserts. After you do the first insert into the client table use @@identity to get the ID of the inserted record.

    INSERT INTO client VALUES ('Peter', 'Griffin')
    
    SET @clientKey = @@IDENTITY
    
    INSERT INTO address VALUES (@clientKey, '123 Elm')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Liu Chang asked a very similar question to this one here, Linux equivalent of
This question is very similar to SQL Server 2005: T-SQL to temporarily disable a
This is very similar to a question I asked the other day but my
I've asked a very similar question before for a video renderer filter. See here:
This is very similar to a question I asked the other day but my
This is a follow up to a very similar question I have already asked
I'm afraid very similar question has been asked already here , but for some
There was a similar question asked here three years ago, but I want to
This question is very similar to one I recently asked: Python threading- returning control
This is very similar to this question I asked earlier. I am hoping to

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.