Dbms Lab File
Dbms Lab File
Practical File of
Submitted To : Submitted By :
Date of
Page Date of Remarks Remarks
SL Name of Experiment no. Experiment
Practical : 1
Prerequisites
The following requirements should be available in your system to work with MySQL:
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
mysqlinstallerwebcounity. Otherwise, choose the other one.
Installing MySQL on Windows
Step 1: After downloading the setup, unzip it anywhere and double click the MSI installer .exe file.
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.
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.
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 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.
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.
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.
Step 19: Now, the MySQL installation is complete. Click on the Finish button.
Verify MySQL installation
Once MySQL has been successfully installed, the base tables have been initialized, and the server has
been started, you can verify its working via some simple tests.
Open your MySQL Command Line Client; it should have appeared with a mysql> prompt. If you have set
any password, write your password here. Now, you are connected to the MySQL server, and you can
execute all the SQL command at mysql> prompt as follows:
For example: Check the already created databases with show databases command:
EXPERIMENT NO. 2
Name of Experiment: Creating Entity-Relationship Diagram using case tools.
Course Name: DBMS Lab Course Code: BCS-551
Branch: CSE Semester: V
Practical -2
An Entity–relationship model (ER model) describes the structure of a database with the help of a
diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER model is a
design or blueprint of a database that can later be implemented as a database.
Practical -3
Objective: Data types in SQL and usage of various Data Definition Language commands
Introduction about SQL-
SQL (Structured Query Language) is a nonprocedural language, you specify what you want, not
how to get it. A block structured format of English key words is used in this Query language. It
has the following components.
DDL (Data Definition Language)-
The SQL DDL provides command for defining relation schemas, deleting relations and
modifying relation schema.
Data Definition Language-
The SQL DDL allows specification of not only a set of relations but also information
Char (n)- A fixed length character length string with user specified length .
• Varchar (n)- A variable character length string with user specified maximum length n.
• Int- An integer.
• Numeric (p, d)-A Fixed point number with user defined precision.
• Real, double precision- Floating point and double precision floating point numbers with
• Date- A calendar date containing a (four digit) year, month and day of the month.
• Time- The time of day, in hours, minutes and seconds Eg. Time ’09:30:00’.
Syntax-
Practical -4
Data constraints: Besides the cell name, cell length and cell data type there are other parameters
i.e. other data constrains that can be passed to the DBA at check creation time. The constraints
can either be placed at column level or at the table level.
i. Column Level Constraints: If the constraints are defined along with the column definition, it
is called a column level constraint.
ii. Table Level Constraints: If the data constraint attached to a specify cell in a table reference
the contents of another cell in the table then the user will have to use table level constraints.
Null Value Concepts:- while creating tables if a row locks a data value for particular column
that value is said to be null . Column of any data types may contain null values unless the
column was defined as not null when the table was created.
Syntax:
Create table tablename (columnname data type (size) not null ……)
Primary Key: primary key is one or more columns is a table used to uniquely identity each row
in the table. Primary key values must not be null and must be unique across the column. A
multicolumn primary key is called composite primary key.
Syntax: primary key as a column constraint
Create table tablename
Default value concept: At the line of cell creation a default value can be assigned to it. When the
user is loading a record with values and leaves this cell empty, the DBA will automatically load
this cell with the default value specified. The data type of the default value should match the
data type of the column .
Syntax:
Foreign Key Concept : Foreign key represents relationship between tables. A foreign key is
column whose values are derived from the primary key of the same of some other table . the
existence of foreign key implies that the table with foreign key is related to the primary key
table from which the foreign key is derived .A foreign key must have corresponding primary
key value in the primary key table to have meaning.
Foreign key as a column constraint
Syntax :
• A check constraints name column of the client_master so that the name is entered in upper case.
• A check constraint on the client_no column of the client _master so that no client_no value starts with
‘c’ Syntax:
Practical -5
• The modification of information stored by the appropriate data model. There are basically two
types.
(i) Procedural DML:- require a user to specify what data are needed and how
(ii) Non Procedural DML : require a user to specify what data are needed
Syntax:
Delete from tablename :
Syntax:
Select column name result_columnname,
Columnname result_columnname,
From table name;
Logical Operators:
The logical operators that can be used in SQL sentenced are
AND all of must be included
OR any of may be included
NOT none of could be included
Range Searching: Between operation is used for range searching.
Pattern Searching:
The most commonly used operation on string is pattern matching using the operation
‘like’ we describe patterns by using two special characters.
• Percent (%) ; the % character matches any substring we consider the following examples.
Oracle functions:
Syntax:
Avg ([distinct/all]n)
Min return minimum value of expr.
Syntax:
MIN((distinct/all )expr)
Count Returns the no of rows where expr is not null
Syntax:
Count ([distinct/all)expr]
Count (*) Returns the no rows in the table, including duplicates and those with nulls.
Max Return max value of expr
Syntax:
Max ([distinct/all]expr) Sum
Syntax:
Sum ([distinct/all]n)
EXPERIMENT NO. 6
Name of Experiment: To implement the concept of Joins and grouping of data.
Course Name: DBMS Lab Course Code: BCS-551
Branch: CSE Semester: V
Practical -6
Joint Multiple Table (Equi Join): Some times we require to treat more than one table as though
manipulate data from all the tables as though the tables were not separate object but one single
entity. To achieve this we have to join tables.Tables are joined on column that have dame data
type and data with in tables.
The tables that have to be joined are specified in the FROM clause and the joining attributes in
the WHERE clause.
Algorithm for JOIN in SQL:
1. Cartesian product of tables (specified in the FROM clause)
1. Cartesian product:-
LEFT OUTER JOIN = Cartesian product + selection but include rows from the left table which
are unmatched pat nulls in the values of attributes belonging to the second table Exam:
Select B.*,P*
FROM student B left join course p
ON B.course # P.course #;
4. RIGHT OUTER JOIN:
RIGHT OUTER JOIN = Cartesian product + selection but include rows from right table which
are unmatched Exam:
Select B.*,P.* From student B RIGHT JOIN course P
B.course# = P course # ;
5. FULL OUTER JOIN
Exam
Select B.*,P.*
From student B FULL JOIN course P
On B.course # = P course # ;
Practical - 7
SubQueries:- A subQuery is a form of an SQL statement that appears inside another SQL
statement. It also termed as nested Query. The statement containing a subQuery called a parent
statement. The rows returned by the subQuery are used by the following statement. It can be
used by the following commands:
1. To insert records in the target table.
4. To create view.
Union Clause:
The user can put together multiple Queries and combine their output using the union
clause . The union clause merges the output of two or more Queries into a single set of
Output: = Records only in Query one + records only in Query two + A single set of
Syntax:
SELECT columnname, columname
FROM tablename 1
UNION
the interest clause. The final output of the interest clause will be : Output =A single
Syntax:
SELECT columnname, columnname
FROM tablename 1
INTERSECT
SELECT columnname, columnname
FROM tablename 2;
MINUS CLAUSE:- The user can put together multiple Queries and combine their output
Syntax:
SELECT columnname, columnname
FROM tablename ;
MINUS
SELECT columnname, columnname
FROM tablename ;
EXPERIMENT NO. 8
Name of Experiment: To implement the concept of Indexes and views.
Course Name: DBMS Lab Course Code: BCS-551
Branch: CSE Semester: V
Practical - 8
Indexes- An index is an ordered list of content of a column or group of columns in a table. An index
created on the single column of the table is called simple index. When multiple table columns are
included in the index it is called composite index.
Creating an Index for a table:-
Syntax (Simple)
CREATE INDEX index_name
ON tablename(column name);
Composite Index:-
CREATE INDEX index_name
ON tablename(columnname,columnname);
Creating an UniQuestion Index:-
CREATE UNIQUESTION INDEX indexfilename
ON tablename(columnname);
Dropping Indexes:-
An index can be dropped by using DROP INDEX
SYNTAX:-
DROP INDEX indexfilename;
Views:-
Logical data is how we want to see the current data in our database. Physical data is how this data is
actually placed in our database. Views are masks placed upon tables. This allows the programmer to
develop a method via which we can display predetermined data to users according to our desire. Views
may be created fore the following reasons:
1. The DBA stores the views as a definition only. Hence there is no duplication of data.
2. Simplifies Queries.
Creation of Views:-
Syntax:-
CREATE VIEW viewname AS
SELECT columnname,columnname
FROM tablename
WHERE columnname=expression_list;
Renaming the columns of a view:-
Syntax:-
CREATE VIEW viewname AS
SELECT newcolumnname….
FROM tablename
WHERE columnname=expression_list;
Selecting a data set from a view-
Syntax:-
SELECT columnname, columnname
FROM viewname
WHERE search condition;
Destroying a view-
Syntax:-
DROP VIEW viewname;
EXPERIMENT NO. 9
Name of Experiment: To implement the basics of PL/SQL.
Course Name: DBMS Lab Course Code: BCS-551
Branch: CSE Semester: V
Practical - 9
Introduction – PL/SQL bridges the gap between database technology and procedural programming
languages. It can be thought of as a development tool that extends the facilities of Oracles SQL
database language. Via PL/SQL you can insert, delete, update and retrieve table data as well as writing
loops or branching to another block of code.
PL/SQL Block structure-
DECLARE
Declarations of memory variables used later
BEGIN
SQL executable statements for manipulating table data.
EXCEPTIONS
SQL and/or PL.SQL code to handle errors.
END;
Displaying user Messages on the screen – Any programming tool requires a method through which
messages can be displayed to the user. Dbms_output is a package that includes a number of procedure
and functions that accumulate information in a buffer so that it can be retrieved later. These functions
can also be used to display message to the user.
put_line: put a piece of information in the buffer followed by a end of line marker. It can also be used
to display message to the user.
Setting the server output on:
SET SERVER OUTPUT ON:
Example: Write the following code in the PL/SQL block to display message to user
DBMS_OUTPUT.PUT_LINE(‘Display user message’);
Conditional control in PL/SQL-
Syntax:
IF <condition> THEN
<Action>
ELSEIF<condition>
<Action>
ELSE
<Action>
ENDIF;
The WHILE LOOP:
Syntax:
WHILE <condition>
LOOP
<Action>
END LOOP;
The FOR LOOP statement:
Syntax:
FOR variable IN [REVERSE] start—end
LOOP
<Action>
END LOOP;
The GOTO statement: The goto statement allows you to change the flow of control within a
PL/SQL Block.
EXPERIMENT NO. 10
Name of Experiment: To implement the concept of Cursor and Trigger.
Course Name: DBMS Lab Course Code: BCS-551
Branch: CSE Semester: V
Practical No- 10
Cursor– We have seen how oracle executes an SQL statement. Oracle DBA uses a work area for its
internal processing. This work area is private to SQL’s operation and is called a cursor. The data that is
stored in the cursor is called the Active Data set. The size of the cursor in memory is the size required
to hold the number of rows in the Active Data Set.
Explicit Cursor- You can explicitly declare a cursor to process the rows individually. A cursor declared
by the user is called Explicit Cursor. For Queries that return more than one row, You must declare a
cursor explicitly.
The data that is stored in the cursor is called the Active Data set. The size of the cursor in memory is
the size required to hold the number of rows in the Active
Why use an Explicit Cursor- Cursor can be used when the user wants to process data one row at a time.
Explicit Cursor Management- The steps involved in declaring a cursor and manipulating data
• Declare a cursor that specifies the SQL select statement that you want to process.
Database triggers are procedures that are stored in the database and are implicitly executed(fired) when
the contents of a table are changed. Use of Da tabase Triggers:- Database triggers support Oracle to
provide a highly customized database management system. Some of the uses to which the database
triggers can be put to customize management information in Oracle are as follows:-
• A Trigger can permit DML statements against a table any if they are issued, during regular
business hours or on predetermined weekdays.
• A trigger can also be used to keep an audit trail of a table along with the operation performed
2. A trigger restriction
3. A trigger action.
Types of Triggers:-
Using the various options , four types of triggers can be created:-
1. Before Statement Trigger:- Before executing the triggering statement, the
2. Before Row Trigger:- Before modifying the each row affected by the
executed if the trigger restriction either evaluated to TRUE or was not included.’
4. After row Trigger:- After modifying each row affected by the triggering
statement and possibly applying appropriate integrity constraints, the trigger action
is executed for the current row if the trigger restriction either evaluates to