I’m creating a page where I want users to be able to book a seat for an event.
- 1 user can only book 1 seat
- users have no seat selected upon login, first after buying into a spot
- Need to able to clear seats table, without loosing anything from user-table (except of course the assigned seats.)
I’ve created two tables, and since I’m pretty new to mySQL, I wanted to check if this was done correctly:
- members-table:
- user_id int(8) Not null auto_increment
- user_name varchar(30) Not null
- user_pass varchar(255) Not null
- seat_ID smallint(6) Yes NULL
- seats-table
- seat_ID smallint(6) No auto_increment
- user_id smallint(6) Yes NULL
- seat_status tinyint(4) Yes NULL
- seat_status tinyint(4) Yes NULL
I’ve created 2 FK-refs:
ALTER TABLE seats
ADD CONSTRAINT FK_seats
FOREIGN KEY (user_id) REFERENCES members(user_id)
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE seats
ADD CONSTRAINT FK_seats
FOREIGN KEY (seat_ID) REFERENCES members(seat_ID)
ON UPDATE CASCADE
ON DELETE CASCADE;
Am I on the right track? Will I be able to progress to a decent final product with this setup? suggestions/improvements? I don’t want to start all over in a couple of weeks because the database structure is of poor quality.
First of all I don’t see why you’re using a second table if any user can only hold one seat at any given time, secondly
user_idinseats-tableshould be the same size asuser_idin members table namelyint(8), otherwise you won’t be able to seat users after a while, third issue is the duplication of seat_status, I suppose that was a mistake or you had another name for it.In my opinion a better idea is to use a single table if it’s a 1->1 mapping and define it as
Clearing the seats with this config would be as simple as