0

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

Amit Kumar
  • 2,685
  • 2
  • 37
  • 72

4 Answers4

1

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.).

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

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).

Clinton Bosch
  • 2,497
  • 4
  • 32
  • 46
  • Thank you Clinton for your answer but the user and passenger are not same. A ticket can be booked for an unregistered user as well. – Amit Kumar Oct 07 '13 at 10:25
0

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.

zonzon
  • 168
  • 4
0

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   |     |         |               |
 +-------+-------------+------+-----+---------+-------------------+
plain jane
  • 1,009
  • 1
  • 8
  • 19