Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Triggers
Message
From
10/12/2003 23:41:03
 
 
To
07/12/2003 10:38:01
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00856698
Message ID:
00857968
Views:
18
>Is there a way to determine if a table record has changed if that table does not have a datetime stamp? Right now I'm comparing the current table with a previous copy of the table to see if any data has changed.
>
>Can triggers do this instead? In other words, if a field is changed, can it trigger an update to a remote table that needs to be kept in sync? If so, what would that trigger look like?
>
>Thanks in advance.

Yes, absolutely.

Depending on the trigger that gets fired, tables are created that contain copies of the data before and after the change. You can query these tables and compare them to the actual values to determine at that point what to do.

The key to making this work is having properly-defined primary keys. By this, I mean that you can get to the record that was changed. For example, assume we have a table 'Customers' with a PK name of 'iCustomerKey'. Your update trigger would look like this:
declare @iCustomerKey int
select @iCustomerKey = iCustomerKey from inserted()

declare @cOldName char(30), @cNewName char(30)
select @cOldName = cCustomerName from inserted()
select @cNewName = cCustomerName from customer where iCustomerKey = @iCustomerKey

if @cOldName <> @cNewName
   { do your stuff }
Obviously this can be tedious to code, but I hope you get the idea. Duffy is right, if you need auditing capability you might check out his product.
Dan LeClair
www.cyberwombat.com
SET RANT ON - The Wombat Blog

Life isn’t a morality contest and purity makes a poor shield. - J. Peter Mulhern
Disclaimer: The comments made here are only my OPINIONS on various aspects of VFP, SQL Server, VS.NET, systems development, or life in general, and my OPINIONS should not be construed to be the authoritative word on any subject. No warranties or degrees of veracity are expressed or implied. Void where prohibited. Side effects may included dizziness, spontaneous combustion, or unexplainable cravings for dark beer. Wash with like colors only, serve immediately for best flavor.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform