Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views12 pages

Hospital Management System

The document outlines the creation and management of three systems: Hospital Management, Electricity Management, and Courier Management. It includes SQL queries for Data Definition Language (DDL) and Data Manipulation Language (DML) tasks such as creating tables, altering tables, inserting data, selecting data, updating records, and deleting records. Each system has specific tables and operations tailored to its functions, such as managing patients and doctors in the hospital system, customers and bills in the electricity system, and couriers and deliveries in the courier system.

Uploaded by

sriyogesheeli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Hospital Management System

The document outlines the creation and management of three systems: Hospital Management, Electricity Management, and Courier Management. It includes SQL queries for Data Definition Language (DDL) and Data Manipulation Language (DML) tasks such as creating tables, altering tables, inserting data, selecting data, updating records, and deleting records. Each system has specific tables and operations tailored to its functions, such as managing patients and doctors in the hospital system, customers and bills in the electricity system, and couriers and deliveries in the courier system.

Uploaded by

sriyogesheeli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

Hospital Management System

DDL (Data Definition Language) Questions

Question 1: Create Tables for the Hospital Management System

Query

1. Create Patients Table

CREATE TABLE Patients (

patient_id INT,

name VARCHAR(100),

age INT,

gender VARCHAR(10),

address VARCHAR(255),

contact_number VARCHAR(15),

disease VARCHAR(100)

);

2. Create Doctors Table

CREATE TABLE Doctors (

doctor_id INT,

name VARCHAR(100),

specialization VARCHAR(100),

experience INT,

contact_number VARCHAR(15)

);

3. Create Appointments Table

CREATE TABLE Appointments (

appointment_id INT,

patient_id INT,

doctor_id INT,

appointment_date DATE,

status VARCHAR(50)

);
Question 2: Alter a Table (Add a Column)

Task: Add an email column to the Patients table

ALTER TABLE Patients

ADD email VARCHAR(100);

Question 3: Rename a Table

Task: Rename ‘Appointments’ to ‘Hospital_Appointments’

RENAME TABLE Appointments TO Hospital_Appointments;

Question 4: Truncate a Table

Task: Remove all data from the Doctors table but keep the structure

TRUNCATE TABLE Doctors;

Question 5: Drop a Table

Task: Drop the Hospital_Appointments table

DROP TABLE Hospital_Appointments;

DML (Data Manipulation Language) Questions

Question 6: Insert Data into Tables

Query

1. Insert Patients

INSERT INTO Patients (patient_id, name, age, gender, address, contact_number, disease)

VALUES

(1, 'John Doe', 35, 'Male', '123 Street, NY', '9876543210', 'Flu'),

(2, 'Alice Smith', 28, 'Female', '456 Avenue, LA', '8765432109', 'Migraine'),

(3, 'Mark Johnson', 40, 'Male', '789 Boulevard, SF', '7654321098', 'Diabetes');

2. Insert Doctors

INSERT INTO Doctors (doctor_id, name, specialization, experience, contact_number)

VALUES

(1, 'Dr. Sarah Lee', 'Cardiologist', 10, '9876541230'),


(2, 'Dr. Tom Brown', 'Neurologist', 8, '8765432190'),

(3, 'Dr. Emma Wilson', 'Dermatologist', 5, '7654321980');

3. Insert Appointments

INSERT INTO Hospital_Appointments (appointment_id, patient_id, doctor_id, appointment_date,


status)

VALUES

(1, 1, 1, '2025-02-10', 'Scheduled'),

(2, 2, 2, '2025-02-12', 'Completed'),

(3, 3, 3, '2025-02-15', 'Cancelled');

Question 7: Select Data from Tables

Query

1. Retrieve all patients who are older than 30

SELECT * FROM Patients

WHERE age > 30;

2. Retrieve all doctors who are either Cardiologists or Neurologists

SELECT * FROM Doctors

WHERE specialization = 'Cardiologist' OR specialization = 'Neurologist';

3. Retrieve all scheduled appointments

SELECT * FROM Hospital_Appointments

WHERE status = 'Scheduled';

Question 8: Use LIKE Operator

Query

1. Find patients whose name starts with ‘A’

SELECT * FROM Patients

WHERE name LIKE 'A%';

2. Find doctors whose specialization contains ‘Neuro’

SELECT * FROM Doctors

WHERE specialization LIKE '%Neuro%';


Question 9: Use BETWEEN Operator

Query

1. Find patients aged between 25 and 40

SELECT * FROM Patients

WHERE age BETWEEN 25 AND 40;

2. Find doctors with experience between 5 and 10 years

SELECT * FROM Doctors

WHERE experience BETWEEN 5 AND 10;

Question 10: Use IS NULL Operator

Query

1. Find patients whose email is not entered (NULL values)

SELECT * FROM Patients

WHERE email IS NULL;

2. Find appointments that have no status assigned

SELECT * FROM Hospital_Appointments

WHERE status IS NULL;

Question 11: Update Data in Tables

Query

1. Update a patient’s address

UPDATE Patients

SET address = '999 New Street, NY'

WHERE patient_id = 1;

2. Update a doctor’s experience

UPDATE Doctors

SET experience = 12

WHERE name = 'Dr. Sarah Lee';

3. Update an appointment status

UPDATE Hospital_Appointments

SET status = 'Completed'


WHERE appointment_id = 1;

Question 12: Delete Data from Tables

Query

1. Delete a patient record

DELETE FROM Patients

WHERE name = 'Mark Johnson';

2. Delete all cancelled appointments

DELETE FROM Hospital_Appointments

WHERE status = 'Cancelled';

2. Electricity Management System

DDL (Data Definition Language) Questions

Question 1: Create Tables for the Electricity Management System

Query

1. Create Customers Table

CREATE TABLE Customers (

customer_id INT,

name VARCHAR(100),

address VARCHAR(255),

contact_number VARCHAR(15),

email VARCHAR(100)

);

2. Create Meters Table

CREATE TABLE Meters (

meter_id INT,

customer_id INT,

meter_type VARCHAR(50),

installation_date DATE

);
3. Create Bills Table

CREATE TABLE Bills (

bill_id INT,

customer_id INT,

meter_id INT,

bill_date DATE,

amount DECIMAL(10,2),

status VARCHAR(50)

);

Question 2: Alter a Table (Add a Column)

Task: Add a column for ‘Due Date’ in the Bills table

ALTER TABLE Bills

ADD due_date DATE;

Question 3: Rename a Table

Task: Rename ‘Meters’ table to ‘Electric_Meters’

RENAME TABLE Meters TO Electric_Meters;

Question 4: Truncate a Table

Task: Remove all data from the Bills table but keep its structure

TRUNCATE TABLE Bills;

Question 5: Drop a Table

Task: Drop the Electric_Meters table

DROP TABLE Electric_Meters;

DML (Data Manipulation Language) Questions

Question 6: Insert Data into Tables

Query

1. Insert Customers
INSERT INTO Customers (customer_id, name, address, contact_number, email)

VALUES

(1, 'John Doe', '123 Main St, NY', '9876543210', '[email protected]'),

(2, 'Alice Smith', '456 Elm St, LA', '8765432109', '[email protected]'),

(3, 'Mark Johnson', '789 Pine St, SF', '7654321098', NULL);

2. Insert Meters

INSERT INTO Meters (meter_id, customer_id, meter_type, installation_date)

VALUES

(101, 1, 'Residential', '2024-01-10'),

(102, 2, 'Commercial', '2023-12-15'),

(103, 3, 'Industrial', '2022-06-05');

3. Insert Bills

INSERT INTO Bills (bill_id, customer_id, meter_id, bill_date, amount, status)

VALUES

(201, 1, 101, '2024-02-01', 100.50, 'Paid'),

(202, 2, 102, '2024-02-05', 200.75, 'Unpaid'),

(203, 3, 103, '2024-02-10', 150.30, 'Pending');

Question 7: Select Data from Tables

Query

1. Retrieve all customers from New York

SELECT * FROM Customers

WHERE address LIKE '%NY%';

2. Retrieve all unpaid bills

SELECT * FROM Bills

WHERE status = 'Unpaid';

3. Retrieve all commercial meters installed after 2023

SELECT * FROM Meters

WHERE meter_type = 'Commercial' AND installation_date > '2023-01-01';

Question 8: Use LIKE Operator


Query

1. Find customers whose name starts with ‘A’

SELECT * FROM Customers

WHERE name LIKE 'A%';

2. Find all meter types containing ‘Industrial’

SELECT * FROM Meters

WHERE meter_type LIKE '%Industrial%';

Question 9: Use BETWEEN Operator

Query

1. Find bills between $100 and $200

SELECT * FROM Bills

WHERE amount BETWEEN 100 AND 200;

2. Find meters installed between ‘2022-01-01’ and ‘2023-12-31’

SELECT * FROM Meters

WHERE installation_date BETWEEN '2022-01-01' AND '2023-12-31';

Question 10: Use IS NULL Operator

Query

1. Find customers whose email is not entered (NULL values)

SELECT * FROM Customers

WHERE email IS NULL;

2. Find bills where due date is missing

SELECT * FROM Bills

WHERE due_date IS NULL;

Question 11: Update Data in Tables

Query

1. Update a customer’s address

UPDATE Customers

SET address = '999 New Avenue, NY'


WHERE customer_id = 1;

2. Update a bill’s status

UPDATE Bills

SET status = 'Paid'

WHERE bill_id = 202;

3. Update meter type from ‘Residential’ to ‘Smart Residential’

UPDATE Meters

SET meter_type = 'Smart Residential'

WHERE meter_id = 101;

Question 12: Delete Data from Tables

Query

1. Delete a customer record

DELETE FROM Customers

WHERE name = 'Mark Johnson';

2. Delete all unpaid bills

DELETE FROM Bills

WHERE status = 'Unpaid';

Courier Management System—Practice Exercise

DDL (Data Definition Language) Questions

Question 1: Create Tables for the Courier Management System

Task: Create tables for managing couriers, customers, and deliveries.

Query:

1. Create Customers Table

CREATE TABLE Customers (

customer_id INT,

name VARCHAR(100),

address VARCHAR(255),
phone VARCHAR(15),

email VARCHAR(100)

);

2. Create Couriers Table

CREATE TABLE Couriers (

courier_id INT,

sender_id INT,

receiver_id INT,

package_type VARCHAR(50),

weight DECIMAL(5,2),

status VARCHAR(50)

);

3. Create Deliveries Table

CREATE TABLE Deliveries (

delivery_id INT,

courier_id INT,

delivery_date DATE,

delivery_status VARCHAR(50),

assigned_agent VARCHAR(100)

);

Question 2: Alter a Table (Add a Column)

Task: Add a column for ‘Expected Delivery Date’ in the Deliveries table.

Question 3: Rename a Table

Task: Rename ‘Couriers’ table to ‘Shipment’.

Question 4: Truncate a Table

Task: Remove all data from the Deliveries table but keep its structure.

Question 5: Drop a Table


Task: Drop the Shipment table.

DML (Data Manipulation Language) Questions

Question 6: Insert Data into Tables

Task: Insert records into the Customers, Couriers, and Deliveries tables.

Query:

1. Insert Customers

INSERT INTO Customers (customer_id, name, address, phone, email)

VALUES

(1, 'John Doe', '123 Maple St, NY', '9876543210', '[email protected]'),

(2, 'Alice Smith', '456 Oak St, LA', '8765432109', '[email protected]'),

(3, 'Mark Johnson', '789 Pine St, SF', '7654321098', NULL);

2. Insert Couriers

INSERT INTO Couriers (courier_id, sender_id, receiver_id, package_type, weight, status)

VALUES

(101, 1, 2, 'Documents', 1.5, 'In Transit'),

(102, 2, 3, 'Electronics', 2.8, 'Delivered'),

(103, 3, 1, 'Clothes', 3.0, 'Pending');

3. Insert Deliveries

INSERT INTO Deliveries (delivery_id, courier_id, delivery_date, delivery_status, assigned_agent)

VALUES

(201, 101, '2024-02-01', 'On Route', 'Agent A'),

(202, 102, '2024-02-03', 'Delivered', 'Agent B'),

(203, 103, '2024-02-05', 'Pending', NULL);

Question 7: Select Data from Tables

1. Retrieve all customers from New York.

2. Retrieve all couriers that are in transit or pending.

3. Retrieve deliveries assigned to Agent A.

Question 8: Use LIKE Operator


1. Find customers whose name starts with ‘A’.

2. Find couriers with package types containing ‘Electronics’.

Question 9: Use BETWEEN Operator

1. Find couriers weighing between 2kg and 5kg.

2. Find deliveries made between ‘2024-01-01’ and ‘2024-02-28’.

Question 10: Use IS NULL Operator

1. Find customers whose email is not entered (NULL values).

2. Find deliveries where the assigned agent is missing.

Question 11: Update Data in Tables

1. Update a customer’s address.

2. Update a courier’s status to ‘Delivered’.

3. Update delivery agent for a pending delivery.

Question 12: Delete Data from Tables

1. Delete a customer record.

2. Delete all couriers with status ‘Delivered’.

You might also like