Sql-server – Logical problem with a database model

relational-theorysql server

Beforehand the table names and columns are in Spanish, my native language is Spanish.
(table names have been now edited to English)

I've got a database to manage the tickets sales of a trip that is made by a bus, the problem is that when I related the tables I didn't reason that when setting a trip to a bus the seats of this will be the amount of tickets of the trip, and for each trip this tickets will be different. Also the seat state has to change from available to unavailable when someone buys the ticket of that seat in each trip.

Here's the db model – only the tables involved in this problem :

enter image description here

EDIT: I renamed the table names to English language for be easy to read.

The only way that I imagine to do this is to create another table where I will insert the number tickets of a trip depending on the number of seats that a bus has, and when showing the available stalls in the app I'll set unavailable the seats of the bus where the number of seat is equal to the number of ticket that is already bought. But I don't feel this way leads to a normalized database.

Best Answer

You could reverse the relationship between passenger and ticket so that the ticket has a nullable FK to the passenger. When you create a new trip, create ticket entries for the number of passengers in the trip / seats on the bus. Then relate a passenger to each ticket as the ticket is sold. When a trip has no more tickets with an empty passenger id that trip is sold out.