Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why don't you test your changing columns by using <code>IF UPDATE(Column1,Column2,...)</code> That will let you know whether any of the columns have changed that you're interested in. See <a href="http://msdn.microsoft.com/en-us/library/ms187326.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms187326.aspx</a> for details on the <code>UPDATE()</code> function.</p> <p>You'll also be able to use it if the PK has been modified, whereas comparing between the <code>inserted</code> and <code>deleted</code> the way you're trying to go about it will miss out on changes to the PK.</p> <p>The solution involving testing the inequality of all of the fields will fail unless you <code>SET ANSI_NULLS OFF</code> before comparing.</p> <p>For example:</p> <pre><code>create table table1 ( a varchar(4), b varchar(4) null) create table table2 ( a varchar(4), b varchar(4) null) go insert into table1 ( a, b ) select 'asdf', null insert into table2 ( a, b ) select 'asdf', 'zzzz' --Expect no results select * from table1 inner join table2 on a.a = b.a where a.b &lt;&gt; b.b set ansi_nulls off --Expect 1 result select * from table1 inner join table2 on a.a = b.a where a.b &lt;&gt; b.b </code></pre> <p>Of course, you could put in additional tests rather than going with the <code>ansi_nulls</code> option, but that gets particularly crazy if you're doing this with many fields. Also: you must <code>set ansi_nulls off</code> prior to creating the trigger - you can't turn it on and off inside the trigger, so the whole thing must have the same <code>ansi_nulls</code> setting.</p>
 

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