0% found this document useful (0 votes)
3 views

Database_Case_Study_Updated

Uploaded by

rudrapatel0004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Database_Case_Study_Updated

Uploaded by

rudrapatel0004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Database Schema and Queries

1. Create Statements

-- Create Table for Medicine

CREATE TABLE Medicine (

MName VARCHAR(50) PRIMARY KEY,

Type VARCHAR(20) NOT NULL,

Manufacturer VARCHAR(50) NOT NULL,

Content VARCHAR(100),

Usage VARCHAR(50)

);

-- Create Table for Stock

CREATE TABLE Stock (

MName VARCHAR(50),

BatchNo INT PRIMARY KEY,

ManuDate DATE NOT NULL,

ExpDate DATE NOT NULL,

BatchQty INT NOT NULL,

FOREIGN KEY (MName) REFERENCES Medicine(MName)

);

2. Insert Statements

INSERT INTO Medicine (MName, Type, Manufacturer, Content, Usage) VALUES

('Paracetamol', 'Tablet', 'PharmaCorp', 'Paracetamol 500mg', 'Fever'),


('Ibuprofen', 'Tablet', 'HealthPlus', 'Ibuprofen 200mg', 'Headache'),

('Amoxicillin', 'Capsule', 'MedLife', 'Amoxicillin 250mg', 'Infection'),

('Cough Syrup', 'Syrup', 'PharmaCorp', 'Dextromethorphan', 'Cough'),

('Vitamin C', 'Tablet', 'WellnessPharma', 'Ascorbic Acid', 'Immunity'),

('Cetirizine', 'Tablet', 'MedCare', 'Cetirizine 10mg', 'Allergy'),

('Azithromycin', 'Capsule', 'HealthPlus', 'Azithromycin 500mg', 'Infection'),

('Pain Relief Gel', 'Gel', 'PainAway', 'Diclofenac', 'Pain'),

('Multivitamin', 'Capsule', 'WellnessPharma', 'Vitamin B, C, D', 'Energy'),

('Cold Balm', 'Ointment', 'MedLife', 'Menthol, Camphor', 'Cold');

INSERT INTO Stock (MName, BatchNo, ManuDate, ExpDate, BatchQty) VALUES

('Paracetamol', 101, '2024-01-01', '2025-01-01', 100),

('Ibuprofen', 102, '2024-02-01', '2025-02-01', 50),

('Amoxicillin', 103, '2024-03-01', '2025-03-01', 80),

('Cough Syrup', 104, '2024-01-15', '2025-01-15', 30),

('Vitamin C', 105, '2024-04-01', '2025-04-01', 60),

('Cetirizine', 106, '2024-05-01', '2025-05-01', 45),

('Azithromycin', 107, '2024-06-01', '2025-06-01', 70),

('Pain Relief Gel', 108, '2024-07-01', '2025-07-01', 40),

('Multivitamin', 109, '2024-08-01', '2025-08-01', 90),

('Cold Balm', 110, '2024-09-01', '2025-09-01', 20);

3. Select Statements and Outputs


Query 1:

SQL: SELECT MName, SUM(BatchQty) AS TotalQuantity FROM Stock GROUP BY MName;

Output:

MName | TotalQuantity
Paracetamol | 100

Ibuprofen | 50

Amoxicillin | 80

Cough Syrup | 30

Vitamin C | 60

Cetirizine | 45

Azithromycin | 70

Pain Relief Gel | 40

Multivitamin | 90

Cold Balm | 20

Query 2:

SQL: SELECT Manufacturer, Content FROM Medicine WHERE Type = 'Tablet';

Output:

Manufacturer | Content

PharmaCorp | Paracetamol 500mg

HealthPlus | Ibuprofen 200mg

WellnessPharma | Ascorbic Acid

MedCare | Cetirizine 10mg

Query 3:

SQL: SELECT DISTINCT Manufacturer FROM Medicine WHERE Usage IN ('Fever', 'Headache');

Output:

Manufacturer

PharmaCorp

HealthPlus

Query 4:
SQL: SELECT MName FROM Stock WHERE BatchQty > 50;

Output:

MName

Paracetamol

Amoxicillin

Vitamin C

Azithromycin

Multivitamin

Query 5:

SQL: SELECT M.*, S.* FROM Medicine M JOIN Stock S ON M.MName = S.MName WHERE

M.Type = 'Capsule';

Output:

MName | Type | Manufacturer | Content | Usage | BatchNo | ManuDate | ExpDate | BatchQty

Amoxicillin | Capsule | MedLife | Amoxicillin 250mg | Infection | 103 | 2024-03-01 | 2025-03-01

Azithromycin | Capsule | HealthPlus | Azithromycin 500mg | Infection | 107 | 2024-06-01 | 2025-

Multivitamin | Capsule | WellnessPharma | Vitamin B, C, D | Energy | 109 | 2024-08-01 | 2025-08

You might also like