Re: prevent updates/deletes on certain rows

From: Narayana Vyas Kondreddi (answer_me_at_hotmail.com)
Date: 08/18/03


Date: Mon, 18 Aug 2003 17:14:06 +0100


Here's an example:

CREATE TRIGGER xy
ON test
FOR DELETE, UPDATE
AS
BEGIN
 IF EXISTS
 (
  SELECT 1
  FROM deleted
  WHERE lock = 1
 )
 BEGIN
  ROLLBACK
  RAISERROR('cannot update rows with lock = 1', 16, 1)
 END
END

-- 
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
What hardware is your SQL Server running on?
http://vyaskn.tripod.com/poll.htm
"Rafael Wittek" <Rafael.Wittek@avag.de> wrote in message
news:OJD$U%23ZZDHA.628@TK2MSFTNGP10.phx.gbl...
hi,
I want to implement a row-locking or row-write-protect mechnism, that
prevents certain rows of a table (e.g. that ones with lock (bit)=1) to be
modified or deleted.
I think the best way is to this by  triggers, but how ?
this one doesn´t work
create trigger xy on table test
for update, delete
if lock=1 then
rollback
Rafa


Relevant Pages

  • Re: how does trigger works?
    ... Improve your validation process and use a trigger. ... The suggestion that Daniel P makes is valid for sure. ... > Pro SQL Server 2000 Database Design ... >>> errors if a ROLLBACK is performed. ...
    (microsoft.public.sqlserver.programming)
  • Re: how does trigger works?
    ... Improve your validation process and use a trigger. ... The suggestion that Daniel P makes is valid for sure. ... > Pro SQL Server 2000 Database Design ... >>> errors if a ROLLBACK is performed. ...
    (microsoft.public.sqlserver.programming)
  • Re: trace lock:Released event
    ... Of course the objectid shows the table. ... And of course after the rollback there are 3 lock:released events. ... and that i can not imagine how to release the same lock twice. ... trying to monitor the SQL server lock mechanism. ...
    (microsoft.public.sqlserver.server)
  • Re: Help with Blocking
    ... It's hard to help you without seeing your trigger code. ... Columnist, SQL Server Professional ... process had acquired a Key type X lock on the table and that one of the ... updated and the trigger fires hundreds of times a day. ...
    (microsoft.public.sqlserver.programming)
  • Re: Records not inserting...
    ... > I am totally new to SQL server. ... However, in a trigger, would I be ... test the effects of certain data modifications and to set conditions for ... UPDATE statements. ...
    (microsoft.public.sqlserver.odbc)

Quantcast