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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:23:36+00:00 2026-05-31T10:23:36+00:00

When I use the following statement update INSERTED set … I get the following

  • 0

When I use the following statement

update INSERTED set ...

I get the following error:

The logical tables INSERTED and DELETED cannot be updated

This is the trigger code :

create trigger TCalcul
on dbo.Calcul
after insert 
  as
  begin
   set nocount on;
   declare @Num1 int;
   declare @Num2 int;
   declare @Op varchar(1);
   set @Num1 = (select Num1 from inserted)
   set @Num2 = (select Num2 from inserted)
   set @Op = (select Op from inserted)
   if @Op = '+'
    update inserted set Resultat = @Num1 + @Num2 
    else if @Op = '-'
     update inserted set Resultat = @Num1 - @Num2 ;
         else if @Op = '*'
         update inserted set Resultat = @Num1 * @Num2 ;
              else if @Op = '/'
              update inserted set Resultat = @Num1 / @Num2 ;
  end
go
  • 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-31T10:23:37+00:00Added an answer on May 31, 2026 at 10:23 am

    As the error says you cannot change inserted. Table Calcul will already contain rows submitted by insert at the moment trigger is called; therefore you operate directly on that data. As there is a possibility of inserting multiple rows at once, you should not work with local variables but work on a set:

    create trigger TCalcul
    on dbo.Calcul
    after insert 
    as
    begin
    
       set nocount on
    
       update Calcul 
              set Resultat = case Calcul.Op 
                                  when '+' then Calcul.Num1 + Calcul.Num2
                                  when '-' then Calcul.Num1 - Calcul.Num2
                                  when '*' then Calcul.Num1 * Calcul.Num2
                                  when '/' then Calcul.Num1 / Calcul.Num2
                                  else null end
             from Calcul inner join Inserted on Calcul.ID = Inserted.ID
    end
    go
    

    If you cannot use set for some reason then you should use cursor to step through inserted rows.

    Note: I’m assuming that Calcul has a primary key named ID; you will definately need one when dealing with triggers.

    EDIT:

    SET NOCOUNT ON instructs Sql Server not to return a message to client saying how many row were affected by an operation. It is often used in triggers to avoid sending information which would conflict with rowcount of original query (insert, update or delete which fired the trigger). It is best to put it at the beginning of every trigger as select will also return this message.

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

Sidebar

Related Questions

I use the following jquery statements but i get error in this function onGetDataSuccess(result)
I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET
I use the following statement prepared and bound in ODBC: SELECT (CASE profile WHEN
What should I use in the following statement? Include or required. if(a ==b){ require
My select statement in PHP is select * from table; I use the following
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
I use the following jquery statements, $(.resultsdiv:odd).css(background-color, #fff); $(.resultsdiv:even).css(background-color, #EFF1F1); $('.resultsdiv').hover(function() { $(this).css('background-color', '#f4f2f2');
I use the following jQuery statements and I am getting the error, jQuery.parseJSON is
I'm trying to use PostgreSQL's RETURNING clause on an UPDATE within in UPDATE statement,
I use the following statement to generate my primary key. table2 keeps the curent

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.