Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can avoid the error message by wrapping your <code>UPDATE</code> in a TRY/CATCH block. This will also allow you to report errors that you do not want to suppress. For example, you may want to try this:</p> <pre><code>BEGIN TRY UPDATE ProductDemo SET ListPrice = 100.00 WHERE ProductID = 3 END TRY BEGIN CATCH IF ERROR_NUMBER() &lt;&gt; 3609 BEGIN DECLARE @errormessage nvarchar(500) DECLARE @errorstate INT DECLARE @errorseverity INT SET @errormessage = 'Error ' + CAST(error_number() AS nvarchar) + ': ' + error_message() SET @errorstate = error_state() SET @errorseverity = error_severity() RAISERROR (@errormessage, @errorseverity, @errorstate) END END CATCH </code></pre> <p>You do have another issue with the trigger. It doesn't anticipate the situation where multiple rows are updated with a single <code>UPDATE</code> statement. When you save columns from the <code>inserted</code> and <code>deleted</code> tables to variables, you will lose information from all rows except the last rows returned in the result set. You can avoid this situation by replacing your <code>SELECT</code>, <code>SET</code> and <code>INSERT</code> statements with a single <code>INSERT INTO... SELECT FROM</code> statement.</p> <pre><code>PRINT 'Can''t Change Price' INSERT INTO #UpdateLIstPrices SELECT 'Tried to update the price of ' + d.Name + ' [ProductID :' + CONVERT(VARCHAR(10), d.ProductId) + '] ' + ' from ' + CONVERT(VARCHAR(10), d.ListPrice) + ' to ' + CONVERT(VARCHAR(10), i.ListPrice) FROM inserted i INNER JOIN deleted d ON i.ProductID = d.ProductID </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload