Well this was not expected. The ADP seems to create an update statement only
for the columns that I change in teh front end form. BUT it always tries to
update TEXT column types regardless of whether or not they have changed!
So I'm confused now. I always thought that UPDATE(col1)... was testing for a
change in the value not just whether or not it was inlcuded in the update
statement. If that's the case, what's the point? It sure seems useless
otherwise. For example, I have a Delphi program running right now that has a
form with about 40 text boxes on it. It's unbound so I'm doing the update to
the table manually by passing the values on the form to a stored procedure.
I'm passing all values, not just the ones that have been changed. So in that
situation, if Col1 changed but Col2 did not and I still pass Col2 to the
procedure and there's a trigger that tests to see if Col2 was updated then
it will ALWAYS return true. It would seem that the only way to do this
exactly right would be to create the update statement dynamically depending
on what was changed. Otherwise the UPDATE function is useless. Am I way off
on this? Maybe I'm missing something here.
Keith
>I forget to use the profiler sometimes. That's a good suggestion. I'll
>check it out.
[quoted text clipped - 92 lines]
>>
>> John
>So I'm confused now. I always thought that UPDATE(col1)... was testing for a
>change in the value not just whether or not it was inlcuded in the update
>statement.
Hi Keith,
That would be impossible. Remember that a trigger fires once per
statement execution, not once per row affected. So if a single UPDATE
affects 5 rows, and one of the columns in the SET clause is really
changed for 2 of them and "changed" to its original value for the other
3, what would you expect IF UPDATE(...) to do for that column?
Basically, IF UPDATE(col) tests is a column is used in the SET clause.
> If that's the case, what's the point?
I have built several triggers where large parts of the code can be
skipped if I know that a column is not in the SET clause of the UPDATE
statement. If it is, I have to do various things (sometimes including
testing for "real" changes, sometimes not), but if it isn't I can skip
that becuase I know for sure that there were no changes to that column.
Another use is to test for columns that may never be changed, not even
by users with elevated privileges:
IF UPDATE(ImmutableColumn)
BEGIN;
Slap user;
ROLLBACK TRANSACTION;
RETURN;
END;

Signature
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Keith G Hicks - 30 Dec 2008 21:44 GMT
That makes sense. Thanks for the info.
>>So I'm confused now. I always thought that UPDATE(col1)... was testing for
>>a
[quoted text clipped - 27 lines]
> RETURN;
> END;