The PetrolPump Management System enforces a fully normalised relational model through twelve explicit foreign key constraints defined inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Adarsh275/PetrolPump-Management-System/llms.txt
Use this file to discover all available pages before exploring further.
Backend/relation.sql. These constraints ensure that no orphaned records can exist — an employee cannot reference a non-existent pump, an invoice cannot reference a non-existent customer, and so on. Indexes are added on all foreign key columns before the constraints themselves are declared, which improves join performance and satisfies InnoDB’s requirement that referenced columns be indexed. Together, the constraints form a tightly coupled graph of six primary entities connected by four join tables.
Complete relation.sql
Constraint Explanations
Owns — PetrolPump ↔ Owners (many-to-many)
Owns_ibfk_1 and Owns_ibfk_2 together enforce that every row in the Owns join table must reference a valid pump registration number and a valid owner name. This is the only purely many-to-many relationship in the schema: a single pump (e.g. HPC805103) can have multiple partners (Pawan Kumar, Avinash Shankar, Vikash Kumar Tarun), and a single owner can hold stakes in more than one pump.
The
Owns relationship is the only many-to-many join in the database. It uses both Registration_No and Owner_Name as a composite primary key, preventing the same owner from being recorded twice for the same pump.Tanker.Petrolpump_No → PetrolPump.Registration_No
Tanker_ibfk_1 ensures every tanker record is associated with a real pump outlet. A tanker belongs to exactly one pump — you cannot insert a tanker row with a Petrolpump_No that does not already exist in PetrolPump. The column is nullable, so tankers that have not yet been assigned to a pump can still be stored.
Employee.Petrolpump_No → PetrolPump.Registration_No
Employee_ibfk_1 enforces that every employee must be attached to a real, registered petrol pump. Like tankers, the column is nullable to allow for employees who are temporarily unassigned.
Employee.Manager_ID → Employee.Employee_ID (self-referential hierarchy)
Employee_ibfk_2 is a self-join on the Employee table. Every Manager_ID value must correspond to a valid Employee_ID in the same table. This models the organisational hierarchy: nozzle persons report to managers, managers may reference themselves as their own manager. Employees with no manager have NULL in this column.
Invoice.Date → Sales.Date
Invoice_ibfk_1 ties every invoice to a date on which a sales shift actually occurred. Because Date is part of the composite primary key on Sales, this constraint guarantees that no invoice can be generated for a day with no recorded nozzle activity.
Invoice.Customer_Code → Customer.Customer_Code
Invoice_ibfk_2 links each invoice to a registered customer. The column is nullable, accommodating walk-in or anonymous purchases that should still be recorded.
Sales.Petrolpump_No → PetrolPump.Registration_No
Sales_ibfk_1 ensures that every daily sales record belongs to a valid pump. This constraint is what makes cross-pump revenue reporting possible — sales can always be traced back to a specific outlet.
Contacts — Employee phone numbers (multi-valued attribute)
Contacts_ibfk_1 ensures that every phone number row in Contacts references a valid employee. This table exists because an employee can have more than one contact number; normalisation requires pulling repeated groups into a separate table rather than adding multiple phone columns to Employee.
Serves — Employee ↔ Customer (many-to-many)
Serves_ibfk_1 and Serves_ibfk_2 jointly enforce that both sides of a “serves” relationship must exist. Only nozzle persons who actually dispensed fuel to a customer should appear here, making this table useful for accountability and customer-service analytics.
Sales_Manage — Employee ↔ Sales (three-way composite FK)
Sales_Manage carries three foreign keys. Sales_Manage_ibfk_1 links to an employee, and Sales_Manage_ibfk_2 + Sales_Manage_ibfk_3 jointly reference the composite primary key (Sales_No, Date) on the Sales table. This accurately reflects that a sales record is uniquely identified by both its number and its date.
Entity Relationship Diagram
The diagram below shows the directional flow of foreign key references across all ten tables. Arrows point from the child (the table holding the FK column) toward the parent (the table holding the referenced PK).| Constraint | Child Table | Child Column | Parent Table | Parent Column |
|---|---|---|---|---|
Owns_ibfk_1 | Owns | Registration_No | PetrolPump | Registration_No |
Owns_ibfk_2 | Owns | Owner_Name | Owners | Owner_Name |
Tanker_ibfk_1 | Tanker | Petrolpump_No | PetrolPump | Registration_No |
Employee_ibfk_1 | Employee | Petrolpump_No | PetrolPump | Registration_No |
Employee_ibfk_2 | Employee | Manager_ID | Employee | Employee_ID |
Invoice_ibfk_1 | Invoice | Date | Sales | Date |
Invoice_ibfk_2 | Invoice | Customer_Code | Customer | Customer_Code |
Sales_ibfk_1 | Sales | Petrolpump_No | PetrolPump | Registration_No |
Contacts_ibfk_1 | Contacts | Employee_ID | Employee | Employee_ID |
Serves_ibfk_1 | Serves | Employee_ID | Employee | Employee_ID |
Serves_ibfk_2 | Serves | Customer_Code | Customer | Customer_Code |
Sales_Manage_ibfk_1 | Sales_Manage | Employee_ID | Employee | Employee_ID |
Sales_Manage_ibfk_2 | Sales_Manage | Sales_No | Sales | Sales_No |
Sales_Manage_ibfk_3 | Sales_Manage | Date | Sales | Date |