473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Triggers and Flag bit

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.

thanks.

--s
Mar 24 '08 #1
3 4256
Sharif Islam (mi****@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.
There are a couple of alternatives. Which version of SQL Server are you
using? If you use SQL 2005, Query Notification is an interesting
alternative. Your Perl script would issue a query, and then wait until
the result set changes. Of course, this presumes that you use an API
that supports Query Notification, but Win32::SqlServer, available from
my web site on http://www.sommarskog.se/mssqlperl/index.html does.

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.

I don't believe in flag bits. In this case, the Perl script would have
to flip them back, and that's more complex.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 24 '08 #2
>I am trying to come up with a different mechanism where I don't have to use the date field [sic: columns are not fields]. I am looking into flag bits. <<

All that will do is destroy data you have collected. Just use the
date.
Mar 25 '08 #3
Erland Sommarskog wrote:
Sharif Islam (mi****@spam.uiuc.edu) writes:
>Thanks, the timestamp solution seems feasible. I am little confused on
how to use it.
>
Rather than using @@DBTS, min_active_rowversion() is a better choice.
This function was added in SP2, and it was added to Books Online as late
in the September 2007 edition (see my signature for download link). Looking
at @@dbts can cause some issues when there are uncommitted transaction.
Thanks for the help. Here's how I am using it. I created a column 'Flag'
with timestamp datatype.

------

declare @before timestamp
declare @after timestamp
set @before= min_active_rowversion() -1
update MyTable set MyCol ='Test' where MyCol like 'Test123%'
set @after = min_active_rowversion() -1

select ID,MyCol from MyCol where Flag -1 < @after
and Flag -1 >= @before
-----
This gave me the list of record ID that was just changed. Is this the
way to use min_active_rowversion()?

--s
Mar 28 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jonathan Bishop | last post by:
Hi. We are using MSDE2000 on a Point of Sale application. We need to keep a copy of a few key tables as up to date as possible for backup purposes. We are looking at using triggers over the...
4
by: Mark Flippin | last post by:
I'm just starting to use triggers in my databases and find the support in Enterpise Manager lacking. Using Enterprise Manager and Query Analyzer you can maintain the triggers, but it's...
1
by: tim.pascoe | last post by:
I'm trying to generate scrips for a database, and everything so far has worked fine, except for the triggers. When I try and script existing triggers, all I get is a blank file - no SQL script. I...
4
by: stacdab | last post by:
We have a partitioned view with 4 underlying tables. The view and each of the underlying tables are in seperate databases on the same server. Inserts and deletes on the view work fine. We then...
5
by: Bruce | last post by:
I have several user defined functions which are referenced in triggers and views. For software upgrades, I need to be able to drop the triggers and views which reference these user defined...
0
debasisdas
by: debasisdas | last post by:
trigger sample code Ex#10 ======================= INSTEAD OF TRIGGER ---------------------------------------- create or replace trigger mytrig instead of delete or insert or update on eview...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips/sample codes regarding TRIGGERS in oracle, that the forum members may find useful. TRIGGERS: =============== Database trigger is a PL/SQL block that is...
1
by: khyati30 | last post by:
hello Everyone, My problem is for triggers in mysql i will give u an example of that:, what i have made & problem is occured my trigger is like this;DELIMITER | CREATE TRIGGER testcdr BEFORE...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.