Professional Web Applications Themes

prevent updates/deletes on certain rows - Microsoft SQL / MS SQL Server

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...

  1. #1

    Default prevent updates/deletes on certain rows

    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


    Rafael Guest

  2. #2

    Default Re: prevent updates/deletes on certain rows

    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" <de> wrote in message
    news:OJD$U%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



    Narayana Guest

  3. #3

    Default Re: prevent updates/deletes on certain rows

    Hi Vyas,

    it works ! thanks

    Rafa

    "Narayana Vyas Kondreddi" <com> schrieb im Newsbeitrag
    news:OKQ$phx.gbl... 


    Rafael Guest

Similar Threads

  1. Bulk Updates to Rows on gridview won't work as specified?
    By BenG in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: August 18th, 03:20 AM
  2. I want to prevent accidental updates to records
    By Michael Fine in forum Microsoft Access
    Replies: 2
    Last Post: July 17th, 03:32 PM
  3. Replies: 3
    Last Post: July 9th, 12:41 PM
  4. How to optimise many updates on 1Mio rows?
    By George in forum Microsoft SQL / MS SQL Server
    Replies: 8
    Last Post: July 1st, 04:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139