Simple trigger (I think)

  • Thread starter Thread starter Bill Le May
  • Start date Start date
B

Bill Le May

We are debugging a problem with an application that sporadically writes to
record 0 in a certain database table. So far we can't determine what
conditions cause it to write to this record, but we would like to alleviate
the problems it causes. I thought maybe a trigger would be a solution to
detect when Record 0 is being updated. The examples of triggers that I've
found don't cover cases where only a certain record is being updated.

My table name is Lienholder
The Primary key is LienholderID
The field that's being updated erroneously is Name

So, I want this trigger to fire when LienHolderID=0

I'm not sure what to put in /* */

Does the following look correct?


CREATE TRIGGER CheckZeroRecord ON [Lienholder]
FOR UPDATE
AS
IF (SELECT LienholderID FROM inserted) = 0
BEGIN
PRINT 'Cannot write to record 0'
PRINT 'Transaction has been cancelled'
ROLLBACK
END

Thanks,

Bill
 
Are you doing this in MS Access?
AFAIK, Access itself doesn't do triggers.

If you're using SQL Server, or some other database, I'd suggest posting in a
newsgroup dedicated to that product.

HTH
 
Back
Top