sql server 2008 multiple inserts over 2 tables

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-27T18:40:52Z Indexed on 2010/04/27 18:43 UTC
Read the original article Hit count: 257

I got the following trigger on my sql server 2008 database

CREATE TRIGGER tr_check_stoelen
ON Passenger
AFTER INSERT, UPDATE
AS
BEGIN
        IF EXISTS(
                SELECT 1
                FROM Passenger p 
                INNER JOIN Inserted i on i.flight= p.flight
                WHERE p.flight= i.flightAND p.seat= i.seat
             )
        BEGIN
            RAISERROR('Seat taken!',16,1)
            ROLLBACK TRAN   
        END
END

The trigger is throwing errors when i try to run the query below. This query i supposed to insert two different passengers in a database on two different flights. I'm sure both seats aren't taken, but i can't figure out why the trigger is giving me the error. Does it have to do something with correlation?

INSERT INTO passagier VALUES 
(13392,5315,3,'Janssen Z','2A','October 30, 2006 10:43','M'),
(13333,5316,2,'Janssen Q','2A','October 30, 2006 11:51','V')

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008