sql server - Trigger in SQL to count a column and give a error if it is more than a specific value -


I need a trigger to avoid putting a specific value for the column, for example, in the booking table I have Booking is an ID and invoice id I want to count the booking ID for each invoice and compare the numbers in the airline table, which is called MaxBooking. If the number was higher than MaxBooking, it means that I can not book with that invoice number now

  | Booking id | Invoice id Traveler iid Flight ID | | | 1 | 101 | 20 | 99 | | 1 | 101 | 20 | 99 | | 1 | 101 | 20 | 99 | | 1 | 101 | 20 | 99 | | Flight Id | Airline id | | 99 | 500 | Airline ID | Airline-name | MaxBooking | | 500 Birtish Airway | 4 |    

This is the right solution, you are searching for

I have accepted the names of the table:
1. dbo.fllightbookings
2.dbo.Flights
3.dbo.Airlines
According to their appearance in their question

  Create Triggers [DBO]. [Trg_restrictMaxBooking] ON [dbo]. [Flightbearing] Start as the starting of INSERT; BEGIN transfer notification @ flight iid is selected @fliteaid = iFlightId I is included with IF ((SELECT COUNT (*) to dbo.FlightBookings where flight id = @ flight ID) & lt; ISNULL ((SELECT MAXBOING FROM) Dbo.Airlines WHERE AirlineId = (SELECT AirLineId FROM dbo.Flights WHERE FlightId = @ FlightId)), 0)) Rollback Transaction Rezer ('Failed', 16,1) Go Back Command Transmission Go After   

Do you need any further help or I'm missing something, please tell me.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -