Re: Triggers and Flag bit
Erland Sommarskog wrote:
> Sharif Islam (mislam@spam.uiuc.edu) writes:
>> I have a perl script (uses sql query) that will run if there is any
>> update in the row. Currently, I am a trigger that sets the DateModified
>> field with getdate() Then my perl script looks for certain range of
>> modified dates and runs the necessary query.
>>
>> I am trying to come up with a different mechanism where I don't have to
>> use the date field. I am looking into flag bits. But not sure how
>> to use it.
>>
>> Should I create a trigger that will set the flag bit after any update?
>> This way the script will just look for the updated records, regardless
>> of what time it was updated. Maybe I am misunderstanding flag bits, then
>> after another subsequent update how would the perl/sql script know which
>> records were updated? I hope this make sense.
[...]
>
> Another alternative is to use a timestamp column. A timestamp column
> in SQL Server has nothing do with date and time, but is automatically
> updated each time a row is updated with a database-unique value that
> grows monotonically. Thus, the Perl script could look at the timestamp
> column and save the latest value as a high-water mark. This would at
> least save you the trigger.
Thanks, the timestamp solution seems feasible. I am little confused on
how to use it.
According to the documentation SELECT @@DBTS should return the records
that were just updated or modified. After some updated, when I ran the
select statement, I am getting all the rows. Is there anything else I
need to do? When I created the field I just assigned the data type,
didn't include any default vaule (using MSSQL 2005).
--s
|