Harsh Dbms File
Harsh Dbms File
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.
(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.
(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.
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.
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
Tables creation
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.
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.
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 TRUNCATE TABLE command deletes the data inside a table, but not the table itself.
truncate table customer;
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
Query To Display All Records Of Table Based On Pattern Matches using LIKE
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
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.
Method: -
To perform the following functions let us take a table STUDENTS. which contain
information of students such as ID, NAME, AGE, MARKS.
The MAX () function returns the largest value of the selected 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.
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.
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.
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.
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
EXPERIMENT- 9
Title: - A trigger is a stored procedure in database which automatically invokes whenever a special
event in the database occurs
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.
BEFORE triggers run the trigger action before the triggering statement is run.
AFTER TRIGGER:
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.
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.
Employee table –
RESULT: -
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.
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
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.