0% found this document useful (0 votes)
4 views4 pages

MySQL CRUD Tasks

The document outlines tasks for performing CRUD operations on patient and student records using MySQL. It includes steps for creating databases, tables, inserting sample data, and executing various CRUD operations for both patient and student records. Each task is accompanied by specific questions requiring SQL queries to complete the operations.

Uploaded by

waheed1122pak
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)
4 views4 pages

MySQL CRUD Tasks

The document outlines tasks for performing CRUD operations on patient and student records using MySQL. It includes steps for creating databases, tables, inserting sample data, and executing various CRUD operations for both patient and student records. Each task is accompanied by specific questions requiring SQL queries to complete the operations.

Uploaded by

waheed1122pak
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/ 4

MySQL CRUD Operation Tasks

Task 1: Perform CRUD Operations on Patient Records


Objective
Create a database and table for managing patient records, and perform CRUD operations.
Follow the steps below and answer the questions.

Step 1: Create a Database


Question 1:
Write a query to create a database named `HospitalDB`.

Step 2: Use the Database


Question 2:
Write a query to select and use the `HospitalDB` database for further operations.

Step 3: Create the `patients` Table


The table structure is as follows:

Column Name Data Type Constraints Description


id INT PRIMARY KEY, Unique identifier for
AUTO_INCREMENT each patient.
name VARCHAR(100) NOT NULL Full name of the
patient.
age INT NOT NULL Age of the patient.
gender ENUM('Male', NOT NULL Gender of the
'Female') patient.
disease VARCHAR(150) Disease diagnosed
for the patient.
admission_date DATE NOT NULL Date of admission to
the hospital.
Question 3:
Write a query to create the `patients` table as per the structure above.

Step 4: Insert Sample Data


Insert the following sample records into the `patients` table:

id name age gender disease admission_date


1 Ayub Khan 25 male Fever 2025-01-20
2 Ahmed Ali 30 Male Malaria 2025-01-18
3 Fatima Zafar 28 Female Dengue 2025-01-15
4 Muhammad 35 Male Typhoid 2025-01-10
Umar
Question 4:
Write a query to insert the above data into the `patients` table.
Step 5: Perform CRUD Operations

Part A: Create
Question 5:
Add a new record to the `patients` table with the following details:
- Name: Zainab Farooq
- Age: 32
- Gender: Female
- Disease: COVID-19
- Admission Date: 2025-01-22

Write the SQL query to insert this record.

Part B: Read
Question 6:
Write queries to:
1. Retrieve all records from the `patients` table.
2. Retrieve the names and diseases of all female patients.
3. Find the patient admitted on `2025-01-10`.

Part C: Update
Question 7:
Write a query to update the `disease` of the patient named "Ahmed Ali" to "Pneumonia."

Part D: Delete
Question 8:
Write a query to delete the record of the patient with the `id` = 4.

Task 2: Manage Student Records with MySQL


Objective
Create a database and table for managing student records, and perform CRUD operations.
Follow the steps below and answer the questions.

Step 1: Create a Database


Question 1:
Write a query to create a database named `SchoolDB`.

Step 2: Use the Database


Question 2:
Write a query to select and use the `SchoolDB` database for further operations.

Step 3: Create the `students` Table


The table structure is as follows:
Column Name Data Type Constraints Description
id INT PRIMARY KEY, Unique identifier for
AUTO_INCREMENT each student.
name VARCHAR(100) NOT NULL Full name of the
student.
age INT NOT NULL Age of the student.
class VARCHAR(50) NOT NULL Class in which the
student is enrolled.
grade CHAR(1) Grade obtained in
the last exam.
admission_date DATE NOT NULL Date of admission to
the school.
Question 3:
Write a query to create the `students` table with the structure given above.

Step 4: Insert Sample Data


Insert the following sample records into the `students` table:

id name age class grade admission_date


1 Ali Hassan 15 10th A 2024-12-01
2 Sara Ahmed 14 9th B 2024-11-20
3 Umar 16 11th A 2024-10-15
Farooq
4 Fatima 17 12th C 2024-09-25
Khalid
Question 4:
Write a query to insert the above data into the `students` table.

Step 5: Perform CRUD Operations

Part A: Create
Question 5:
Add a new student record to the `students` table with the following details:
- Name: Zainab Khan
- Age: 15
- Class: 10th
- Grade: B
- Admission Date: 2025-01-22

Write the SQL query to insert this record.

Part B: Read
Question 6:
Write queries to:
1. Retrieve all records from the `students` table.
2. Retrieve the names and grades of all students in the 10th class.
3. Find the student admitted on `2024-09-25`.

Part C: Update
Question 7:
Write a query to update the `grade` of the student named "Sara Ahmed" to "A."

Part D: Delete
Question 8:
Write a query to delete the record of the student with the `id` = 4.

You might also like