100% found this document useful (1 vote)
185 views67 pages

DBMS Lab Guide for B.Tech Students

The document provides an overview of the Database Management Systems Lab course, including the course objectives, outcomes, syllabus, list of experiments, safety guidelines and assessment criteria. It outlines the vision and mission of the institute and department. The document is intended to guide students in their laboratory work for the Database Management Systems course.

Uploaded by

Prabhanshu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
185 views67 pages

DBMS Lab Guide for B.Tech Students

The document provides an overview of the Database Management Systems Lab course, including the course objectives, outcomes, syllabus, list of experiments, safety guidelines and assessment criteria. It outlines the vision and mission of the institute and department. The document is intended to guide students in their laboratory work for the Database Management Systems course.

Uploaded by

Prabhanshu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DATABASE MANAGEMENT SYSTEMS LAB (LC-CSE-209G)

LABORATORY MANUAL
B.Tech. Semester- IV

DATABASE MANAGEMENT SYSTEMS LAB


Subject code: LC-CSE-209G

Prepared by: Checked by: Approved by:


Dr Shipra Arora Dr Ritu Pahwa Name : Prof. (Dr.) Isha Malhotra

Sign.: ……………………. Sign.: …………………. Sign.: ………………….

DEPARTMENT OF CSE(AI&ML)
DRONACHARYA COLLEGE OF ENGINEERING
KHENTAWAS, FARRUKH NAGAR, GURUGRAM (HARYANA)
Database Management System Lab (LC-CSE-209G)

Table of Contents
1. Vision and Mission of the Institute
2. Vision and Mission of the Department
3. Programme Educational Objectives (PEOs)
4. Programme Outcomes (POs)
5. Programme Specific Outcomes (PSOs)
6. University Syllabus
7. Course Outcomes (COs)
8. CO- PO and CO-PSO mapping
9. Course Overview
10. List of Experiments
11. DOs and DON‟Ts
12. General Safety Precautions
13. Guidelines for students for report preparation
14. Lab assessment criteria
15. Lab Experiments

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Vision and Mission of the Institute

Vision:

“To impart Quality Education, to give an enviable growth to seekers of learning, to groom them as
World Class Engineers and managers competent to match the expending expectations of the
Corporate World has been ever enlarging vision extending to new horizons of Dronacharya
College of Engineering”

Mission:

M1: To prepare students for full and ethical participation in a diverse society and encourage
lifelong learning by following the principle of „Shiksha evam Sahayata‟ i.e., Education &
Help.
M2: To impart high-quality education, knowledge and technology through rigorous academic
programs, cutting-edge research, & Industry collaborations, with a focus on producing
engineers& managers who are socially responsible, globally aware, & equipped to address
complex challenges.
M3: Educate students in the best practices of the field as well as integrate the latest research into
the academics.
M4: Provide quality learning experiences through effective classroom practices, innovative
teaching practices and opportunities for meaningful interactions between students and
faculty.
M5: To devise and implement programmes of education in technology that are relevant to the
changing needs of society, in terms of breadth of diversity and depth of specialization.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Vision and Mission of the Department

Vision:
To cultivate skills and make proficient engineers cum trainers in the domain of Artificial
Intelligence & Machine Learning for exceptional contributions to the society.

Mission:

M1: To impart intense training and learning to generate knowledge through the state-of-the-art
concepts and technologies in Artificial Intelligence and Machine Learning.
M2: To establish centres of excellence by collaborating with the leading
industries to exhilarate innovative research and development in AIML and
its allied technology.
M3: To inculcate regenerative self-learning abilities, team spirit, and professional
ethics among the students for noble cause.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Programme Educational Objectives (PEOs)

PEO1- ANALYTICAL SKILLS:


Using a solid foundation in mathematical, scientific, engineering, and current computing
principles, formulate, analyse, and resolve engineering issues in real-world domain.
PEO2- TECHNICAL SKILLS:
Apply artificial intelligence theory and concepts to analyse the requirements, realise
technical specifications, and design engineering solutions.
PEO3- SOFT SKILLS:
Through inter-disciplinary projects and a variety of professional activities, demonstrate
technical proficiency, AI competency, and foster collaborative learning and a sense of
teamwork.
PEO4- PROFESSIONAL ETHICS:
Excel as socially responsible engineers or entrepreneurs with high moral and ethical
standards, competence, and soft skills that will enable them to contribute to societal
demands and achieve sustainable advancement in emerging computer technologies.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

PROGRAM OUTCOMES (POs)

PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
PO9: Individual and teamwork: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.
P11: Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one‟s own work, as a member and leader in a team,
to manage projects and in multidisciplinary environments.
P12: Life-long learning: Recognize the need for and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

PROGRAM SPECIFIC OUTCOMES (PSOs)

PSO1: Fundamentals and critical knowledge of the Computer System:


Apply the knowledge gained pertaining to build, asses, and analyze the software
and hardware aspects of the program to solve real world business problems.
PSO2: Comprehensive and applicative knowledge of Software Development:
Ability to evaluate and apply knowledge of data engineering, methodologies, and
able to plan, develop, test, analyze, and manage required aspects in heterogenous
platforms individually or in team work.
PSO3: Applications in Computing Domain:
Ability to acquire computational knowledge and project development abilities
using novel tools and methodologies to tackle challenges in the fields related to
Deep Learning, Machine learning, Artificial Intelligence.
PSO4: Applications in Innovations and Research:
Capacity to direct a team or firm that develops products and to use the
knowledge learned to recognise actual research issues

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

University Syllabus
Contents:

i. Creation of a database and writing SQL queries to retrieve information from the database.
ii. Performing Insertion, Deletion, Modifying, Altering, Updating and Viewing records based on
conditions.
iii. Creation of Views, Synonyms, Sequence, Indexes, Save point.
iv. Creating an Employee database to set various constraints.
v. Creating relationship between the databases.
vi. Study of PL/SQL block.
vii. Write a PL/SQL block to satisfy some conditions by accepting input from the user.
viii. Write a PL/SQL block that handles all types of exceptions.
ix. Creation of Procedures.
x. Creation of database triggers and functions
xi. Mini project (Application Development using Oracle/ MySQL)
a. Inventory Control System
b. Material Requirement Processing.
c. Hospital Management System.
d. Railway Reservation System.
e. Personal Information System.
f. Web Based User Identification System.
g. Time Table Management System.
h. Hotel Management

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Course Outcomes (COs)


Upon successful completion of the course, the students will be able to:

1. Get practical knowledge on designing and creating relational database systems


2. Implement basic SQL DDL Queries
3. Implement basic SQL DML Queries
4. Understand various advanced queries execution such as relational constraints, joins,
set operations, aggregate functions, trigger, view and embedded SQL.
5. To design and implement database applications on their own.

CO-PO Mapping
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 2 1 1 1 1 1 2 2 1 2
CO2 1 1 1 1 1
CO3 2 2 2 2 2
CO4 3 3 3 3 3 3 3 3 3 3
CO5 3 3 3 3 3 3 3 3 3 3 3

CO-PSO Mapping

CO PSO1 PSO2 PSO3 PSO4


CO1 3 1 3 1
CO2 1 1 1 1
CO3 1 1 2 2
CO4 2 2 3 3
CO5 3 3 3 3

*3-HIGH
*2-MEDIUM
*1-LOW

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Course Overview

Database management has evolved from a specialized computer application to a central component of a
modern computing environment and as a result knowledge about database system has become an essential
part of computer science. The course serves as a visual guide to the material presented during our
lectures. The aim of this course is to provide an introduction to Database management system, with an
emphasis on foundational material.

DBMS is a computer application software that provides a way to manage data. The requirement of modern
days is to have an automated system that manages, modifies, and updates data perfectly. This is
accomplished by a DBMS in robust, accurate, and non-redundant way. Consequently, Oracle, Sybase,
Microsoft SQL Server, etc. have emerged as prominent commercial systems while MySQL, PostgreSQL
etc. lead as open source software. This Course permits students to apply the conceptual design model to
construct the real-world problems. Course provides familiarity of Database Concepts so that students can
analyze the various different constraints to populate the database and examine different DBMS concepts to
deduce the most suitable pattern of documentation. DBMS lab with mini project targets at practicing and
accomplishing this aim by using MySQL as well as gain proficiency to design database and its hierarchical
structure for given real world application.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

List of Experiments mapped with COs


Sr. No. Program COs
1 Creation of database and SQL Queries to retrieve CO1,CO2
information from database
2 Performing insertion, deletion, modification, altering and CO1,CO3
updating operations on the records based on conditions.
3 To Manipulate the Operations on the table CO1,CO2,CO3
4 To Implement the structure of the table CO1,CO2
5 To Implement the restrictions on the table. CO2,CO3,CO4
6 To implement the concept of Joins. CO2,CO3,CO4
7 To implement the concept of grouping of Data. CO2,CO3,CO4
8 To implement the concept of Sub-Queries. CO2,CO3,CO4
9 To implement the concept of Indexes and views. CO2,CO3,CO4
10 To implement the basics of PL/SQL. CO2,CO3,CO4
Mini Project(Application Development using CO1,CO2,CO3,CO4
Oracle/MySQL) ,CO5
Inventory Control System
Material Requirement Processing
Hospital Management System
Railway Reservation System
Personal information System
Web Based User Identification System
Time Table Management System
Hotel Management

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

DOs and DON’Ts


DOs

1. Login-on with your username and password.


2. Log off the Computer every time when you leave the Lab.
3. Arrange your chair properly when you are leaving the lab.
4. Put your bags in the designated area.
5. Ask permission to print.

DON’Ts

1. Do not share your username and password.


2. Do not remove or disconnect cables or hardware parts.
3. Do not personalize the computer setting.
4. Do not run programs that continue to execute after you log off.
5. Do not download or install any programs, games or music on computer in Lab.
6. Personal Internet use chat room for Instant Messaging (IM) and Sites is strictly
prohibited.
7. No Internet gaming activities allowed.
8. Tea, Coffee, Water & Eatables are not allowed in the Computer Lab.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

General Safety Precautions

Precautions (In case of Injury or Electric Shock)


1. To break the victim with live electric source, use an insulator such as fire wood or plastic to break
the contact. Do not touch the victim with bare hands to avoid the risk of electrifying yourself.
2. Unplug the risk of faulty equipment. If main circuit breaker is accessible, turn the circuit off.
3. If the victim is unconscious, start resuscitation immediately, use your hands to press the chest
in and out to continue breathing function. Use mouth-to-mouth resuscitation if necessary.
4. Immediately call medical emergency and security. Remember! Time is critical; be best.

Precautions (In case of Fire)

1. Turn the equipment off. If power switch is not immediately accessible, take plug off.
2. If fire continues, try to curb the fire, if possible, by using the fire extinguisher or by covering
it with a heavy cloth if possible, isolate the burning equipment from the other surrounding
equipment.
3. Sound the fire alarm by activating the nearest alarm switch located in the hallway.
4. Call security and emergency department immediately:

Emergency : 201 (Reception)


Security: 231 (Gate No.1)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Guidelines to students for report preparation


All students are required to maintain a record of the experiments conducted by them. Guidelines for its
preparation are as follows: -

1) All files must contain a title page followed by an index page. The files will not be signed by
the faculty without an entry in the index page.
2) Student‟s Name, roll number and date of conduction of experiment must be written on all
pages.
3) For each experiment, the record must contain the following
(i) Aim/Objective of the experiment
(ii) Pre-experiment work (as given by the faculty)
(iii) Lab assignment questions and their solutions
(iv) Test Cases (if applicable to the course)
(v) Results/ output
Note:
1. Students must bring their lab record along with them whenever they come for the lab.
2. Students must ensure that their lab record is regularly evaluated.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Lab Assessment Criteria


An estimated 10 lab classes are conducted in a semester for each lab course. These lab classes are
assessed continuously. Each lab experiment is evaluated based on 5 assessment criteria as shown in
following table. Assessed performance in each experiment is used to compute CO attainment as well as
internal marks in the lab course.
Grading Exemplary (4) Competent (3) Needs Poor (1)
Criteria Improvement (2)
AC1: Complete Underlined concept Not able to write Underlined concept is not clearly
Pre-Lab written procedure with is written but concept and understood
work (this may underlined concept procedure is procedure
is properly written incomplete
be assessed
through viva)
AC2: Unable to Assigned problem Assigned problem is Assigned problem is properly
Program Writing/ understand the is properly properly analyzed & analyzed
Modeling reason for errors/ analyzed, correct correct solution
bugs even after they solution designed, designed
are explicitly appropriate
pointed out language
constructs/ tools are
applied

AC3: Able to identify Able to identify Is dependent totally Unable to understand the reason
Identification & errors/ bugs and errors/ bugs and on someone for for errors/ bugs even after they
Removal of remove them remove them with identification of are explicitly pointed out
errors/ bugs little bit of guidance errors/ bugs and their
removal

AC4: All variants of input All variants of input Only few variants of Solution is not well demonstrated
Execution & /output are tested, /output are not input /output are and implemented concept is not
Demonstration Solution is well tested, However, tested, clearly explained
demonstrated and solution is well Solution is well
implemented demonstrated and demonstrated but
concept is clearly implemented
implemented
explained concept is clearly
explained concept is not
clearly explained
AC5: All assigned More than 70 % of Less than 70 % of the
Lab Record problems are well the assigned assigned problems
Assessment recorded with problems are well are well recorded
objective, design recorded with with objective, design
constructs and objective, design contracts and solution
solution along with contracts and along with
Performance Performance
solution along with
analysis using all Performance analysis is done
variants of input analysis is done with all variants of
and output with all variants input and output
of input and
output

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

LAB EXPERIMENTS

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical #1
Objective: Create tables and specify the Questionnaires in SQL.

Theory & Concepts:

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.
DML (DATA Manipulation Language)-
It includes commands to insert tuples into, delete tuples from and modify tuples in
the database.
View definition-
The SQL DDL includes commands for defining views.
Transaction Control- SQL includes for specifying the beginning and ending of
transactions.
Embedded SQL and Dynamic SQL-
Embedded and Dynamic SQL define how SQL statements can be embedded with in
general purpose programming languages, such as C, C++, JAVA, COBOL, Pascal
and Fortran.
Integrity-
The SQL DDL includes commands for specifying integrity constraints that the
datastored in the database must specify. Updates that violate integrity constraints are
allowed.
Authorization-
The SQL DDL includes commands for specifying access rights to relations and views.

Data Definition Language-

The SQL DDL allows specification of not only a set of relations but also
informationabout each relation, including-
 Schema for each relation
 The domain of values associated with each attribute.
 The integrity constraints.
 The set of indices to be maintained for each relation.
 The security and authorization information for each relation.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

 The physical storage structure of each relation on disk.

Domain types in SQL-

The SQL standard supports a variety of built in domain types, including-


 Char (n) - A fixed length character length string with user specified length.
 Varchar (n) - A variable character length string with user specified
maximumlength n.
 Int- An integer.
 Small integer- A small integer.
 Numeric (p, d)-A Fixed point number with user defined precision.
 Real, double precision- Floating point and double precision floating point
numbers with machine dependent precision.
 Float (n) - A floating point number, with precision of at least n digits.
 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‟.
 Number- Number is used to store numbers (fixed or floating point).

DDL statement for creating a table-


Syntax-
Create table tablename
(columnname datatype(size), columnname datatype(size));

Creating a table from a table-

Syntax-
CREATE TABLE TABLENAME
[(columnname, columnname, ………)]
AS SELECT columnname, columnname ......... FROM tablename;

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical #2

Performing insertion, deletion, modification, altering and updating operations on the records
based on conditions.

Insertion of data into tables-


Syntax-
INSERT INTO tablename
[(columnname, columnname,
………)]Values(expression,
expression);
Inserting data into a table from another table:
Syntax-
INSERT INTO tablename
SELECT columnname, columnname,
…….FROM tablename;
Insertion of selected data into a table from another table:
Syntax-
INSERT INTO tablename
SELECT columnname, columnname……..
FROM tablename
WHERE columnname= expression;

Retrieving of data from the tables-


Syntax-
SELECT * FROM tablename;
The retrieving of specific columns from a table-
Syntax-
SELECT columnname, columnname,
….FROM tablename;
Elimination of duplicates from the select statement-
Syntax-
SELECT DISTINCT columnname,
columnnameFROM tablename;

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Selecting a data set from table data-


Syntax-
SELECT columnname,
columnnameFROM tablename
WHERE searchcondition;

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Q1. Create the following tables:

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Q2- Insert the following data into their respective tables:

Client Name City Pincode State Balance Due


No
0001 Ivan Bombay 400054 Maharashtra 15000
0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000
0006 Rukmini Bombay 400050 Maharashtra 0

Data for Product Master:

Product Description Profit Unit Qty_on_ Reorder Selling Cost


No. % Measure hand _lvl Price Price
P00001 1.44floppies 5 piece 100 20 525 500
P03453 Monitors 6 piece 10 3 12000 11200
P06734 Mouse 5 piece 20 5 1050 500
P07865 1.22 floppies 5 piece 100 20 525 500
P07868 Keyboards 2 piece 10 3 3150 3050
P07885 CD Drive 2.5 piece 10 3 5250 5100
P07965 540 HDD 4 piece 10 3 8400 8000
P07975 1.44 Drive 5 piece 10 3 1050 1000
P08865 1.22 Drive 5 piece 2 3 1050 1000

Q3:- On the basis of above two tables answer the following Questionries:
i) Find out the names of all the clients.
ii) Retrieve the list of names and cities of all the clients.
iii) List the various products available from the product_master table.
iv) List all the clients who are located in Bombay.
v) Display the information for client no 0001 and 0002.
vi) Find the products with description as „1.44 drive‟ and „1.22 Drive‟.
vii) Find all the products whose sell price is greater then 5000.
viii) Find the list of all clients who stay in in city „Bombay‟ or city
„Delhi‟ or„Madras‟.
ix) Find the product whose selling price is greater than 2000 and less
than orequal to 5000.
x) List the name, city and state of clients not in the state of „Maharashtra‟.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical #3
Objective:- To Manipulate the Operations on the table.
DML ( Data Manipulation Language) Data manipulation is

 The retrieval of information stored in the database.


 The insertion of new information into the database.
 The deletion of information from the database.
 The modification of information stored by the appropriate data model.
There arebasically two types.
(i) Procedural DML:- require a user to specify what data are needed and
howto get those data.
(ii) Non Procedural DML : require a user to specify what data are
neededwithout specifying how to get those data.
Updating the content of a table:
In creation situation we may wish to change a value in table without changing all
valuesin the tuple . For this purpose the update statement can be used.

Update table name


Set columnname = expression, columnname
=expression……Where columnname = expression;

Deletion Operation:-
A delete query is expressed in much the same way as Query. We can delete whole
tuple (rows) we can delete values on only particulars attributes.
Deletion of all rows

Syntax:
Delete from tablename :
Deletion of specified number of rows
Syntax:

Delete from table


name Where search
condition ;
Computation in expression lists used to select data

+ Addition - Subtraction
* multiplication ** exponentiation
/ Division () Enclosed operation

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Renaming columns used with Expression Lists: - The default output


column names canbe renamed by the user if required
Syntax:

Select column name


resul
t_columnname,
Columnname
resul
t_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 followingexamples.
 „Perry %‟ matches any string beginning with perry
 „% idge % matches any string containing‟ idge as substring.
 „ - - - „ matches any string exactly three characters.
 „ - - - % matches any string of at least of three characters.

Oracle functions:
Functions are used to manipulate data items and return result. function
follow the format of function _name (argument1, argument2 ..) .An
arrangement is user defined variable or constant. The structure of function
is such that it accepts zero or more arguments.
Examples:
Avg return average value of n

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

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

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 Returns sum of values of n
Syntax:
Sum ([distinct/all]n)
Sorting of data in table

Syntax:
Select
columnname,
columnnameFrom
table
Order by columnname;

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Question.1 Using the table client master and product master answer the
followingQuestionnaires.

i. Change the selling price of „1.44 floppy drive to Rs.1150.00


ii. Delete the record with client 0001 from the client master table.
iii. Change the city of client_no‟0005‟ to Bombay.
iv. Change the bal_due of client_no „0001, to 1000.
v. Find the products whose selling price is more than 1500 and
also find the newselling price as original selling price *15.
vi. Find out the clients who stay in a city whose second letter is a.
vii. Find out the name of all clients having „a‟ as the second letter in their names.
viii. List the products in sorted order of their description.
ix. Count the total number of orders
x. Calculate the average price of all the products.
xi. Calculate the minimum price of products.
xii. Determine the maximum and minimum prices . Rename the tittle
as „max_price‟and min_price respectively.
xiii. Count the number of products having price greater than or equal to 1500.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical .4

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Objective:- To Implement the structure of the table


Modifying the Structure of Tables- Alter table command is used to
changing the structure of a table. Using the alter table clause you cannot
perform the following tasks:

(i) change the name of table


(ii) add a column
(iii) drop a column
(iv) decrease the size of a table if table data exists.

The following tasks you can perform through alter table command.

(i) Adding new columns:


Syntax
ALTER TABLE tablename
ADD (newcolumnname newdatatype (size));

(ii) Modifying existing table


Syntax:
ALTER TABLE tablename
MODIFY (newcolumnname newdatatype (size));

NOTE: Oracle not allow constraints defined using the alter table, if the data
in the table,violates such constraints.

Removing/Deleting Tables- Following command is used for removing or


deleting atable.
Syntax:
DROP TABLE tablename:

Defining Integrity constraints in the ALTER TABLE command-

You can also define integrity constraints using the constraint clause in the
ALTER TABLE command. The following examples show the definitions of
several integrityconstraints.

Add PRIMARY KEY-


(1) Syntax:
ALTER TABLE tablename
ADD PRIMARY KEY (columnname);

(2) Add FOREIGN KEY-


Syntax:

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

ALTER TABLE tablename


ADD CONSTRAINT constraintname
FOREIGN KEY(columnname) REFERENCES tablename;Dropping integrity
constraints in the ALTER TABLE command:

You can drop an integrity constraint if the rule that if enforces is no longer true or
if theconstraint is no longer needed. Drop the constraint using the ALTER
TABLE commandwith the DROP clause. The following examples illustrate the
dropping of integrity constraints.

(1) DROP the PRIMARY KEY-Syntax:


ALTER TABLE tablenameDROP PRIMARY KEY

(2) DROP FOREIGN KEY-Syntax:


ALTER TABLE tablename
DROP CONSTRAINT constraintname;

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Question 1. Create the following tables:


Challan_Header
Column name data type size Attributes
Challan_no varchar2 6 Primary key
s_order_no varchar2 6 Foreign key references s_order_no of
sales_order table
challan_date date not null
billed_yn char 1 values („Y‟,‟N‟). Default „N‟

Table Name : Challan_Details


Column name data type size Attributes
Challan_no varchar2 6 Primary key/Foreign key references
Product_no of product_master
Qty_disp number 4,2 not null

Q2. Insert the following values into the challan header and challan_details tables:

(i) Challan No S_order No Challan Date Billed

CH9001 019001 12-DEC-95 Y


CH865 046865 12-NOV-95 Y
CH3965 010008 12-OCT-95 Y

Data for challan_details table

Challan No Product No Qty Disp


CH9001 P00001 4
CH9001 P07965 1
CH9001 P07885 1
CH6865 P07868 3
CH6865 P03453 4
CH6865 P00001 10
CH3965 P00001 5
CH3965 P07975 2
Answer the following Questionries

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Q1. Make the primary key to client_no in client_master.


Q2. Add a new column phone_no in the client_master table.
Q3. Add the not null constraint in the product_master table with the
columns description,profit percent , sell price and cost price.
Q4. Change the size of client_no field in the client_master table.
Q5. Select product_no, description where profit percent is between 20 and
30 bothinclusive.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical #5
Objective:- To Implement the restrictions on the table.
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 atable 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
(columnname datatype (size) primary key,….)
Primary key as a table constraint
Create table tablename
(columnname datatype (size), columnname datatype(
size)…Primary key (columnname,columnname));

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:
Create table tablename
(columnname datatype (size) default value,….);

Foreign Key Concept : Foreign key represents relationship between tables. A

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

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 primarykey table to have meaning.
Foreign key as a column constraint
Syntax :
Create table table name
(columnname datatype (size) references another table name);

Foreign key as a table constraint:


Syntax :
Create table name
(columnname datatype
(size)….primary key
(columnname);
foreign key (columnname)references table name);

Check Integrity Constraints: Use the check constraints when you need to
enforce integrity rules that can be evaluated based on a logical expression
following are a few examples of appropriate check constraints.
 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 thatno client_no value starts with „c‟

Syntax:
Create table tablename
(columnname datatype (size) CONSTRAINT
constraintname)Check (expression) );

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

OUTPUT:-

Question.1 Create the following tables:


Columnname Datatype Size Attributes
Salesman_no varchar2 6 Primary key/first letter
must start with „s‟
Sal_name varchar2 20 Not null
Address varchar2 Not null
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2 Not null, cannot be 0
Tgt_to_get Number 6,2 Not null, cannot be 0
Ytd_sales Number 6,2 Not null, cannot be 0
Remarks Varchar2 30

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

i. Sales_order
Columnname Datatype Size Attributes
S_order_no varchar2 6 Primary/first letter must be 0
S_order_date Date 6 Primary key reference clientno
of client_master table
Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6 Foreign key references
salesman_no of
salesman_master table
Dely_type Char 1 Delivery part(p)/full(f),default f
Billed_yn Char 1
Dely_date Date Can not be lessthan
s_order_date
Order_status Varchar2 10 Values („in
process‟;‟fulfilled‟;back
order‟;‟canceled

I. Sales_order_details
Column Datatype Size Attributes

S_order_no Varchar2 6 Primary key/foreign


key references
s_order_no of
sales_order
Product_no Varchar2 6 Primary key/foreign
key references
product_no of
product_master
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2

Insert the following data into their respective tables using insert statement:
Data for sales_man master table
Salesman_ Salesman Address City Pin State Salamt Tgt_to_get Ytd Remarks
no name code Sales
500001 Kiran A/14 Bom 400002 Mah 3000 100 50 Good
worli bay
500002 Manish 65,nariman Bom 400001 Mah 3000 200 100 Good
bay
500003 Ravi P-7 Bom 400032 Mah 3000 200 100 Good
Bandra bay
500004 Ashish A/5 Bom 400044 Mah 3500 200 150 Good
Juhu bay

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

(ii)
Data for salesorder table:
S_orderno S_orderdate Client no Dely Bill Salesman no Delay Orderst
type yn date atus
019001 12-jan-96 0001 F N 50001 20-jan- Ip
96
019002 25-jan-96 0002 P N 50002 27-jan- C
96
016865 18-feb-96 0003 F Y 500003 20-feb- F
96
019003 03-apr-96 0001 F Y 500001 07-apr- F
96
046866 20-may-96 0004 P N 500002 22- C
may-96
010008 24-may-96 0005 F N 500004 26- Ip
may-96

(i)
Data for sales_order_details table:
S_order no Product no Qty ordered Qty disp Product_rate
019001 P00001 4 4 525
019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical #6
Objective:- To implement the concept of Joins

Joint Multiple Table (Equi Join): Sometimes we require to treat more than
one table asthough 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)
2. Selection of rows that match (predicate in the WHERE clause)
3. Project column specified in the SELECT clause.

1. Cartesian product:-
Consider two table student and
courseSelect B.*,P.*
FROM student B, course P;
2. INNER JOIN:
Cartesian product followed by
selectionSelect B.*,P.*
FROM student B, Course P WHERE
B.course # P.course # ;

3. LEFT OUTER JOIN:


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 th esecond table
Exam:
Select B.*,P*
FROM student B left join course pON
B.course # P.course #;

4. RIGHT OUTER JOIN:


RIGHT OUTER JOIN = Cartesian product + selection but include rows
fromright table which are unmatched

Exam:
Select B.*,P.*
From student B RIGHT JOIN course P
B.course# = P course # ;

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

5. FULL OUTER JOIN


Exam
Select B.*,P.*
From student B FULL JOIN course POn
B.course # = P course # ;

OUTPUT:-

Answer the following Queries:


1. Find out the product which has been sold to „Ivan Sayross.‟
2. Find out the product and their quantities that will have do delivered.
3. Find the product_no and description of moving products.
4. Find out the names of clients who have purchased „CD DRIVE‟
5. List the product_no and s_order_no of customers haaving qty
ordered less than 5from the order details table for the product “1.44 floppies”.
6. Find the products and their quantities for the orders placed by
„Vandan Saitwal ‟and “Ivan Bayross”.
7. Find the products and their quantities for the orders placed by
client_no “C00001” and “C00002”
8. Find the order No,, Client No and salesman No. where a client
has been receivedby more than one salesman.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

9. Display the s_order_date in the format “dd-mm-yy” e.g. “12- feb-96”


10. Find the date , 15 days after date.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical # 7

Objective:- To implement the concept of grouping of Data.

Grouping Data From Tables:


There are circumstances where we would like to apply the aggregate function not
only to a single set of tuples, but also to a group of sets of tuples, we specify this wish
in SQL using the group by clause. The attribute or attributes given in the group by
clause are used to form group. Tuples with the same value on all attributes in the
group by clauseare placed in one group.
Syntax:
SELECT columnname, columnnameFROM
tablename
GROUP BY columnname;
At times it is useful to state a condition that applies to groups rather than to tuples. For
example we might be interested in only those branches where the average account
balance is more than 1200. This condition does not apply to a single tuple,
rather it applies to each group constructed by the GROUP BY clause. To express
such Questionry, we use the having clause of SQL. SQL applies predicates in the
having maybe used.
Syntax:
SELECT columnname, columnname
FROM tablename
GROUP BY columnname;HAVING searchcondition;

Answer the following Queries:

Q1.- Print the description and total quantity sold for


each product. Q2.- Find the value of each product sold.
Q3.- Calculate the average quantity sold for each client that has a maximum order value
of 15000.
Q4.- Find out the products which has been
sold to Ivan. Q5.- Find the names of clients
who have „CD Drive‟.
Q6.- Find the products and their quantities for the orders placed by
„Vandana‟ and „Ivan‟.
Q7.- Select product_no, total qty_ordered for each product.

Q8.- Select product_no, product description and qty ordered for each product. Q9.-
Display the order number and day on which clients placed their order.
Q10.- Display the month and Date when the order must be delivered.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical #8
Objective:- To implement the concept of SubQueries.

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.
2. To create tables and insert records in this table.
3. To update records in the target table.
4. To create view.
5. To provide values for the condition in the WHERE , HAVING IN
,SELECT,UPDATE, and DELETE statements.
Exam:-
Creating clientmaster table from oldclient_master, table

Create table client_master


AS SELECT * FROM oldclient_master;
Using the Union, Intersect and Minus Clause:
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 rows and column. The final output of union
clause will be

Output: = Records only in Query one + records only in Query two + A


single set of records with is common in the both Queries.

Syntax:

SELECT
columnname,
columnameFROM
tablename 1
UNION
SELECT columnname,
columnnameFrom
tablename2;

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Intersect Clause: The use can put together multiple Queries and their
output using the interest clause. The final output of the interest clause will
be :

Output =A single set of records which are common

in both QueriesSyntax:

SELECT columnname, columnnameFROM tablename 1


INTERSECT
SELECT columnname, columnnameFROM tablename
2;

MINUS CLAUSE:- The user can put together multiple Queries and combine their output
= records
only in
Query one
Syntax:
SELECT columnname, columnnameFROM tablename ;
MINUS
SELECT columnname, columnnameFROM tablename ;

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Answer the following Queries:


Question.
1. Find the product_no and description of non- moving products.
2. Find the customer name, address, city and pincode for the client
who has placedorder no “019001”
3. Find the client names who have placed order before the month of may 96.
4. Find out if product “1.44 Drive” is ordered by only client and
print the client_noname to whom it was sold.
5. find the names of client who have placed orders worth Rs.10000 or more.
6. Select the orders placed by „Rahul Desai”
7. Select the names of persons who are in Mr. Pradeep‟s department
and who havealso worked on an inventory control system.
8. Select all the clients and the salesman in the city of Bombay.
9. Select salesman name in “Bombay” who has atleast one client
located at“Bombay”
10. Select the product_no, description, qty_on-hand,cost_price of
non_moving itemsin the product_master table.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Practical # 9
Objective:- To implement the concept of Indexes and views.
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_nameON
tablename(colu
mn name);
Composite Index:-
CREATE INDEX index_name
ON tablename(columnname,columnname);

Creating an UniQuestion Index:-


CREATE UNIQUESTION INDEX
indexfilenameON
tablename(columnname);

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Creation of Views:-

Syntax:-
CREATE VIEW viewname AS SELECT
columnname,columnnameFROM tablename
WHERE columnname=expression_list;

OUTPUT:-

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Answer the following Questions

Q1. Create an index on the table client_master, field client_no.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Q2. Create an index on the sales_order, field s_order_no.


Q3. Create an composite index on the sales_order_details table for the columns s_order_no
and product_no.
Q4. Create an composite index ch_index on challan_header table for the columns challan no
and s_order_no.
Q5. Create an uniQuestion index on the table salesman_master, field salesman_no.
Q6. Drop index ch_index on table challan_header.
Q7. Create view on salesman_master whose sal_amt is less than 3500.
Q8. Create a view client_view on client_master and rename the columns as name, add1, add2,
city, pcode, state respectively.
Q9. Select the client names from client_view who lives in city „Bombay‟.
Q10. Drop the view client_view.

Practical # 10

Objective:- To implement the basics of PL/SQL.


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

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

userDBMS_OUTPUT.PUT_LINE(„Display user message‟);

Conditional control in PL/SQL-


Syntax:
IF <condition> THEN
<Action> ELSEIF<condition>
<Action>
ELSE
<Action>ENDIF;

The GOTO statement: The goto statement allows you to change the
flow of controlwithin a PL/SQL Block.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

OUTPUT:-
19 21 8
b is maximum 21
Q1. WAP in PL/SQL for addition of two numbers.

Q2. WAP in PL/SQL for addition of 1 to 100 numbers.

Q3. WAP in PL/SQL to check the given number is even or odd.

Q4. WAP in PL/SQL to inverse a number, eg. Number 5639 when inverted must be display
output 9365.

Q5. WAP in PL/SQL for changing the price of product „P00001‟ to 4000 if the price is less than
4000 in product_master table. The change is recorded in the old_price_table along with
product_no and the date on which the price was changed last.

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

MINI PROJECT(Sample)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Note:- Execute at least 20 queries

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

VIVA QUESTIONS

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

It is number of entity type participating

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23


Database Management System Lab (LC-CSE-209G)

Department of CSE(AI&ML) 2022-23

You might also like