Question

I am working on a project related to ticket booking. I can store passenger data i.e. Name,Age,Sex along with Ticket ID in passenger table. But the problem is if another ticket is booked for same passenger I will have to re-enter the same passenger data & just the Ticket ID will differ.

mysql> desc passenger;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Name  | varchar(32) | NO   |     | NULL    |       |
| Age   | int(11)     | NO   |     | NULL    |       |
| sex   | char(1)     | NO   |     | NULL    |       |
| PNR   | varchar(32) | YES  | MUL | NULL    |       |
+-------+-------------+------+-----+---------+-------+

Can anyone Please tell me how can I minimize such redundancy?

Any link,reference,clue or idea will be appreciable. Thank you

Was it helpful?

Solution

You could store a passenger entity, consisting of name/age/sex etc. (in a passenger entity table) and then your passenger booking table would simply contain the passenger entity ids (integers, GUIDs etc.). This is a form of normalisation.

However this may be an optimisation too far. Whether you do this really depends on how many duplicate entities etc. you have, and whether they're a real performance/management issue for you. e.g. do you expect to store more data for passengers (addresses, frequent flyer info etc.).

OTHER TIPS

In a relational database like mysql, surely the passenget and ticket data should be in separate tables. So have a passenger table that contains personal details like Name, DateOfBirth, Address, Telephone etc and then have a ticket table that has ticketNumber, date etc as well as passengerId (classic many to one relationship).

The passenger parameters should belong to the passenger table. And the ticket parameters should belong to the ticket table.

The link between the passenger and the ticket is just a foreign key like "fk_passenger" linking with the id_passenger.

You may need to create a tables Users and Ticket details, where users table will store the details of users and Ticket_details will store the ticket details. Here user_id will be used as Foreign key in the ticket_details table (you can name this table according to your convenience)

 TABLE users
 +---------+-------------+------+-----+---------+---------------+
 | Field   | Type        | Null | Key | Default | Extra         |
 +-------+-------------+------+-----+---------+-----------------+
 | user_id | int(11)     | NO   | PK  |         | AutoIncrement |
 | name    | varchar(32) | NO   |     | NULL    |               |
 | age     | int(11)     | NO   |     | NULL    |               |
 | sex     | char(1)     | NO   |     | NULL    |               |
 +-------+-------------+------+-----+---------+-----------------+`


 TABLE ticket_details
 +---------+-------------+------+-----+---------+-----------------+
 | Field   | Type        | Null | Key | Default | Extra           |
 +-------+---------------+------+-----+---------+-----------------+
 | ticket_id | int(11)     | NO   | PK  |         | AutoIncrement |
 | user_id   | int(11)     | NO   | FK  |         |               |
 | PNR       | varchar(32) | NO   |     |         |               |
 +-------+-------------+------+-----+---------+-------------------+
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top