Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views19 pages

DBMS Lab

The document provides an introduction to MySQL, a relational database management system that is open-source and ideal for various applications. It details the installation process of MySQL, including steps to configure the server and create databases and tables, as well as the use of SQL commands for data manipulation. Additionally, it covers data types, retrieval of rows, and various SQL statements such as CREATE, SELECT, ALTER, and DROP.

Uploaded by

Rohit Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views19 pages

DBMS Lab

The document provides an introduction to MySQL, a relational database management system that is open-source and ideal for various applications. It details the installation process of MySQL, including steps to configure the server and create databases and tables, as well as the use of SQL commands for data manipulation. Additionally, it covers data types, retrieval of rows, and various SQL statements such as CREATE, SELECT, ALTER, and DROP.

Uploaded by

Rohit Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Database Management Systems Lab Rohit kumar

BTCS 505-18 2224525


Practical 01. Introduction to MySQL and Installation of MySQL.
A Database Management System (DBMS) is a software system that is designed to manage
and organize data in a structured manner. It allows users to create, modify, and query a
database, as well as manage the security and access controls for that database.
DBMS provides an environment to store and retrieve the data in convenient and efficient
manner.
 MySQL is a relational database management system
 MySQL is open-source
 MySQL is free
 MySQL is ideal for both small and large applications
 MySQL is very fast, reliable, scalable, and easy to use
 MySQL is cross-platform
 MySQL is compliant with the ANSI SQL standard
 MySQL was first released in 1995
 MySQL is developed, distributed, and supported by Oracle Corporation
 MySQL is named after co-founder Monty Widenius's daughter: My
 Uses of MySQL :-
 Huge websites like Facebook, Twitter, Airbnb, Booking.com, Uber, GitHub, YouTube,
etc.
 Content Management Systems like WordPress, Drupal, Joomla!, Contao, etc.
 A very large number of web developers around the world

 Installation of MySQL server.


Step 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.
Step 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 the mysql-installer-web-community. Otherwise,
choose the other one.

1
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

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 product and features.
Here, we are going to 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.

2
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

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

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.

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.

3
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
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.
We are going to show you how to configure the server only. Now, click on the Next
button.

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. Now, choose the Standalone MySQL

4
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
Server/Classic MySQL Replication option and click on Next. Here, you can also
choose the InnoDB Cluster based on your needs.

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.

5
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

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

6
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
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.

7
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

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.

8
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

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.

9
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

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

10
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

Step 19: Now, the MySQL installation is complete. Click on the Finish button.

Practical 02. Data Types, Creating Tables, Retrieval of Rows using Select
Statement, Conditional Retrieval of Rows, Alter and Drop Statements.
Data Types :- In a Database Management System (DBMS), a data type is a classification that
specifies the type of data that a column can hold in a database table. It defines the kind of
value and the operations that can be performed on that data. Data types are crucial because
they inform the DBMS how much physical storage to allocate for the data and how to
interpret bit patterns representing the data.
Key Functions of Data Types in DBMS:-
1. Data Integrity and Validation:
o Ensure that only valid data is stored in the database.

o Prevent insertion of invalid data types, enhancing data reliability.

2. Storage Optimization:
o Optimize the use of disk space by allocating appropriate storage sizes.

o Different data types consume different amounts of storage.

3. Performance Enhancement:

11
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
o Improve query execution speed through proper indexing and data retrieval
methods.
o Facilitate efficient data manipulation and processing.

4. Data Interpretation:
o Help the DBMS understand how to process and display the stored data.

o Define the permissible operations (e.g., arithmetic on numbers, concatenation


on strings).
Common Categories of Data Types:-
1. Numeric Data Types:
o Store numerical values.

o Examples: INTEGER, SMALLINT, FLOAT, DOUBLE, DECIMAL.

2. Character/String Data Types:


o Store alphanumeric characters and text.

o Examples: CHAR(n), VARCHAR(n), TEXT, CLOB.

3. Date and Time Data Types:


o Store dates, times, and timestamps.

o Examples: DATE, TIME, TIMESTAMP, DATETIME.

4. Binary Data Types:


o Store binary data such as images or files.

o Examples: BLOB, BINARY, VARBINARY.

5. Boolean Data Types:


o Store logical values.

o Examples: BOOLEAN, storing TRUE or FALSE.

6. Spatial Data Types:


o Store geometric data.

o Examples: GEOMETRY, POINT, LINESTRING, POLYGON.

7. JSON and XML Data Types:


o Store structured data in JSON or XML format.

o Examples: JSON, XML.

12
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
 Creating Tables, Retrieval of Rows using Select Statement, Conditional Retrieval
of Rows, Alter and Drop Statements :-
Create Database :- To create a database in MySQL, you use the CREATE DATABASE
statement. Optionally, you can specify the character set and collation for the database.
Syntax :- create database database_name;
Example :- create database rohan;
Show Database :- The SHOW DATABASES statement in MySQL is used to display all
databases that exist on the MySQL server to which the user is connected. It provides a list of
all databases that the user has access to, based on their permissions.
Syntax :- show databases;

Use Database :- The USE statement in MySQL is used to select a particular database to work
with. After executing the USE command, all subsequent SQL queries will apply to the
selected database unless another database is explicitly specified. It essentially sets the default
database for the current session.
Syntax :- use database_name;
Example :- use rohan;
Create Table :- The CREATE TABLE statement in MySQL is used to create a new table in a
database. A table consists of rows and columns, where each column represents a specific data
field, and each row is a record. The table is structured with defined data types, constraints,
and optional parameters like indexing or auto-incrementing.
Syntax :- create table table_name ( column_name1 data_type [constraint], column_name2
data_type [constraint], ... [table_constraints] );
Example :- create table allstudent(id int,fullname varchar(20),address varchar(30),class
varchar(10),age int,dob date);
Show Tables :- The SHOW TABLES statement in MySQL is used to list all the tables in the
currently selected database. This command provides an overview of the available tables and
helps in identifying the structure of the database.

13
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
Syntax :- show tables;

Insertion :- The INSERT statement in MySQL is used to add new rows (records) to a table.
You can insert a single row or multiple rows at once. The values provided in the INSERT
statement must match the order and data types of the columns in the table.
Syntax :- insert into table_name values (value1, value2, value3, ...);
Example :-
insert into allstudent values(100,"Rohan Kumar","Bihar","CSE",21,'2001-10-9');
insert into allstudent values(101,"Ritik Kumar","Bihar","CSE",20,'2001-10-10');
insert into allstudent values(102,"Rajeev Kumar","Bihar","CSE",19,'2003-10-9');
insert into allstudent values(103,"Rishav Kumar","Bihar","CSE",21,'2001-8-9');
insert into allstudent values(104,"Ranjan Kumar","Bihar","CSE",20,'2002-10-9');
insert into allstudent values(105,"Rohan Raj","Punjab","CSE",22,'2001-8-4');
insert into allstudent values(106,"Ritesh Kumar","Patna","CSE",20,'2004-10-9');
insert into allstudent values(107,"Raj Kumar","Jaypur","CSE",21,'2001-8-9');
insert into allstudent values(108,"Robin","USA","CSE",21,'2003-10-9');
insert into allstudent values(109,"Roshan","Bihar","CSE",22,'2001-10-1');
insert into allstudent values(110,"Ronak Kumar","Bihar","CSE",20,'2003-8-8');
Select Statement :- The SELECT statement in MySQL is used to retrieve data from one or
more tables in a database. The result is stored in a result table (called the result set). The
SELECT statement can be customized to fetch specific columns, filter rows, sort data, group
results, and much more.
Syntax :- select*from table_name;
Example :- select*from allstudent;

14
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

Conditional Retrieval of Rows :- Conditional retrieval of rows in MySQL is done using the
WHERE clause in the SELECT, UPDATE, or DELETE statements. The WHERE clause
filters the rows based on specific conditions or criteria. It retrieves only the rows that meet
the condition(s) specified. You can use a variety of operators and functions to define
conditions, such as comparison operators, logical operators, pattern matching, and more.
Syntax :- select field_name from table_name where field_name = value;
Example :- select fullname from allstudent where fullname = "Rohan Kumar";

Alter Statement :- The ALTER statement in MySQL is used to modify an existing table's
structure. It allows you to add, delete, or modify columns, as well as change other table
properties like indexes, constraints, and even rename the table itself. The ALTER statement is
essential for maintaining the flexibility of a database as the data model evolves over time.
Syntax:-alter table table_name add new_column _name data_type;
Example :-
alter table allstudent add CGPA int;
describe allstudent;

15
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

Drop Statement :- The DROP statement in MySQL is used to delete database objects such as
tables, databases, indexes, or views. Once an object is dropped, it is permanently removed
from the database, including all of its data and associated metadata. The DROP statement is a
powerful command and should be used with caution, as it cannot be rolled back unless you
have a backup.
Syntax :- alter table table_name drop column_name ;
Example:-
alter table allstudent drop CGPA;
describe allstudent;

Syntax :- drop table table_name;


Example :-
Drop table sabhistudent;
show tables;

16
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
Rename :- The RENAME statement in MySQL is used to change the name of a table or a
column. It allows you to update the names of these database objects without having to
recreate them. This can be useful for correcting naming errors, improving naming
conventions, or simply renaming objects to better reflect their purpose.
Syntax :- alter table table_name rename column old_column_name to new_column_name;
Example :-
alter table allstudent rename column class to department;
describe allstudent;

Syntax :- rename table old_table_name to new_table_name;


Example :-
rename table allstudent to sabhistudent;
show tables;

Truncate Statement :- The TRUNCATE statement in MySQL is used to quickly remove all
rows from a table, effectively emptying the table while retaining its structure (schema) for
future use. Unlike the DELETE statement, which removes rows one at a time and can be
slower, TRUNCATE is a more efficient way to clear out large amounts of data. It does not
generate individual row delete operations and typically executes faster.
Syntax :- truncate table table_name;
Example :-
truncate table allstudent;
select*from allstudent;

17
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525

All Code :-
show databases;
use rohan;
create table allstudent(id int,fullname varchar(20),address varchar(30),class varchar(10),age
int,dob date);
insert into allstudent values(100,"Rohan Kumar","Bihar","CSE",21,'2001-10-9');
insert into allstudent values(101,"Ritik Kumar","Bihar","CSE",20,'2001-10-10');
insert into allstudent values(102,"Rajeev Kumar","Bihar","CSE",19,'2003-10-9');
insert into allstudent values(103,"Rishav Kumar","Bihar","CSE",21,'2001-8-9');
insert into allstudent values(104,"Ranjan Kumar","Bihar","CSE",20,'2002-10-9');
insert into allstudent values(105,"Rohan Raj","Punjab","CSE",22,'2001-8-4');
insert into allstudent values(106,"Ritesh Kumar","Patna","CSE",20,'2004-10-9');
insert into allstudent values(107,"Raj Kumar","Jaypur","CSE",21,'2001-8-9');
insert into allstudent values(108,"Robin","USA","CSE",21,'2003-10-9');
insert into allstudent values(109,"Roshan","Bihar","CSE",22,'2001-10-1');
insert into allstudent values(110,"Ronak Kumar","Bihar","CSE",20,'2003-8-8');
show tables;
select*from allstudent;
describe allstudent;
select fullname from allstudent where fullname = "Rohan Kumar";
alter table allstudent add CGPA int;
describe allstudent;
alter table allstudent drop CGPA;
describe allstudent;
alter table allstudent rename column class to department;
describe allstudent;

18
Database Management Systems Lab Rohit kumar
BTCS 505-18 2224525
truncate table allstudent;
describe allstudent;
select*from allstudent;
rename table allstudent to sabhistudent;
show tables;
Drop table sabhistudent;
show tables;

19

You might also like