User Name
User ID: ----
Dashboard
Book Ticket
Quick search and book
Find Train
Check train schedules
My Bookings
View and manage tickets
Upcoming Trips
Lahore to Karachi
Pakistan Express (1-Up)
Departure: 8:30 AM
Popular Routes
Lahore - Karachi
19 hours journey
Islamabad - Lahore
4 hours journey
Karachi - Quetta
17 hours journey
Peshawar - Islamabad
2 hours journey
Book Ticket
Available Trains
My Bookings
Your Reservations
Karachi Express (2-Down)
Lahore to Karachi • AC Standard
Wed, 23 May 2023
Departure: 08:30 AM
Route Map
Route Details
Total Distance
1,218 km
Journey Time
Approx. 18-21 hours
Major Stops
Lahore, Khanewal, Rohri, Hyderabad, Karachi
Train Schedule
Pakistan Express (1-Up)
Lahore to Karachi
23 May, 2023
On Time
Station Schedule
Profile Settings
User Name
user@example.com
Change Password
Database Management
This is a simulation of a relational database system for Pakistan Railways. Create tables, insert data, and see how application actions affect the database.
Database Tables
Users Table
CREATE TABLE users (
user_id INT PRIMARY KEY AUTO_INCREMENT,
full_name VARCHAR(100) NOT NULL,
cnic VARCHAR(15) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
phone VARCHAR(20) NOT NULL,
password_hash VARCHAR(255) NOT NULL,
address TEXT,
profile_image TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Trains Table
CREATE TABLE trains (
train_id INT PRIMARY KEY AUTO_INCREMENT,
train_name VARCHAR(100) NOT NULL,
train_number VARCHAR(20) UNIQUE NOT NULL,
source_station VARCHAR(100) NOT NULL,
destination_station VARCHAR(100) NOT NULL,
total_distance INT NOT NULL, -- in kilometers
journey_time INT NOT NULL, -- in minutes
is_active BOOLEAN DEFAULT TRUE
);
Stations Table
CREATE TABLE stations (
station_id INT PRIMARY KEY AUTO_INCREMENT,
station_name VARCHAR(100) NOT NULL,
station_code VARCHAR(10) UNIQUE NOT NULL,
city VARCHAR(100) NOT NULL,
address TEXT NOT NULL,
latitude DECIMAL(10,6),
longitude DECIMAL(10,6)
);
Additional Tables
Schedules Table
CREATE TABLE schedules (
schedule_id INT PRIMARY KEY AUTO_INCREMENT,
train_id INT NOT NULL,
station_id INT NOT NULL,
arrival_time TIME,
departure_time TIME,
day_offset INT DEFAULT 0, -- 0 means same day, 1 means next day, etc.
stop_order INT NOT NULL, -- order of stops for the train
FOREIGN KEY (train_id) REFERENCES trains(train_id),
FOREIGN KEY (station_id) REFERENCES stations(station_id)
);
Train Classes Table
CREATE TABLE train_classes (
class_id INT PRIMARY KEY AUTO_INCREMENT,
train_id INT NOT NULL,
class_name VARCHAR(50) NOT NULL, -- Economy, AC Standard, AC Business, etc.
base_fare DECIMAL(10,2) NOT NULL, -- Base fare per kilometer
total_seats INT NOT NULL,
FOREIGN KEY (train_id) REFERENCES trains(train_id)
);
Bookings Table
CREATE TABLE bookings (
booking_id INT PRIMARY KEY AUTO_INCREMENT,
booking_reference VARCHAR(20) UNIQUE NOT NULL,
user_id INT NOT NULL,
train_id INT NOT NULL,
class_id INT NOT NULL,
source_station_id INT NOT NULL,
destination_station_id INT NOT NULL,
travel_date DATE NOT NULL,
fare_amount DECIMAL(10,2) NOT NULL,
passengers INT NOT NULL DEFAULT 1,
booking_status ENUM('pending', 'confirmed', 'cancelled') DEFAULT 'pending',
payment_status ENUM('pending', 'completed', 'refunded') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (train_id) REFERENCES trains(train_id),
FOREIGN KEY (class_id) REFERENCES train_classes(class_id),
FOREIGN KEY (source_station_id) REFERENCES stations(station_id),
FOREIGN KEY (destination_station_id) REFERENCES stations(station_id)
);
Passenger Details Table
CREATE TABLE passenger_details (
passenger_id INT PRIMARY KEY AUTO_INCREMENT,
booking_id INT NOT NULL,
passenger_name VARCHAR(100) NOT NULL,
passenger_cnic VARCHAR(15) NOT NULL,
passenger_age INT,
passenger_gender ENUM('male', 'female', 'other'),
seat_number VARCHAR(10),
FOREIGN KEY (booking_id) REFERENCES bookings(booking_id)
);
Payments Table
CREATE TABLE payments (
payment_id INT PRIMARY KEY AUTO_INCREMENT,
booking_id INT NOT NULL,
transaction_reference VARCHAR(50) UNIQUE NOT NULL,
amount DECIMAL(10,2) NOT NULL,
payment_method ENUM('credit_card', 'debit_card', 'bank_transfer', 'easypaisa', 'jazzcash') NOT NULL,
payment_status ENUM('pending', 'completed', 'failed', 'refunded') DEFAULT 'pending',
payment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (booking_id) REFERENCES bookings(booking_id)
);
Database Data
No data found in this table
Select a table to view data
SQL Query Executor
Write and execute custom SQL queries against the database.