MySQL Installation
To install the MySQL software, we must use the MySQL official site and download the latest version from the MySQL Community Server as per the requirement of our system.
For this installation, we need the downloaded version of the MySQL which we initially done in the system. from the directory where we have the unzipped files, open Window Explorer and double-click on setup.exe.
The product we want to install is MySQL Server 9.0 Setup Wizard.
First window of MySQL Server 9.0 Setup
We can perform a basic installation with some term acceptance which is End-User License Agreement then go to the next step.
License and Agreement of MySQL Server 9.0 Setup
Now choose the Setup Type as per the requirement, we will go with the Complete Setup Option.
Installation window has been appeared, now simply click on the Install tab.
Ready to Install MySQL Server 9.0
Now our MySQL Server Setup Wizard has been successfully completed. Click on the finish button by giving permission to Run MySQL Configuration with tick icon.
Choose the Setup Type of MySQL Server 9.0
A new window with the name MySQL Configurator will pop out to our system. Go with the each step for the proper functioning of our SQL Server.
Configuration window of MySQL Server 9.0 Setup
Data Directory contains the detail of our work path.
Type and Networking contains the Config Type, we will go with the Development Computer with TCP/IP connectivity Port:3306 and X Protocol Port:33060.
Accounts and Roles of MySQL Server 9.0 Setup
Account and Roles contains the Password Setup for our MySQL Root server. We may also add the user here as our requirement.
With our Username, Password and Database role we will go to the next step.
For Windows Service, we will go with the option as our need.
For Server File Permission, we give full access to the server.
Sample Database contain Create Sakila Database and Create World Database, we will go with both the option.
After applying Configuration, the steps will start to be executed.
Applying Configuration for MySQL Server 9.0 Setup
Now the Configuration completed Finish the window now by clicking on the tab.
For running the SQL Program, we have to download the MySQL Workbench in our system from the same MySQL Official site from the Community Server and select the path where we want to install the Workbench.
Setup for MySQL Workbench 8.0 CE
Click on the Complete Setup type and go to the next step.
Connect to MySQL Server 9.0
Wizard Completed for MySQL Workbench 8.0 CE
After that MySQL Workbench is started to install in the system it will take sometime to install the data. After that the Wizard Completed has been shown in the system.
For connecting the MySQL Server, we have to enter the Password which we created earlier to link it with the MySQL Workbench.
Our SQL Workbench will look like as the below image:
Startup Window of MySQL Workbench
Notes: After installation you can work now on the Workbench to create your Database very efficiently by using DDL and DML Commands.
Experiment 2
Objective: Create a database by using the Following SQL Commands:
create
insert
select
DESCRIBE
Theory
SQL commands are extensively used to interact with databases, enabling users to perform a wide range of actions on database systems. Understanding these commands is crucial for effectively managing and manipulating data.
SQL Commands are mainly categorized into five categories:
DDL: Data Definition Language
DQL: Data Query Language
DML: Data Manipulation Language
DCL: Data Control Language
TCL: Transaction Control Language
create: Create database or its objects (table, index, function, views, store procedure, and triggers).
insert: insert data into a table.
select: Used to retrieve data from a database.
DESCRIBE: Used to display the structure of a table, view, type, procedure, function, package, or synonym.
Output:
Create Table and delete data in Admin 4 (PostgreSQL).
Output:
Alter column and update in Admin 4 (PostgreSQL).
Experiment 3
Objective: Create a database using the following Aggregate Functions:
MIN()MAX()COUNT()SUM()AVG()
Theory:
An aggregate function is a function that performs a calculation on a set of values, and returns a single value.
Aggregate functions ignore null values (except for COUNT()).
The most commonly used SQL aggregate functions are:
min(): returns the smallest value within the selected column.
max(): returns the largest value within the selected column.
sum(): returns the total sum of a numerical column.
avg(): returns the average value of a numerical column.
At first we need to create database.
Output:
Alter column and update in Admin 4 (PostgreSQL).
Alter column and update in Admin 4 (PostgreSQL).
Alter column and update in Admin 4 (PostgreSQL).
Experiment 4
Objective: Create a database using the following SQL Clauses:
ORDER BY
GROUP BY
HAVING Clause
Theory:
SQL clauses help us to retrieve a set or bundles of records from the table. SQL clauses help us to specify a condition on the columns or the records of a table.
The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions COUNT(), MAX(), MIN(), SUM(), AVG() to group the result-set by one or more columns.
The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions
Output:
SQL clause max min function in Admin 4 (PostgreSQL).
SQL clause count function in Admin 4 (PostgreSQL).
Experiment 5
Objective: Create a database using JOIN SQL Commands.
Theory:
A SQL JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Types of SQL JOINs
inner join: Returns records that have matching values in both tables.
left join: Returns all records from the left table, and the matched records from the right table.
right join: Returns all records from the right table, and the matched records from the left table.
full outer join: Returns all records when there is a match in either left or right table.
Students and Course table in Admin 4 (PostgreSQL).
Enrollment table with foreign key in Admin 4 (PostgreSQL).
All joins are same except cross join using Admin 4 (PostgreSQL).
Cross join using Admin 4 (PostgreSQL).
Experiment 6
Objective: Creating Entity-Relationship Diagram.
Theory:
An Entiry-Relationship Diagram (ERD) is a visual representaion of the entities within a database and the relationships betweeen those entities. It is an essential art of database design as it provides a clear and organized structure for the data to be stored, ensuring data integrity and facilitating efficient data retrieval.
There are the following steps to create E-R diagram in Visual Studio (VS) code given below—
Open vs code in the System.
Opening Visual Studio (vs) Code.
Go to extentions tab. Search draw.io and install in vs code.
Install Draw.io Extension in vs code.
Create a file with extenstion .drawio. e.g. test.drawio. A canva and tools automatically open.
Create as .drawio Extension file to open Canva.
Choose the particular section and use the given shapes to create any type of diagram.
Double tap inside the shape, text editor will be open automatically.
Choose different shaps in draw.io canva.
use different shapes and tools edit to desirable diagrams.
Build desirable diagram, wireframs, etc., using it.
Normalization is the process of organizing data in a database to reduce redunedency and improve data integrity. It involves diving large tables into smaller, related tables and defining relationships between them. The main goal of normalization is to eliminate redundant data and ensure data dependencies make sense to improve the overall efficiency and integrity of the database.
Normal Forms:First Normal Form (1NF):
for non-1NF
Non-1NF table fig. (Student-courses).
Ensures that each table has a primary key.
Remove any repeating groups or arrays.
Conevrted into 1 NF table fig. (students).
Second Normal Form (2NF):
for non-2NF
Non-2NF table fig. (Student-courses).
Remove partial dependencies by ensuring that non-key attributes are fully dependent on the primary key.
Conevrted into 2 NF table fig. (students).
Conevrted into 2 NF table fig. (student-courses), (course-teacher).
Third Normal Form (3NF):
for non-3NF
Non-3NF table fig. (Students)
Remove transitive dependencies by ensuring that non-key attributes are not dependent on other non-key attributes.
Conevrted into 3 NF table fig. (students), (branch)
Experiment 8
Objective: Creating Cursor.
Theory:
Cursor in PL/SQL is a databse object used to retrieve and manipulate multiple rows of data in a controlled manner. It allows row-by-row processing of query results. There are two types of Cursor—
Implicit Cursor: Automatically created by PL/SQL for single-row queries.
Explicit Cursor: Defined by the programmer for queries that return multiple rows.
Declare a cursor:student_cursor is declared for the select query.
Creating a cursor for print the student record.
Experiment 9
Objective: Creating Procedure and Functions.
Theory:
Stored Procedures and Functions are PL/SQL constructs used to encapsulate a set of operations or queries to perform specific tasks.
Procedure: A subprogram that performs a specific action but does not return a value.
Function: Similar to a procedure but it returns a single value.
Creating a Procedure: A procedure is a set of SQL and procedural statements that perform a task.
Updating the age in students table with the procedure.
Creating a Function: A function is a set of SQL and procedural statements that perform a task and return a value.
Get the student from the students table with the function.
Experiment 10
Objective: Creating Package and Triggers.
Theory:
Packages in PL/SQL are schema objects that group logically related PL/SQL types, items, and subprograms. They consist of two parts—
Package Specification: Declares the public items that can be referenced outside the package.
Package Body: Defines the code for the subprograms declared in the Specification.
Add the data in existing table with the package function.
Get the name from db with the package function.
Creating a trigger:
A trigger is a stored procedure that automatically executes when certain events occur in the database, such as insert, update, or delete.
The triggerBeforeInsertStudent is defined to execute before an insert operation on the students table.
The trigger body checks a record into the students table, new.student_id is null or not. If null then return raise_application_error.
After changes on students table creating a student_changes_log table.