Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore

Shri Vaishnav Institute of Information Technology

EXPERIMENT - 1
Title: - MySQL is one of the most popular relational database management software that is widely
used in today's industry. It provides multi-user access support with various storage engines. It is
backed by Oracle Company. We are going to download and install MySQL.

Outcome: - My SQL will be successfully installed on our computer.


Objectives: - Installation of MySQL.
Steps: - Download MySQL
(1)- Go to the official website of MySQL and download the community server edition
software.Here, you will see the option to choose the Operating System, such as
Windows.

(2)- Next, there are two options available to download the setup. Choose the version number
for the MySQL community server, which you want. If you have good internet connectivity,
then choose theMySQL-installer-web-community. Otherwise, choose the other one.

Installing MySQL on Windows


(1)- After downloading the setup, unzip it anywhere and double click the MSI installer .exe file.

(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 product and features. select the Full option
and click on the Next button.
This option will install the following things: MySQL Server, MySQL Shell, MySQL Router,
MySQL Workbench, MySQL Connectors, documentation, samples and examples, and many
more.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

(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. We can resolve them by clicking on the
Execute button that will install all requirements automatically or can skip them. Now, click on the
Next button.

(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.

After clicking on the Yes button, we will see the list of the products which are going to be installed.
So, if we need all products, click on the Execute button.

(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.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

(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. We are going to show you
how to configure the server only. Now, click on the Next button.

(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. Now, choose the Standalone MySQL Server/Classic MySQL
Replication option and click on Next. Here, you can also choose the InnoDB Cluster based on your
needs.

(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.

(9)- Now, select the Authentication Method and click on Next. Here, I am going to select the first
option.

(10)- The next screen will ask you to mention the MySQL Root Password. After filling in the
password details, click on the Next button.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
(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.

(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.

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

(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.

(15)- In the next wizard, we can choose to configure the Router. So, click on Next->Finish and
then click the Next button.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

(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.

In this screen, it is also required to check about the connection is successful or not by clicking on
the Check button. If the connection is successful, click on the Execute button. Now, the
configuration is complete, click on Next.

(17)- In the next wizard, select the applied configurations and click on the Execute button.

(18)- After completing the above step, we will get the following screen. Here, click on the Finish
button.

(19)- Now, the MySQL installation is complete. Click on the Finish button.

Result: - MySQL is successfully installed in our windows computer.

VIVA QUESTIONS - 1. - What are different installation options available in MySQL?


2. How does the MySQL installer simplify the installation process?
3. Can you explain the purpose of MySQL server instance configuration wizard?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
EXPERIMENT- 2
Title: - A database is an organized collection of data, so that it can be easily accessed and
managed.
You can organize data into tables, rows, columns, and index it to make it easier to find relevant
information.

Outcome: - After performing this experiment we will be able to create Databases and tables for
those Databases.
Objective: -To Design a Database and create required tables. For e.g., Bank, College Database.

Nomenclature: - Database-A database is an organized collection of structured information, or data,


typically stored electronically in a computer system.
DBMS - A database is usually controlled by a database management system (DBMS).
Table - A collection of closely related columns. A table consists of rows each of which shares the same
columns but vary in the column values.
Relational Model – A database in which inter-table relationships are organized primarily through
common data columns, which define a one-to-many relationship between a row of the primary key table
and one or more rows of the matching foreign key table.

Method: - For Bank database Creation


Use Query “create database bank;”
Now to use the database we have created.
Use Query “use bank;”
Now we are inside the bank database which we created earlier.
Now we will create suitable tables for bank database like customer details, branch details
and course details.
For table creation
Customer table-
Use query “create table customer (cust_name varchar (20) not null, street varchar (20) not
null, city varchar (20) not null);”
Branch table-
“Create table branch (branch name varchar(20) not null, assets varchar(20) not null,
branch_city varchar(20) not null);”

Deposit table-
“create table deposit(cust_name varchar(20) not null,branch_name varchar(20) not
null, account_no int not null, balance int not null);”.

Borrow table-
“create table borrow(cust_name varchar(20) not null,branch_name varchar(20) not null,
loan_no int not null, balance int not null);”

Results: - The database bank and the table related to it ( customer, branch, deposit, borrow)
havebeen created.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

Database creation and selection

Tables creation

VIVA QUESTIONS:- 1. Which type of database management system is MySQL?


2. What are the various types of relationships in Database? Define them
3. What do you understand by ‘Database’?
4. What are the advantages of DBMS over traditional file-based system
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT – 3
Title: - The PRIMARY KEY constraint consists of one column or multiple columns with values
that uniquely identify each row in the table. A NOT NULL constraint in SQL is used to prevent
inserting NULL values into the specified column, considering it as a not accepted value for that
column. A foreign key is a column or group of columns in a relational database table that provides
a link between data in two tables.

Outcome: - At the end of the experiment we will be able to apply primary key, foreign key and
Not Null constraints.

Objective: - To Apply the constraints like Primary Key, Foreign key, NOT NULL to the tables.

Method: - PRIMARY KEY-

The PRIMARY KEY constraint uniquely identifies each record in a table.Primary keys must
contain UNIQUE values and cannot contain NULL values. A table can have only ONE primary
key; and in the table, this primary key can consist of single or multiple columns (fields).

Now we will create a PRIMARY KEY on the “ID” column when the “Persons” table is created:
Create table persons(
ID int not null, LastName varchar(255) not null, firstName varchar(225), Age int, primary key
(ID)
);

FOREIGN KEY -

The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY
KEY in another table. The table with the foreign key is called the child table, and the table with
the primary key is called the referenced or parent table.

Now we will create a FOREIGN KEY on the "PersonID" column when the "Orders" table is
created:
CREATE TABLE Orders(
OrderID int NOT NULL, OrderNumber int NOT NULL, ID int, PRIMARY KEY
(OrderID), FOREIGN KEY (ID) REFERENCES Persons(ID)
);

NOT NULL -
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT
accept NULL values. This enforces a field to always contain a value, which means that you cannot
insert a new record, or update a record without adding a value to this field.
We already used not null in the field which were candidates for PRIMARY KEY.

RESULT –

VIVA QUESTIONS: - 1. What are super, primary, candidate, and foreign keys?
2. What is the purpose of constraints in DBMS?
3. What is the function of the Primary key ?
4. Why do we use NOTNULL Constraints in DBMS?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT – 4
Title: - Data Definition Language, shortly termed DDL, is a subset of SQL commands that define
the structure or schema of the database like alter, drop, update.
Data Manipulation Language, shortly termed DML, is an element in SQL language that deals with
managing and manipulating data in the database like select, insert, update, delete.

Outcome: - we will be able to perform some of the DDL and DML Queries.

Objective: - To Write a SQL statement for table and record handling like implementing INSERT
statement, Using SELECT and INSERT together, DELETE, UPDATE, TRUNCATE statements,
and DROP, ALTER statements.

Nomenclature:- DDL- Data Definition Language, shortly termed DDL, is a subset of SQL commands
that define the structure or schema of the database like alter, drop, update.
DML-Data Manipulation Language, shortly termed DML, is an element in SQL language that deals with
managing and manipulating data in the database like select, insert, update, delete.

Method – First we will use insert query.


“create table customer(cust_name varchar(20) not null, street varchar(20) not null, city
varchar(20) not null);”
insert into customer value('Amit', 'MG Road', 'Indore');
insert into customer value('Arpit', 'Bus Stand', 'Bhopal');
insert into customer value('Saurabh', 'Railway Station', 'Dewas');
insert into customer value('Neema', 'Central Library', 'Rewa');

The UPDATE statement is used to modify the existing records in a table.


“update customer set cust_name= 'Harsh’, street='Mill Road' where
city= 'Indore';”
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
The updated table will be:

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing
table.
To ALTER TABLE “alter table customer add email varchar(30);”

The DELETE statement is used to delete existing records in a table.delete from

“delete from customer where city='Indore';”


Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

The TRUNCATE TABLE command deletes the data inside a table, but not the table itself.
truncate table customer;

The DROP TABLE command deletes a table in the database.

VIVA QUESTIONS:- 1. What is DDL (Data Definition Language)?


2. What is DML (Data Manipulation Language)?
3. Explain the functionality of DML Compiler.
4. Define the Two types of DML?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
EXPERIMENT- 5
Title: - A clause in SQL is a built-in function that helps to fetch the required records from a
database table. A clause receives a conditional expression, i.e., a column name or some terms
involving the columns. The clause calculates the result based on the given statements in the
expression.

Outcome: - after the completion of this experiment we will be able to use clauses in MySQL.

Objective: - To Write the queries for Retrieving Data from a Database Using the WHERE clause,
Using Logical Operators in the WHERE clause , Using IN, BETWEEN, LIKE , ORDER BY,
GROUP BY and HAVING Clause, Using Aggregate Functions and Combining Tables Using
JOINS.

Nomenclature:- Clause - A clause in SQL is a built-in function that helps to fetch the required records
from a database table.
Where-The SQL WHERE Clause. The WHERE clause is used to filter records. It is used to extract only
those records that fulfill a specified condition.
Order by -The ORDER BY keyword sorts the records in ascending order by default. To sort the records
in descending order, use the DESC keyword.
Group by -The GROUP BY statement groups rows that have the same values into summary rows, like
"find the number of customers in each country".

Method: -
SQL Query To Display All Records Of Table Using Where Clause

SQL Query To Display Selected Fields Of Table Using Where


Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
Query To Display All Records from Table Using Logical Operators.

Query To Display Records of Table Using IN.

Query To Display All Records from Table Using Logical Operators.

Query To Display All Records Of Table Based On Pattern Matches using LIKE
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

Query To Display All Records Using Order by Clause.

Query To Display All Records Using Group by Clause.


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 withaggregate
functions (COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more
columns.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

Query to demonstrate use of Having clause.

Queries to demonstrate some aggregate functions.


Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

JOIN is an SQL clause used to query and access data from multiple tables, based on logical
relationships between those tables. In other words, JOINS indicate how SQL Server should use
data from one table to select the rows from another table

QUERY TO JOIN 2 TABLES

VIVA QUESTIONS - 1. What are Clauses in dbms?


2. How do we use where clause in dbms?
3. Explain the functionality of Group By ?
4. How to print in descending or using order by?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT- 6
Title: - SQL aggregation function is used to perform the calculations on
multiple rows of a single column of a table. It returns a single value. It is also used
to summarize the data.

Outcome: - After this experiment we will be able to perform MIN, MAX,


COUNT and AVG functions.

Objective: - To Write the query for implementing the following functions:


MAX (), MIN (), AVG (), COUNT ().

Method: -
To perform the following functions let us take a table STUDENTS. which contain
information of students such as ID, NAME, AGE, MARKS.

The SQL MIN () and MAX () Functions


The MIN () function returns the smallest value of the selected column.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

The MAX () function returns the largest value of the selected column

The AVG () function returns the average value of a numeric column.

The COUNT () function returns the number of rows that matches a specified criterion.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT-7
Title: - Integrity constraints are a set of rules. It is used to maintain the quality of
information. Integrity constraints ensure that the data insertion, updating, and other
processes must be performed in such a way that data integrity is not affected. Thus,
integrity constraint is used to guard against accidental damage tothe database.

Outcome: - we will be able to understand and perform queries for integrity


constraints.

Objective: - To Write the query to implement the concept of Integrity constraints.

Nomenclature: - Integrity constraints- Integrity constraints are a set of rules. It is used to


maintain the quality of information.
Domain constraints- Domain constraints can be defined as the definition of a valid set of values
for an attribute.
Entity Integrity Constraints: The entity integrity constraint states that primary key value can’t be
null.
Method: -
In Database Management Systems, integrity constraints are pre-defined set of rules that
are applied on the table fields(columns) or relations to ensure that the overall validity,
integrity, and consistency of the data present in the database table is maintained.
Evaluation of all the conditions or rules mentioned in the integrity constraint is done
every time a table insert, update, delete, or alter operation is performed. The data can be
inserted, updated, deleted, or altered only if the result of the constraint comes out to be
True. Thus, integrity constraints are useful in preventing any accidental damage to the
database by anauthorized user.
Types of Integrity Constraints
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
1. Domain Constraints:
Domain constraints can be defined as the definition of a valid set of values for an
attribute.
The data type of domain includes string, character, integer, time, date, currency,
etc. The value of the attribute must be available in the corresponding domain.
Here, we are making a person table –
create table person(per_id int,per_name varchar(20),Age int);
and inserting some values

Now the “Age” field is restricted for integer values only and we are trying to add
character into that field. So, it is showing error.

2. Entity Integrity Constraints:


The entity integrity constraint states that primary key value can’t be null. This is
because the primary key value is used to identify individual rows in relation and if the
primary key has a null value, then we can’t identify those rows. A table can contain a null
value other than the primary key field.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
Now if we try to add null value in the PRIMARY KEY field (per_id) there will be an
error.

3. Referential Integrity Constraints:

A referential integrity constraint is specified between two tables. In the Referential


integrity constraints, if a foreign key in Table 1 refers to the Primary Key of Table 2, then
every value of the Foreign Key in Table 1 must be null or be available in Table 2.

Let’s make two table a and b and “aid” is a column which is primary key of table a and
foreign key of table b;
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

Inserting a value in b with “aid” does not present in a will give an error.

4. Key Constraints:

Keys are the entity set that is used to identify an entity within its entity set uniquely. An
entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.

Let us make a table person. With “p_id” as UNIQUE KEY


Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology
Let’s insert some data into this table.

It will prevent us from entering any duplicate key in “p_id” column.

VIVA QUESTIONS - 1. Why do we use integrity constraints?


2. Define the types of integrity constraints?
3. What is the function of Domain Constraint?
4. Explain Entity Integrity constraints?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT- 8
Title: - Views in SQL are considered as a virtual table. A view also contains rows and
columns.
Outcome: - we will be able to create views.

Objective: - To Write the query to create the views.

Nomenclature: - Views- Views in SQL are considered as a

virtual table. A view also contains rows and columns.

Table- Table is structure of Rows and Columns.

Method: -

To create the view, we can select the fields from one or more tables present in the database. A view
can either have specific rows based on certain condition or all the rows of a table.
let us take sample table: person

Creating View “detail”

VIVA QUESTIONS: - 1. What is View in DBMS?


2. Explain how View is different from regular table in DBMS?
3. What is the function of view?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT- 9
Title: - A trigger is a stored procedure in database which automatically invokes whenever a special
event in the database occurs

Outcome: - we will be able to perform trigger queries in MySQL.

Objective: - To Perform the queries for triggers.


Nomenclature: - Trigger- A trigger is a stored procedure in database which automatically invokes
whenever a special event in the database occurs.
Table- Table is a structure of rows and columns.
VIEW- Views in SQL are considered as a virtual table. A view also contains rows and columns.

Method: -
A trigger is a stored procedure in database which automatically invokes whenever a special event
in the database occurs. For example, a trigger can be invoked when a row is inserted into a specified
table or when certain table columns are being updated.
Let us take a sample table: student1.

Now, BEFORE TRIGGER:

BEFORE triggers run the trigger action before the triggering statement is run.

CREATING TRIGGER WITH INSERT STATEMENT


Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

INSERTING INTO student AFTER CREATING ‘stu_sem’

#semester value gets incremented by 1.

AFTER TRIGGER:

To use after trigger, we first need to create a new table.

Creating Relation Audit-

Query to use After Trigger –


Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

VIVA QUESTIONS: - 1. Define Trigger.


2.What are the type of Triggers?
3. Explain what is after Trigger?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT- 10
Title: - A cursor in SQL is a database object stored in temp memory and used to work with
datasets. You can use cursors to manipulate data in a database, one row at a time.

Outcome: - we will be able to use a curser.

Objective: - To Display name, hire date of all employees using cursor.

Nomenclature: - Cursor- A cursor in SQL is a database object stored in temp memory and used to work
with datasets.
Implicit Cursors: Implicit Cursors are also known as Default Cursors of SQL SERVER. These Cursors
are allocated by SQL SERVER when the user performs. DML operations.
Explicit Cursors : Explicit Cursors are Created by Users whenever the user requires them. Explicit
Cursors are used for Fetching data from Table in Row-By Row Manner.

Method: - Cursor is a Temporary Memory or Temporary Workstation. It is Allocated by


Database
Server at the Time of Performing DML(Data Manipulation Language) operations on Table
by User. Cursors are used to store Database Tables. There are 2 types of Cursors: Implicit
Cursors, and Explicit Cursors. These are explained as
following below.
1. Implicit Cursors: Implicit Cursors are also known as Default Cursors of SQL
SERVER. These Cursors are allocated by SQL SERVER when the user performs.
DML operations.
2. Explicit Cursors : Explicit Cursors are Created by Users whenever the user
requires them. Explicit Cursors are used for Fetching data from Table in Row-By Row Manner

Employee table –

Creating MySQL Cursor:


In MySQL, Cursor can also be created. Following are the steps for creating a
cursor.
Declare Cursor: -A cursor is a select statement, defined in the declaration section
in MySQL.
Open Cursor: -After declaring the cursor the next step is to open the cursor using
Fetch Cursor: - After declaring and opening the cursor, the next step is to fetch
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

the cursor. It is used to fetch the row or the column.


Close Cursor: -The final step is to close the cursor.

RESULT: -

VIVA QUESTIONS:- 1. What is Cursor in SQL?


2. Explain the types of cursors?
3. Explain implicit cursor in detail?
4. What is the limitations of cursor?
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

EXPERIMENT- 11
Title: - DCL commands are used to enforce database security in a multiple user database
environment. Two types of DCL commands are GRANT and REVOKE. Only Database
Administrator's or owners of the database object can provide/remove privileges on a database
object.
Outcome: - we will be able to use GRANT and REVOKE commands to give and take
permissions from users.

Objective: -Write the query for creating the users and their role. Using GRANT and REVOKE
operations.

Nomenclature: - Grant-SQL Grant command is specifically used to provide privileges to database


objects for a user.
Revoke- Revoke command withdraw user privileges on database objects if any granted.
User- The USER returns the current user’s name and host name for the MySQL connection.
Method: -
Creating a New User
CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';

SQL GRANT Command


SQL GRANT is a command used to provide access or privileges on the database objects to the
users. You can grant users various privileges to tables. These permissions can be any combination
of SELECT, INSERT, UPDATE, DELETE, REFERENCES, ALTER, or ALL.

First, we will create a role then we will grant permission to that role.
Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
Shri Vaishnav Institute of Information Technology

Revoke Privileges on Table

Once you have granted privileges, you may need to revoke some or all of these privileges. To do
this, you can run a revoke command. You can revoke any combination of SELECT, INSERT,
UPDATE, DELETE, REFERENCES, ALTER, or ALL.

Here, we have created new users, new roles and then granted those roles new privileges.
And then Revoked those privileges.

VIVA QUESTIONS:- 1.What is the purpose of Grant?


2. Difference between Grant and revoke.
3.Define revoke .
4. How do we give privileges in SQL?

You might also like