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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:09:35+00:00 2026-05-27T01:09:35+00:00

I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.

  • 0

I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.

After inserting a record in the child table (Table_B) I want to use a trigger to grab a value from a field in the parent table (Table_A) and update the currently inserted record in Table_B.

Table_A

PK|EmpID|MemID|Firstname|Lastname
----------------------------------
1 |1234 |AB123|John     | Doe
2 |5678 |CD456|Jane     | Smith

Table_B

PK|EmpID|MemID|Description
---------------------
1 |1234 |NULL |Finance
2 |1234 |NULL |IT
3 |5678 |NULL |Finance 
4 |5678 |NULL |Management

The trigger should grab the MemID value from Table_A and update it’s corresponding value in Table_B where [Table_A].[EmpID] = [Table_B].[EmpID]. Of course after 4 inserts in Table_B the results should be as follows:

PK|EmpID|MemID|Description
---------------------
1 |1234 |AB123|Finance
2 |1234 |AB123|IT
3 |5678 |CD456|Finance 
4 |5678 |CD456|Management

I extensively searched other technical sites but can’t seem to find one with this particular scenario. As a desperate move I have registered into this site and this would be my 1st post for help.

The following is my futile attempt at trying to create my 1st trigger in MS SQL Server 2008 R2.

CREATE TRIGGER dbo.trgInsMemID
ON dbo.Table_B
AFTER INSERT
AS
    BEGIN
        UPDATE dbo.Table_B
            SET MemID = 
                (SELECT MemID 
                FROM inserted i 
                JOIN dbo.Table_A c ON c.EmpID = i.EmpID)
            FROM dbo.Table_B b
            JOIN inserted i ON i.MemID = b.MemID
    END
  • 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-27T01:09:36+00:00Added an answer on May 27, 2026 at 1:09 am

    I believe you’ll want your update statement changed to look like this:

    UPDATE b
    SET b.MemId = a.MemId
    FROM dbo.Table_B AS b
    INNER JOIN Inserted AS i ON b.EmpId = i.EmpId
    INNER JOIN dbo.Table_A AS a ON b.EmpId = a.EmpId
    

    This will update only the records in b that were also in the insterted table. (first INNER JOIN)

    It will then INNER JOIN into Table_A on EmpId to pull the proper MemId to update your records with.

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

Sidebar

Related Questions

I have two tables with a many-to-one relationship. (Oracle) **Table: PARENT** Field: A (PK)
I have two tables A & B, and B has a many:1 relationship with
I have two tables that are joined together. A has many B Normally you
I have two tables, each one has a primary ID column as key. I
I have two rows from a table that has many columns. How do I
Suppose I have two tables A and B and each one has only 1
My question is: I have two tables: table A has two columns (KeyA and
I have a table y Which has two columns a and b Entries are:
I have two tables, for example: Table A Table B ======= ======= Name |
I have two tables A and B as defined bellow. create table A (

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.