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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:16:59+00:00 2026-06-17T11:16:59+00:00

I have a table let us say TableA . I have created a trigger

  • 0

I have a table let us say TableA. I have created a trigger which is fired on Insertion, Update or Deletion of record in TableA and inserts record in another table let us say TableB. Now where am I finding difficulty is from some of the stored procedures of TableA I am returning scope_identity() of inserted record. That must be returned from TableA's record while I am getting it from TableB. Is there any way to solve this issue? I want scope_identity() from TableA only, NOT from TableB. Awaiting for your valuable response.

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-06-17T11:17:01+00:00Added an answer on June 17, 2026 at 11:17 am

    SCOPE_IDENTITY() should work in that situation, it should be scoped to your stored proc and the insert to TableA, not the insert done in the trigger.

    CREATE TABLE [dbo].[TableA](
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [TestColumn] [nvarchar](50) NULL
    ) ON [PRIMARY]
    
    CREATE TABLE [dbo].[TableB](
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [TestColumn] [nvarchar](50) NULL
    ) ON [PRIMARY]
    
    CREATE TRIGGER [dbo].[TableA_AIDU]
       ON  [dbo].[TableA]
       AFTER INSERT,DELETE,UPDATE
    AS 
    BEGIN
        SET NOCOUNT ON;
        INSERT INTO TableB ( TestColumn )
        SELECT 'TableA Modified'
    END
    
    CREATE PROCEDURE [dbo].[sp_InsertToTableA]
        @ID INT OUTPUT  
    AS
    BEGIN
        SET NOCOUNT ON;
        INSERT TableA ( TestColumn )
        SELECT 'Insert from sp_InsertToTableA'
        SET @ID = SCOPE_IDENTITY()
    END
    

    The stored proc returns the ID from TableA, and the TableB insert is triggered as expected. Are you sure you’re not using @@IDENTITY instead of SCOPE_IDENTITY()?

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

Sidebar

Related Questions

Let's say I have a table called Users which represents registered users of a
Let's say I have a table TableA : parent_id int this_id int filter int
Let's say I have a table called Event which has a to-many relationship with
Let's say I have a dynamically-created table that is filled with data from a
Let's say we have the following table: CREATE TABLE T ( ID INT, String1
I have a simple table in Sybase, let's say it looks as follows: CREATE
I have a table let's say in the form of: match(id, hometeam_id, awayteam_id) and
I have two tables with similar columns - let's say table A with column
Let's say I have a table with a Color column. Color can have various
Let's say I have a table called messages with the columns: id | from_id

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.