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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:45:45+00:00 2026-06-06T05:45:45+00:00

I want to check a Column value when update.If its match insert into another

  • 0

I want to check a Column value when update.If its match insert into another table.
My Tables:FirstTable

SecondTable

My trigger:

CREATE TRIGGER tr_test
ON test1
FOR UPDATE
AS
    SET nocount ON

    IF ( Update(sname) )
      DECLARE @Name NVARCHAR

    DECLARE @id INT

    SET @id=@@IDENTITY 
    SET @Name=(SELECT sname
               FROM   test1
               WHERE  id = @id)

    IF( @Name = 'Paras' )
      BEGIN
          INSERT INTO test2
                      (loginfo)
          VALUES     ('success')
      END  

And my update query is:

update Test1 set Sname='Paras' where ID=1

When I run this update query Nothing is happen.Test2 table is empty.I think problem is @@IDENTITY but not sure.Thanks.

  • 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-06T05:45:48+00:00Added an answer on June 6, 2026 at 5:45 am

    Try this:

    CREATE TRIGGER tr_test
    ON test1
    FOR UPDATE
    AS
        SET nocount ON
    
        IF ( Update(sname) )
          DECLARE @Name NVARCHAR
    
        DECLARE @id INT
    
        SET @id=(select id from inserted) 
        SET @Name=(SELECT sname
                   FROM   inserted
                   WHERE  id = @id)
    
        IF( @Name = 'Paras' )
          BEGIN
              INSERT INTO test2
                          (loginfo)
              VALUES     ('success')
          END  
    

    But it’s better to do this, an update can update many rows, the above will fail if UPDATE matches many rows, use EXISTS:

    CREATE TRIGGER tr_test
    ON test1
    FOR UPDATE
    AS
        SET nocount ON
    
        IF( EXISTS(select * From inserted where sname = 'Paras' ) )
          BEGIN
              INSERT INTO test2
                          (loginfo)
              VALUES     ('success')
          END  
    

    inserted table is the name of the table where the UPDATE’s new values goes, deleted table is the name of the table where UPDATE’s old values goes

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

Sidebar

Related Questions

Often I want to add a value to a table or update the value
I want to create a table that has a birthday date, this column shouldn't
Assuming I have a column called A and I want to check if A
I want add my custom sidebar next right column all page. Please check this
I don't want check if an item with a value exists in the arraylist,
I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table
I often want to do a quick check of the value of a large
i want to know how to find the column value change or not Example
I have new problem with query: I want to update column 'column' depending on
I have a gridview and on row update I want to check if the

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.