You are on page 1of 44

Experiment-1

Objective: Write the Steps to Install Oracle / MySql

➔ The Steps to Install MySql are:

Step 1: After downloading the setup, unzip it anywhere and double click the MSI installer .exe
file. It will give the following screen:

Step 2: In the next wizard, choose the Setup Type. There are several types available, and you need
to choose the appropriate option to install MySQL products and features.

Step 3: Once we click on the Next button, it may give information about some features that may
fail to install on your system due to a lack of requirements.

Step 4: In the next wizard, we will see a dialog box that asks for our confirmation of a few products
not getting installed. Here, we have to click on the Yes button.

Step 5: Once we click on the Execute button, it will download and install all the products. After
completing the installation, click on the Next button.

Step 6: In the next wizard, we need to configure the MySQL Server and Router. Here, I am not
going to configure the Router because there is no need to use it with MySQL

Step 7: As soon as you will click on the Next button, you can see the screen below. Here, we have
to configure the MySQL Server.

Step 8: In the next screen, the system will ask you to choose the Config Type and other connectivity
options. Here, we are going to select the Config Type as 'Development Machine' and Connectivity
as TCP/IP, and Port Number is 3306, then click on Next.

Step 9: Now, select the Authentication Method and click on Next. Here, I am going to select the
first option.

Step 10: The next screen will ask you to mention the MySQL Root Password. After filling the
password details, click on the Next button.
Step 11: The next screen will ask you to configure the Windows Service to start the server. Keep
the default setup and click on the Next button.

Step 12: In the next wizard, the system will ask you to apply the Server Configuration. If you agree
with this configuration, click on the Execute button.

Step 13: Once the configuration has completed, you will get the screen below. Now, click on the
Finish button to continue.

Step 14: In the next screen, you can see that the Product Configuration is completed. Keep the
default setting and click on the Next-> Finish button to complete the MySQL package installation.

Step 15: In the next wizard, we can choose to configure the Router. So click on Next->Finish and
then click the Next button.

Step 16: In the next wizard, we will see the Connect to Server option. Here, we have to mention
the root password, which we had set in the previous steps.

Step 17: In the next wizard, select the applied configurations and click on the Execute button.

Step 18: After completing the above step, we will get the following screen. Here, click on the
Finish button.

Step 19: Now, the MySQL installation is complete. Click on the Finish button.
Result : MySql downloaded Successfully
Experiment-2
Objective: Creating Entity Relationship Diagram using case tools

THEORY:
An Entity Relationship Diagram (ERD) is a visual representation of different entities
within a system and how they relate to each other.. ER diagrams use symbols to
represent entities, attributes, and relationships, which help to illustrate the relationships
between the entities in the database. ER diagrams are commonly used in software
engineering and database design to help developers and stakeholders understand and
design complex databases

Symbols Used in ER Model

ER Model is used to model the logical view of the system from data
perspective which consists of these symbols:
• Rectangles:Rectangles represent Entities in the ER Model.
• Ellipses:EllipsesrepresentAttributesintheERModel.
• Diamond:DiamondsrepresentRelationshipsamongEntities.

Lines:Linesrepresentattributestoentitiesandentitysetswithoth
er relationship types.
• DoubleEllipse:Double EllipsesrepresentMulti-ValuedAttributes.
• Double Rectangle:DoubleRectangle representsaWeakEntity.

WhyUseERDiagramsInDBMS?
1. ER diagrams are used to represent thE-Modelina Database,which
makes them easy to be converted into relations (tables).
2. ER diagrams provide the purpose of real-world modeling of objects
which makes them intently useful.
3. ER diagrams require no technical knowledge and no hardware support.
Components of ER Diagram

EntitySet: An Entity is an object of Entity Type and a set of all entities is called an
entity set.
1. Strong Entity A Strong Entity is a type of entity that has keyAttribute.
2.WeakEntity

An Entity type has a key attribute that uniquely identifies each entity in the entity set.

Attributes:Attributes Are The Properties That Define The Entity Type.

1.KeyAttribute The attribute which uniquely identifies each entity in the entity set is called the
key attribute.

2. Composite Attribute An attribute composed of many other attributes called a


composite attribute.
3.MultivaluedAttribute An attribute consisting of more than one Value For Given entity.
4.DerivedAttribute An attribute that can be derived from other attributes of the entity type is
known as a derived attribute.

Implementation:
The Entity Relationship Diagram for Library Management System

Result: The Entity Relationship Diagram of Library Management is implemented


successfully
Experiment-3
Objective: Writing SQL Statements using Oracle/MySQL:
a) Writing the basic SQL Select statement
b) Restricting and Sorting Data
c) Displaying Data from Multiple Data
d) Aggregration data using Group Functions
e) Manipulating Data
f) Creating and Managing tables

Theory: SQL (Structured Query Language) is used for managing relational databases. Basic
SELECT retrieves data, WHERE clause restricts and ORDER BY sorts. JOIN fetches data from
multiple tables, GROUP BY aggregates, and DML manipulates.

Implementation:
1.Create table Employee and Department
2. Basic SQL Select statement

3.Restricting and Sorting Data

4.Displaying Data from Multiple Data


5.Aggregation data using Group Functions

6.Manipulating Data

7. Creating and Managing tables


Result:
Successfully executed SQL statements in MySQL. Retrieved, restricted, and sorted data.
Displayed data from multiple tables using JOIN.
Aggregated data with GROUP BY. Manipulated data with INSERT, UPDATE, DELETE.
Created and managed tables.

Experiment-4
Objective: Writing SQL Statements using Oracle/MySQLfor Normalization

Theory:
Normalization is a process in database design that organizes tables and columns in a
relational database to reduce redundancy and improve data integrity. There are several
normal forms (1NF, 2NF, 3NF, BCNF, etc.), and the normalization process involves
eliminating dependencies and organizing data to avoid anomalies.

Implementation:

Initial Table not in 3nF


Steps to Normalize to 3NF:
Step 1: Identify Primary Key
In the initial table, the primary key is order_id. This uniquely identifies each order.

Step 2: Identify Partial Dependencies


Partial dependencies occur when a column in a table depends on only part of the
primary key. In this case, customer_name depends on customer_id, and
product_name depends on product_id.

Step 3: Create Separate Tables for Partial Dependencies


Create separate tables for customers and products:

Step 4: Create Foreign Keys


In the original "orders" table, replace customer_id and product_id with foreign
keys referencing the new "customers" and "products" tables

Step 5: Remove Redundant Columns


Remove redundant columns from the "orders" table

Result:
Successfully executed Normalization on the given table
Experiment-5
Objective: Design and Implementation of Payroll Processing System
Theory:
MySQL, a relational database management system (RDBMS), is crucial for storing,
managing, and retrieving data. It facilitates the creation of database structures, ensures data
integrity, and supports CRUD operations—enabling data insertion and deletion through
SQL queries.
Implementation
mysql> USE payroll_system;
Database changed
mysql> CREATE TABLE employees (
-> employee_id INT PRIMARY KEY,
-> first_name VARCHAR(50),
-> last_name VARCHAR(50),
-> birth_date DATE,
-> hire_date DATE,
-> department VARCHAR(50),
-> job_title VARCHAR(50),
-> salary DECIMAL(10, 2)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> DESCRIBE employees;


+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| employee_id | int | NO | PRI | NULL | |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| birth_date | date | YES | | NULL | |
| hire_date | date | YES | | NULL | |
| department | varchar(50) | YES | | NULL | |
| job_title | varchar(50) | YES | | NULL | |
| salary | decimal(10,2) | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
8 rows in set (0.03 sec)

mysql> CREATE TABLE deductions (


-> deduction_id INT PRIMARY KEY,
-> deduction_name VARCHAR(50),
-> amount DECIMAL(10, 2)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> DESCRIBE deductions;


+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| deduction_id | int | NO | PRI | NULL | |
| deduction_name | varchar(50) | YES | | NULL | |
| amount | decimal(10,2) | YES | | NULL | |
+----------------+---------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> CREATE TABLE payroll (


-> payroll_id INT PRIMARY KEY,
-> employee_id INT,
-> pay_date DATE,
-> net_salary DECIMAL(10, 2),
-> deductions_amount DECIMAL(10, 2),
-> total_salary DECIMAL(10, 2),
-> FOREIGN KEY (employee_id) REFERENCES employees(employee_id)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> DESCRIBE payroll;
+-------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------+------+-----+---------+-------+
| payroll_id | int | NO | PRI | NULL | |
| employee_id | int | YES | MUL | NULL | |
| pay_date | date | YES | | NULL | |
| net_salary | decimal(10,2) | YES | | NULL | |
| deductions_amount | decimal(10,2) | YES | | NULL | |
| total_salary | decimal(10,2) | YES | | NULL | |
+-------------------+---------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> INSERT INTO employees VALUES


-> (1, 'John', 'Doe', '1990-01-01', '2020-01-01', 'IT', 'Software Engineer', 60000.00),
-> (2, 'Jane', 'Smith', '1985-05-15', '2019-02-15', 'HR', 'HR Manager', 70000.00);
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT INTO deductions VALUES


-> (1, 'Health Insurance', 1000.00),
-> (2, 'Income Tax', 2000.00);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT INTO payroll VALUES


-> (1, 1, '2023-01-31', 59000.00, 3000.00, 56000.00),
-> (2, 2, '2023-01-31', 67000.00, 3000.00, 64000.00);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from employees
-> ;
+-------------+------------+-----------+------------+------------+------------+-------------------+---
-------+
| employee_id | first_name | last_name | birth_date | hire_date | department | job_title
| salary |
+-------------+------------+-----------+------------+------------+------------+-------------------+---
-------+
| 1 | John | Doe | 1990-01-01 | 2020-01-01 | IT | Software Engineer |
60000.00 |
| 2 | Jane | Smith | 1985-05-15 | 2019-02-15 | HR | HR Manager |
70000.00 |
+-------------+------------+-----------+------------+------------+------------+-------------------+---
-------+
2 rows in set (0.00 sec)

mysql> select * from deductions ;


+--------------+------------------+---------+
| deduction_id | deduction_name | amount |
+--------------+------------------+---------+
| 1 | Health Insurance | 1000.00 |
| 2 | Income Tax | 2000.00 |
+--------------+------------------+---------+
2 rows in set (0.00 sec)
mysql> select * from payroll ;
+------------+-------------+------------+------------+-------------------+--------------+
| payroll_id | employee_id | pay_date | net_salary | deductions_amount | total_salary |
+------------+-------------+------------+------------+-------------------+--------------+
| 1| 1 | 2023-01-31 | 59000.00 | 3000.00 | 56000.00 |
| 2| 2 | 2023-01-31 | 67000.00 | 3000.00 | 64000.00 |
+------------+-------------+------------+------------+-------------------+--------------+
2 rows in set (0.00 sec)

Output
Result : Successfully designed and implemented the Payroll Processing System.

Experiment-6
Objective: Design and Implementation of Library Information System
Theory:
MySQL, a relational database management system (RDBMS), is crucial for storing,
managing, and retrieving data. It facilitates the creation of database structures, ensures data
integrity, and supports CRUD operations—enabling data insertion and deletion through
SQL queries.
Implementation:
mysql> CREATE DATABASE library_system;
Query OK, 1 row affected (0.01 sec)

mysql> USE library_system;


Database changed
mysql> CREATE TABLE books (
-> book_id INT PRIMARY KEY,
-> title VARCHAR(100),
-> author VARCHAR(100),
-> genre VARCHAR(50),
-> publication_year INT,
-> available BOOLEAN
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE members (


-> member_id INT PRIMARY KEY,
-> first_name VARCHAR(50),
-> last_name VARCHAR(50),
-> birth_date DATE,
-> email VARCHAR(100),
-> phone_number VARCHAR(15)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE checkouts (


-> checkout_id INT PRIMARY KEY,
-> member_id INT,
-> book_id INT,
-> checkout_date DATE,
-> return_date DATE,
-> FOREIGN KEY (member_id) REFERENCES members(member_id),
-> FOREIGN KEY (book_id) REFERENCES books(book_id)
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO books VALUES


-> (1, 'The Catcher in the Rye', 'J.D. Salinger', 'Fiction', 1951, true),
-> (2, 'To Kill a Mockingbird', 'Harper Lee', 'Fiction', 1960, true),
-> (3, '1984', 'George Orwell', 'Dystopian', 1949, true);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> INSERT INTO members VALUES


-> (1, 'Alice', 'Johnson', '1995-03-15', 'alice@email.com', '123-456-7890'),
-> (2, 'Bob', 'Smith', '1980-12-10', 'bob@email.com', '987-654-3210');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT INTO checkouts VALUES


-> (1, 1, 1, '2023-01-15', '2023-02-15'),
-> (2, 2, 2, '2023-01-20', '2023-02-20');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> DESCRIBE books;


+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| title | varchar(100) | YES | | NULL | |
| author | varchar(100) | YES | | NULL | |
| genre | varchar(50) | YES | | NULL | |
| publication_year | int | YES | | NULL | |
| available | tinyint(1) | YES | | NULL | |
+------------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> SELECT * FROM books;


+---------+------------------------+---------------+-----------+------------------+-----------+
| book_id | title | author | genre | publication_year | available |
+---------+------------------------+---------------+-----------+------------------+-----------+
| 1 | The Catcher in the Rye | J.D. Salinger | Fiction | 1951 | 1|
| 2 | To Kill a Mockingbird | Harper Lee | Fiction | 1960 | 1|
| 3 | 1984 | George Orwell | Dystopian | 1949 | 1|
+---------+------------------------+---------------+-----------+------------------+-----------+
3 rows in set (0.00 sec)

mysql> DESCRIBE members;


+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| member_id | int | NO | PRI | NULL | |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| birth_date | date | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| phone_number | varchar(15) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> SELECT * FROM members;


+-----------+------------+-----------+------------+-----------------+--------------+
| member_id | first_name | last_name | birth_date | email | phone_number |
+-----------+------------+-----------+------------+-----------------+--------------+
| 1 | Alice | Johnson | 1995-03-15 | alice@email.com | 123-456-7890 |
| 2 | Bob | Smith | 1980-12-10 | bob@email.com | 987-654-3210 |
+-----------+------------+-----------+------------+-----------------+--------------+
2 rows in set (0.00 sec)

mysql> DESCRIBE checkouts;


+---------------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------+------+-----+---------+-------+
| checkout_id | int | NO | PRI | NULL | |
| member_id | int | YES | MUL | NULL | |
| book_id | int | YES | MUL | NULL | |
| checkout_date | date | YES | | NULL | |
| return_date | date | YES | | NULL | |
+---------------+------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM checkouts;


+-------------+-----------+---------+---------------+-------------+
| checkout_id | member_id | book_id | checkout_date | return_date |
+-------------+-----------+---------+---------------+-------------+
| 1| 1| 1 | 2023-01-15 | 2023-02-15 |
| 2| 2| 2 | 2023-01-20 | 2023-02-20 |
+-------------+-----------+---------+---------------+-------------+
2 rows in set (0.00 sec)

Output:
Result :
Successfully designed and implemented the Library Management System.
Experiment-7
Objective: Design and Implementation of Student Information System
Theory:
MySQL, a relational database management system (RDBMS), is crucial for storing,
managing, and retrieving data. It facilitates the creation of database structures, ensures data
integrity, and supports CRUD operations—enabling data insertion and deletion through
SQL queries.
Implementation
mysql> CREATE DATABASE student_information_system;
Query OK, 1 row affected (0.00 sec)
mysql> USE student_information_system;
Database changed
mysql> CREATE TABLE students (
-> student_id INT PRIMARY KEY,
-> first_name VARCHAR(50),
-> last_name VARCHAR(50),
-> date_of_birth DATE,
-> email VARCHAR(100),
-> phone_number VARCHAR(15)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE courses (
-> course_id INT PRIMARY KEY,
-> course_name VARCHAR(100),
-> credit_hours INT
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE enrollments (
-> enrollment_id INT PRIMARY KEY,
-> student_id INT,
-> course_id INT,
-> enrollment_date DATE,
-> grade VARCHAR(2),
-> FOREIGN KEY (student_id) REFERENCES students(student_id),
-> FOREIGN KEY (course_id) REFERENCES courses(course_id)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO students VALUES
-> (1, 'John', 'Doe', '1998-05-20', 'john.doe@email.com', '123-456-7890'),
-> (2, 'Alice', 'Johnson', '1999-03-15', 'alice@email.com', '987-654-3210');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO courses VALUES
-> (1, 'Introduction to Computer Science', 3),
-> (2, 'Linear Algebra', 4);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO enrollments VALUES
-> (1, 1, 1, '2023-01-15', 'A'),
-> (2, 2, 2, '2023-01-20', 'B');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> DESCRIBE students
-> ;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| student_id | int | NO | PRI | NULL | |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| date_of_birth | date | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| phone_number | varchar(15) | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> DESCRIBE courses ;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| course_id | int | NO | PRI | NULL | |
| course_name | varchar(100) | YES | | NULL | |
| credit_hours | int | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> DESCRIBE enrollments ;


+-----------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+------------+------+-----+---------+-------+
| enrollment_id | int | NO | PRI | NULL | |
| student_id | int | YES | MUL | NULL | |
| course_id | int | YES | MUL | NULL | |
| enrollment_date | date | YES | | NULL | |
| grade | varchar(2) | YES | | NULL | |
+-----------------+------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM students;


+------------+------------+-----------+---------------+--------------------+--------------+
| student_id | first_name | last_name | date_of_birth | email | phone_number |
+------------+------------+-----------+---------------+--------------------+--------------+
| 1 | John | Doe | 1998-05-20 | john.doe@email.com | 123-456-7890 |
| 2 | Alice | Johnson | 1999-03-15 | alice@email.com | 987-654-3210 |
+------------+------------+-----------+---------------+--------------------+--------------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM courses;


+-----------+----------------------------------+--------------+
| course_id | course_name | credit_hours |
+-----------+----------------------------------+--------------+
| 1 | Introduction to Computer Science | 3|
| 2 | Linear Algebra | 4|
+-----------+----------------------------------+--------------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM enrollments;


+---------------+------------+-----------+-----------------+-------+
| enrollment_id | student_id | course_id | enrollment_date | grade |
+---------------+------------+-----------+-----------------+-------+
| 1| 1| 1 | 2023-01-15 |A |
| 2| 2| 2 | 2023-01-20 |B |
+---------------+------------+-----------+-----------------+-------+
2 rows in set (0.00 sec)
Output:
Result :
Successfully designed and implemented the Student Information System.
Experiment-8
Objective: Writing SQL Statements using MySQLfor Creating Cursor
Theory:
In MySQL, a cursor is a database object used for traversing records in a result set. It
allows sequential processing of data. Cursors are employed for complex queries and
data manipulation.
Implementation :
mysql> CREATE DATABASE my_database;
Query OK, 1 row affected (0.00 sec)

mysql> USE my_database;


Database changed
mysql> CREATE TABLE my_table (
-> id INT PRIMARY KEY,
-> name VARCHAR(50)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO my_table VALUES


-> (1, 'John'),
-> (2, 'Alice'),
-> (3, 'Bob');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> DELIMITER //
mysql> CREATE PROCEDURE my_cursor_demo()
-> BEGIN
-> -- Declare variables for cursor
-> DECLARE done BOOLEAN DEFAULT FALSE;
-> DECLARE id_val INT;
-> DECLARE name_val VARCHAR(50);
->
-> -- Declare the cursor
-> DECLARE my_cursor CURSOR FOR
-> SELECT id, name FROM my_table;
->
-> -- Declare continue handler to exit the loop
-> DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
->
-> -- Open the cursor
-> OPEN my_cursor;
->
-> -- Start fetching rows from the cursor
-> FETCH FROM my_cursor INTO id_val, name_val;
->
-> -- Loop through the result set
-> my_loop: LOOP
-> -- Check if no more rows
-> IF done THEN
-> LEAVE my_loop;
-> END IF;
->
-> -- Process the current row (you can perform any operation here)
-> SELECT id_val, name_val;
->
-> -- Fetch the next row
-> FETCH FROM my_cursor INTO id_val, name_val;
-> END LOOP;
->
-> -- Close the cursor
-> CLOSE my_cursor;
-> END //
Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> DELIMITER ;
mysql>
mysql> -- Call the stored procedure
mysql> CALL my_cursor_demo();
+--------+----------+
| id_val | name_val |
+--------+----------+
| 1 | John |
+--------+----------+
1 row in set (0.01 sec)

+--------+----------+
| id_val | name_val |
+--------+----------+
| 2 | Alice |
+--------+----------+
1 row in set (0.01 sec)

+--------+----------+
| id_val | name_val |
+--------+----------+
| 3 | Bob |
+--------+----------+
1 row in set (0.01 sec)

Query OK, 0 rows affected (0.01 sec)


Output:
Result :
Successfully implemented and executed MySQL cursor. Demonstrated its
utility in handling complex queries and enhancing data manipulation.
Experiment-9
Objective: Writing SQL Statements using MySQLfor Creating Procedure and
Functions

Theory:
MySQL allows the creation of stored procedures and functions to encapsulate SQL code
for reusability. Procedures are for executing tasks, while functions return values.
Enhances code modularity and efficiency.

Implementation
mysql> -- Create a stored procedure
mysql> DELIMITER //
mysql>
mysql> CREATE PROCEDURE my_procedure_demo()
-> BEGIN
-> -- Procedure logic
-> SELECT 'Hello, this is a stored procedure!' AS Message;
-> END //
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> DELIMITER ;
mysql>
mysql> -- Call the stored procedure
mysql> CALL my_procedure_demo();
+------------------------------------+
| Message |
+------------------------------------+
| Hello, this is a stored procedure! |
+------------------------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Output:

Result:
Successfully implemented MySQL stored procedures and functions

Experiment-10
Objective: Design and Development of Data Application for Hospital
Management System

Theory:
MySQL, a Relational Database Management System (RDBMS), is essential for
creating robust databases. It ensures data integrity and facilitates efficient data
retrieval. MySQL concepts include schema design, normalization, stored
procedures, triggers, and CRUD operations, enhancing seamless data management.

Implementation
mysql> CREATE DATABASE hospital_management_system;
Query OK, 1 row affected (0.01 sec)
mysql> USE hospital_management_system;
Database changed
mysql> CREATE TABLE patients (
-> patient_id INT PRIMARY KEY,
-> first_name VARCHAR(50),
-> last_name VARCHAR(50),
-> date_of_birth DATE,
-> gender VARCHAR(10),
-> contact_number VARCHAR(15),
-> address VARCHAR(100)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE doctors (
-> doctor_id INT PRIMARY KEY,
-> first_name VARCHAR(50),
-> last_name VARCHAR(50),
-> specialization VARCHAR(50),
-> contact_number VARCHAR(15),
-> email VARCHAR(100)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE appointments (
-> appointment_id INT PRIMARY KEY,
-> patient_id INT,
-> doctor_id INT,
-> appointment_date DATETIME,
-> status VARCHAR(20),
-> FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
-> FOREIGN KEY (doctor_id) REFERENCES doctors(doctor_id)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE medical_records (
-> record_id INT PRIMARY KEY,
-> patient_id INT,
-> doctor_id INT,
-> diagnosis TEXT,
-> prescription TEXT,
-> appointment_id INT,
-> FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
-> FOREIGN KEY (doctor_id) REFERENCES doctors(doctor_id),
-> FOREIGN KEY (appointment_id) REFERENCES
appointments(appointment_id)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO patients VALUES
-> (1, 'John', 'Doe', '1990-01-15', 'Male', '123-456-7890', '123 Main St, City'),
-> (2, 'Alice', 'Johnson', '1985-05-20', 'Female', '987-654-3210', '456 Oak St, Town');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO doctors VALUES
-> (1, 'Dr. Smith', 'Cardiologist', 'Cardiology Department', '555-1234',
'dr.smith@example.com'),
-> (2, 'Dr. Patel', 'Orthopedic Surgeon', 'Orthopedic Department', '555-5678',
'dr.patel@example.com');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT INTO appointments VALUES


-> (1, 1, 1, '2023-01-15 10:00:00', 'Confirmed'),
-> (2, 2, 2, '2023-01-20 14:30:00', 'Confirmed');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT INTO medical_records VALUES


-> (1, 1, 1, 'Cardiac issue', 'Prescription for heart medication', 1),
-> (2, 2, 2, 'Fractured leg', 'Prescription for pain relief and rest', 2);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM patients;


+------------+------------+-----------+---------------+--------+----------------+-------------------+
| patient_id | first_name | last_name | date_of_birth | gender | contact_number | address
|
+------------+------------+-----------+---------------+--------+----------------+-------------------+
| 1 | John | Doe | 1990-01-15 | Male | 123-456-7890 | 123 Main St, City |
| 2 | Alice | Johnson | 1985-05-20 | Female | 987-654-3210 | 456 Oak St,
Town |
+------------+------------+-----------+---------------+--------+----------------+-------------------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM doctors;
+-----------+------------+--------------------+-----------------------+----------------+---------------
-------+
| doctor_id | first_name | last_name | specialization | contact_number | email
|
+-----------+------------+--------------------+-----------------------+----------------+---------------
-------+
| 1 | Dr. Smith | Cardiologist | Cardiology Department | 555-1234 |
dr.smith@example.com |
| 2 | Dr. Patel | Orthopedic Surgeon | Orthopedic Department | 555-5678 |
dr.patel@example.com |
+-----------+------------+--------------------+-----------------------+----------------+---------------
-------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM appointments;


+----------------+------------+-----------+---------------------+-----------+
| appointment_id | patient_id | doctor_id | appointment_date | status |
+----------------+------------+-----------+---------------------+-----------+
| 1| 1| 1 | 2023-01-15 10:00:00 | Confirmed |
| 2| 2| 2 | 2023-01-20 14:30:00 | Confirmed |
+----------------+------------+-----------+---------------------+-----------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM medical_records;


+-----------+------------+-----------+---------------+---------------------------------------+---------
-------+
| record_id | patient_id | doctor_id | diagnosis | prescription |
appointment_id |
+-----------+------------+-----------+---------------+---------------------------------------+---------
-------+
| 1| 1| 1 | Cardiac issue | Prescription for heart medication | 1|
| 2| 2| 2 | Fractured leg | Prescription for pain relief and rest | 2|
+-----------+------------+-----------+---------------+---------------------------------------+---------
-------+
2 rows in set (0.00 sec)
Output:
Result :
Successfully designed and implemented the Hospital Management System.

You might also like