Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

-- Create the railway database

CREATE DATABASE railway;


USE railway;

-- Table to store customer details


CREATE TABLE customers (
customer_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
address VARCHAR(255) NOT NULL
);

-- Table to store ticket booking details


CREATE TABLE tickets (
ticket_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
journey_date DATE NOT NULL,
destination VARCHAR(100) NOT NULL,
class_type VARCHAR(50) NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);

-- Table to store class types with rates


CREATE TABLE classtypes (
class_id INT AUTO_INCREMENT PRIMARY KEY,
class_name VARCHAR(50) NOT NULL,
rate DECIMAL(10, 2) NOT NULL
);

-- Table to store train details


CREATE TABLE trains (
train_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
source VARCHAR(100) NOT NULL,
destination VARCHAR(100) NOT NULL
);

-- Table to store train schedules


CREATE TABLE train_schedule (
schedule_id INT AUTO_INCREMENT PRIMARY KEY,
train_id INT,
journey_date DATE NOT NULL,
available_seats INT NOT NULL,
FOREIGN KEY (train_id) REFERENCES trains(train_id)
);

-- Table to store payment details


CREATE TABLE payments (
payment_id INT AUTO_INCREMENT PRIMARY KEY,
ticket_id INT,
amount DECIMAL(10, 2) NOT NULL,
payment_method VARCHAR(50) NOT NULL,
FOREIGN KEY (ticket_id) REFERENCES tickets(ticket_id)
);

-- Insert sample data into classtypes


INSERT INTO classtypes (class_name, rate) VALUES
('First Class', 1500.00),
('Sleeper Class', 500.00),
('General Class', 100.00);

-- Insert sample data into trains


INSERT INTO trains (name, source, destination) VALUES
('Express Train', 'CityA', 'CityB'),
('Superfast Train', 'CityB', 'CityC'),
('Local Train', 'CityA', 'CityC');

-- Insert sample data into train_schedule


INSERT INTO train_schedule (train_id, journey_date, available_seats) VALUES
(1, '2024-07-01', 100),
(2, '2024-07-01', 150),
(3, '2024-07-01', 200);

You might also like