updating SQL2K with triggers

  • I am running SQL2K and am new to triggers. I have four fields in a table that are boolean fields. Only one of them can be true at a time. How would I write a trigger to insure this?

    Edited by - num1badz on 06/27/2002 11:02:57 AM

    Edited by - num1badz on 06/27/2002 11:03:35 AM

  • I'm not sure what data type you are using for you boolean fields, but you could setup something like this:

    create table test (b1 bit, b2 bit, b3 bit, b4 bit)

    go

    create trigger test_trigger on test

    for insert, update

    as

    if update(b1) or update(b2) or update(b3) or update(b4)

    begin

    if exists (select * from inserted where convert(int,b1) + convert(int,b2) + convert(int,b3) + convert(int,b4) > 1)

    rollback

    end

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply