Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TRIGGER CheckDirection
- ON cars.RegistrationRecords
- AFTER INSERT
- AS
- BEGIN
- DECLARE @insertedRecordID int
- DECLARE @insertedAutoID int
- DECLARE @insertedDirection int
- SET @insertedRecordID = (SELECT TOP 1 RecordID
- FROM inserted
- ORDER BY RecordID DESC)
- SET @insertedAutoID = (SELECT TOP 1 AutoID
- FROM inserted
- ORDER BY RecordID DESC)
- SET @insertedDirection = (SELECT TOP 1 Direction
- FROM inserted
- ORDER BY RecordID DESC)
- DECLARE @lastCapturedAutoDirection int
- SET @lastCapturedAutoDirection = (SELECT TOP 1 Direction
- FROM cars.RegistrationRecords
- WHERE cars.RegistrationRecords.AutoID = @insertedAutoID and
- cars.RegistrationRecords.RecordID < @insertedRecordID
- ORDER BY RecordID DESC)
- IF @insertedDirection = @lastCapturedAutoDirection
- BEGIN
- PRINT 'Автомобиль не может несколько раз подряд въехать/выехать'
- ROLLBACK TRANSACTION
- END
- END
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement