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

  • Home
  • SEARCH
  • 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 8887037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:42:26+00:00 2026-06-14T21:42:26+00:00

Possible Duplicate: How can I INSERT data into two tables simultaneously in SQL Server?

  • 0

Possible Duplicate:
How can I INSERT data into two tables simultaneously in SQL Server?

Doing a project for school so any help would be great thank you!

I have two tables – how do I insert into two tables? So both tables are linked.

First table is called Customer with primary key called CID that auto increments

CREATE TABLE [dbo].[Customer](
    [CID] [int] IDENTITY(1,1) NOT NULL,
    [LastName] [varchar](255) NOT NULL,
    [FirstName] [varchar](255) NOT NULL,
    [MiddleName] [varchar](255) NULL,
    [EmailAddress] [varchar](255) NOT NULL,
    [PhoneNumber] [varchar](12) NOT NULL        
 CONSTRAINT [PK__CInforma__C1F8DC5968DD69DC] PRIMARY KEY CLUSTERED 
(

And a second table called Employment that has a foreign key linked to the parent table

CREATE TABLE [dbo].[Employment](
    [EID] [int] IDENTITY(1,1) NOT NULL,
    [CID] [int] NOT NULL,
    [Employer] [varchar](255) NOT NULL, 
    [Occupation] [varchar](255) NOT NULL,
    [Income] [varchar](25) NOT NULL,
    [WPhone] [varchar](12) NOT NULL,
 CONSTRAINT [PK__Employme__C190170BC7827524] PRIMARY KEY CLUSTERED 
(
  • 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-14T21:42:27+00:00Added an answer on June 14, 2026 at 9:42 pm

    You need to do something like this:

    DECLARE @NewID INT
    
    INSERT INTO Customer(LastName,FirstName,......) VALUES(Value1, Value2, .....)
    
    SELECT @NewID = SCOPE_IDENTITY()
    
    INSERT INTO Employment(CID,Employer,.....) VALUES(@NewID, ValueA,..........)
    

    SCOPE_IDENTITY: Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.

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

Sidebar

Related Questions

Possible Duplicate: Unable to insert data into multiple wordpress tables According to the above
Possible Duplicate: Insert string between two points with PHP How can I replace everything
Possible Duplicate: It is possible to insert data in two different table in mysql
Possible Duplicate: SQL Server 2008 : Cannot Insert new column in the middle position
Possible Duplicate: mySQL - Insert into three tables I want to know if I
Possible Duplicate: Can we use any other TAG inside <ul> along with <li>? Or
Possible Duplicate: In Vim: How do I delete a word and go into insert
Possible Duplicate: PHP code can insert image to excel file and open it correctly
Possible Duplicate: How can I prevent SQL injection in PHP? This is the example
Possible Duplicate: How to get offline cookies data with php and insert it 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.