0% found this document useful (0 votes)
17 views70 pages

A 71dbms

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)
17 views70 pages

A 71dbms

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/ 70

DEPARTMENT OF COMPUTER ENGINEERING

Indala College of Engineering ACADEMIC YEAR : 2021–23 (TERM – II)

List of Experiments
Course Name : Database Management system Lab (R-19)
Course Code : CSC403/CSL402

Sr. Name of COs Covered Page Date of Date of Marks


No experiment No. Performanc Submissio &
. e n Signature
1 Identify the case CO2
study and detail
statement of
problem. Design an
Entity-Relationship
(ER) / Extended
Entity-Relationship
(EER) Model.
2 Mapping ER/EER to CO3
Relational schema
model.
3 Create a database CO4
using Data
Definition Language
(DDL) and apply
integrity constraints
for the specified
System
4 Apply DML CO4
Commands for the
specified system
5 Perform Simple CO4
queries, string
manipulation
operations and
aggregate functions
6 Implement various CO4
Join operations.
7 Perform Nested and CO4
Complex queries
8 Perform DCL and CO4
TCL commands
9 Implement CO4
procedure and
functions
10 Implementation of CO4
Views and Triggers.
11 Assignment-1 CO1,CO2,CO3
12 Assignment-2 CO4,CO5,CO6
INDALA COLLEGE OF ENGINEERING

CERTIFICATE
This is to certify that Mr. / Miss of

S.E COMPUTER Class: A Roll No has performed the Experiments /

Assignments / Tutorials / Case Study Work mentioned above in the premises of the

institution.

Practical Incharge Head of Dept. Principal

Date
Examined on

Examiner 1 Examiner 2
INDALA COLLEGE OF ENGINEERING, BAPSAI

Department Mission :
M1: To promote an educational environment that combines academics with intellectual
curiosity.
M2: To develop human resource with sound knowledge of theory and practical in the
discipline of Computer Engineering and the ability to apply the knowledge to the
benefit of society at large.
M3: To assimilate creative research and new technologies in order to facilitate students to be
a lifelong learner who will contribute positively to the economic well-being of the nation.

Program Educational Objectives (PEO)


PEO1: To explicate optimal solutions through application of innovative computer
science techniques that aid towards betterment of society.
PEO2: To adapt recent emerging technologies for enhancing their career opportunity
prospects.
PEO3: To effectively communicate and collaborate as a member or leader in a team
to manage multidisciplinary projects.
PEO4: To prepare graduates to involve in research, higher studies or to become
entrepreneurs in long run.

Program Specific Outcomes (PSO)


PSO1: To apply basic and advanced computational and logical skills to provide
solutions to computer engineering problems.
PSO2: Ability to apply standard practices and strategies in design and development
of software and hardware based systems and adapt to evolutionary changes in
computing to meet the challenges of the future.
PSO3: To develop an approach for lifelong learning and utilize multi-disciplinary
knowledge required for satisfying industry or global requirements.
Program Outcomes as defined by NBA (PO)

Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.
2. 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.
3. 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.
4. 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.
5. 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.
6. 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.
7. 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.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
10. 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.
11. 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.
12. 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.
INDALA COLLEGE OF ENGINEERING,
DEPARTMENT OF COMPUTER ENGINEERING
COURSE NAME: DATABASE MANAGEMENT LAB
COURSE CODE: CSC403/CSL402
YEAR OF STUDY: S.E., SEMESTER: IV COURSE OUTCOMES

CSC403.1 Recognize the need of database management system

CSC403.2 Design ER and EER diagram for real life applications

CSC403.3 Construct relational model and write relational algebra queries.

CSC403.4 Formulate SQL queries

CSC403.5 Apply the concept of normalization to relational database design.

CSC403.6 Describe the concept of transaction, concurrency and recovery.


INDALA OF ENGINEERING DEPARTMENT OF
COMPUTER ENGINEERING ACADEMIC YEAR
2022-23 (TERM II)
SUBJECT: DATABASE MANAGEMENT SYSTEM LAB
SEM: IV
RUBRICS FOR GRADING EXPERIMENTS
Rubric Rubric Title Criteria Marks*
Number (out of 15)
On-time 3
Punctuality, Completion Delayed by not more than a
R1 2
Time / Timeline Week
Delayed more than a Week 1
Presents a logical
explanation for findings and
5
addresses most of the
questions.
Presents a logical
explanation for findings and
4-3
addresses some of the
R2 Knowledge & Concept questions.
Presents a illogical
explanation for findings and 2
addresses few questions.
Presents a illogical
explanation for findings and
1
does not address any of the
questions.
Correct implementation with
4
Results
R3 Result & Implementation Implementation with most of
3
the results
Partial implementation 2-1
Correct and Neat
3
Documentation
R4 Documentation Fairly good documentation 2
Untidy and incorrect
1
documentation
*means obtained marks will be scaled to 15 for Experiments
INDALA COLLEGE OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
ACADEMIC YEAR 2021-22 (TERM II)
SUBJECT: DATABASE MANAGEMENT SYSTEM LAB
SEM: IV
RUBRICS FOR GRADING ASSIGNMENTS

Rubric Rubric Title Criteria Marks


Numbe (out of 5)
r
R1 Punctuality, On-time 2
Completion Delayed by not more than a Week 1
Time / Timeline Delayed more than a Week 0
R2 Knowledge & Clear understanding 2
Concept Partially understood 1
Weak understanding 0
R3 Documentation Correct Documentation 1
Not documented properly 0

*means obtained marks will be scaled to 5 for Assignments


EXPERIMENT NO: 01
Date of performance:
Date of submission:

AIM: To construct an E-R diagram for the given problem statement.

PROBLEM STATEMENT: To construct an ER-diagram for Bank Management system


consisting of a set of customers and a set of loan and branches of bank . This system
keeps records of various entities related to management of bank such as customer, loan,
branch and accounts .

THEORY: An ER-Diagram stands for Entity Relationship-Diagram, that displays the


relationship of entity sets stored in a database. ER diagrams are created based on three
basic concepts: entities, attributes and relationships.

ER Diagrams contain different symbols that use rectangles to represent entities,


ovals to define attributes and diamond shapes to represent relationships.

ER model allows you to draw Database Design


It helps you to identifies the entities which exist in a system and the
relationships between those entities

What is an bank‟s database ?


A bank database is a database which contains critical information, such as
each account information, as well as banking-related information such as their
customers loans, and more.

PROCEDURE: Entity Relationship Diagram mainly contains three basic


symbols which are rectangle, oval and diamond to represent relationships
between elements, entities and attributes.

Following are the main components and its symbols in ER Diagrams:

Rectangles: This Entity Relationship Diagram symbol represents entity types


Ellipses: Symbol represent attributes
Diamonds: This symbol represents relationship types
Lines: It links attributes to entity types and entity types with other relationship types
Primary key: attributes are underlined
Double Ellipses: Represent multi-valued attributes
• Components of the ER Diagram -

This model is based on three basic concepts:

Entities
Attributes
Relationships


WHAT IS ENTITY?

An entity can be place, person, object, event or a concept, which stores data in the
database. The characteristics of entities are must have an attribute, and a unique
key. An entity set is a group of similar kind of entities.

There are two types of entity set‟s -

1) Strong entity‟s:- entity sets with a primary key

2) Weak entity sets:- entity set‟s with no primary key for themselves

Identifying the Entity sets for given problem statement‟s -

Strong Entity sets -

1) Bank.

2) Branch.

3) Account.

4) Customer.
5) Loan.

As we know every entity has its own characteristic‟s we know as there attributes
this attribute provide an idea of the entity. These attributes are represented in an
ellipse this attributes are of 4 types and they are as follows;

Simple attribute Simple attributes can‟t be divided any further..


Composite attribute
It is possible to break down composite attribute

Derived attribute This type of attribute does not include in the physical
database.

Multivalued attribute
These attributes have more than 1 values

Identifying the Attributes for the Entity sets for the given problem statement‟s

– List of attributes for each entity is as follows:

1. Bank-> { code, b_name, b_add }


2. Branch-> {br_id, br_name, br_add }

3. Account-> {acc_no, acc_type, acc_bal }

4. Loan-> {l_id, l_type, l_amt }

5. Customer-> {c_id, c_name, c_add, c_pno}


CARDINALITY -

Defines the numerical attributes of the relationship between two entities or entity
sets.

Different types of cardinal relationships are:

• One-to-One Relationships
• One-to-Many Relationships
• May to One Relationships
• Many-to-Many Relationships
Identifying the Relationships and Mapping Cardinality between entity sets for thr
given problem statement‟s –
• Bank = Bank has Branches => 1:N
• Branch = Branch has Accounts => 1:N
• Loan = Bank offers Loan => 1:N
• Account = Accounts are held by customer => M:N
• Customer = Customer avail loans => M:N

E-R diagram :

After considering all the given aspects the e-r diagram for the given problem
statement will be as follows:-

CONCLUSION:

Thus, indented the case study and detail statement of problem. The Entity–relationship
diagram (ER) is constructed for the given problem statement.

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks)
EXPERIMENT NO: 02
Date of performance:
Date of submission:

AIM: To construct a relational model for the given problem statement.

PROBLEM STATEMENT: To construct a Relational model for an Bank


database management system consisting of a set of bank, a set of departments, a
set of projects and a set of dependents.

THEORY : Relational Model(RM) represents the database as a collection


of relations. A relation is nothing but a table of values.

Every row in the table is a tuple and it represents a collection of related data
values. These rows in the table denote a real-world entity or relationship.

Attribute, Tables, Tuple, Relation Schema, Degree, Cardinality, Column,


Relation instance, are some important terminology of Relational Model
Relational Integrity constraints are referred to conditions which must be present
for a valid Relation approach in DBMS
Insert, Select, Modify and Delete are the operations performed in
Relational Model constraints.

There are several processes and algorithms available to convert ER Diagrams into
Relational
Schema. Some of them are automated and some of them are manual. We may focus
here on the mapping diagram contents to relational basics.


ER diagrams mainly comprise of −
• Entity and its attributes

• Relationship, which is association among entities.


Mapping Entity -

An entity is a real-world object with some attributes.


Mapping Process

(Algorithm) •

Create table for


each entity.

• Entity's attributes should become fields of tables with their respective data types.

• Declare primary key.

Mapping Relationship -
A relationship is an association among entities.

Mapping Process -
• Create table for a relationship.

• Add the primary keys of all participating Entities as fields of table with their
respective data types.

• If relationship has any attribute, add each attribute as field of table.

• Declare a primary key composing all the primary keys of participating entities.

• Declare all foreign key constraints.



Mapping Weak Entity Sets -

A weak entity set is one which does not have any primary key associated with it.


Mapping Process -
• Create table for weak entity set.

• Add all its attributes to table as field.

• Add the primary key of identifying entity set.

• Declare all foreign key constraints.


Mapping Hierarchical Entities -

ER specialization or generalization comes in the form of hierarchical entity sets.


Mapping Process -
• Create tables for all higher-level entities.

• Create tables for lower-level entities.

• Add primary keys of higher-level entities in the table of lower-level entities.

• In lower-level tables, add all other attributes of lower-level entities.

• Declare primary key of higher-level table and the primary key for lower-level table.

• Declare foreign key constraints.



Relational Schema –
A relational schema is a blueprint used in database design to represent the data to be
entered into the database and describe how that data is structured in tables (called
relations in relational

schemas). The schema describes how those tables relate to each other.
In the relational schema, the table, or relation, consists of a set of named, but unsorted,
columns
(called attributes in relational schemas) and an undefined number of unnamed and
unsorted rows (called tuples in relational schemas). Each row is unique, but the rows can
be moved around as needed and stored in any order, modified, or deleted without
impacting the efficient operation of the database.


Types of relational
model - The

One -ToMany
Model

The most common relational model is one where a single record in the parent
table relates to multiple records in the child table.

The One-to-One Model


If your data requires that one record in the parent table be related to only
one record in the child table, you have a one-to-one model.

The Many-to-Many Model


In some cases, you might have data in which many records in one table can
relate to many records in another table.


Converti
CODE NAME ADRESS ng the
Bank
entity
set‟s into
relationa
2021 ABC BANK AIROLI l
database
table as
follows:
Schema : Bank-> { code, b_name, b_add }


Converting the Branch entity set‟s into relational database table as follows:

BRANCH_ID NAME ADRESS

101 ABC BANK AIROLI

102 ABC BANK AIROLI

103 ABC BANK AIROLI

Schema : Branch-> {br_id, br_name, br_add }


Converting the Account entity set‟s into relational database table as
follows:

ACC_NO ACC_TYPE BALANCE

ABC001 SAVINGS 76876

ABC002 SALARY 90897

ABC003 FIXED DEPOSIT 232334

Schema : Account-> {acc_no, acc_type, acc_bal }



Converting the Loan entity set‟s into relational database table as follows:

LOAN_ID LOAN_TYPE AMOUNT

LOAN001 HOME 800000

LOAN002 PERSONAL 20000

LOAN003 CAR 500000

Schema : Loan-> {l_id, l_type, l_amt }


Converting the Customer entity set‟s into relational database table as
follows:

CUS_ID NAME ADDRESS PHONE_NO

CSID001 MAYUR GHARAT 101, ABC, AIROLI 123345678

CSID002 PUSHKARAJ CHAUDHARY 102, BCD, AIROLI 987655432

CSID003 SAKSHI KHANDEKAR 103, XYZ, AIROLI 998855443

Schema : Customer-> {c_id, c_name, c_add, c_pno}

CONCLUSION :

The conversion of ER- model to Relational model for the given problem statement
R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature
marks) marks) marks) marks) marks) marks)
EXPERIMENT NO: 03
Date of performance:
Date of submission:

AIM: Create a database using Data Definition Language (DDL) and apply integrity
constraints for the specified System.

PROBLEM STATEMENT: To execute DDL commands for a Bank Management system


consisting of a set of bank, a set of branch, a set of loan , a set of customer and a set of
account.

THEORY:

Database:
A database in SQL Server is made up of a collection of tables that stores a specific set of
structured data. A table contains a collection of rows, also referred to as records or tuples,
and columns, also referred to as attributes. Each column in the table is designed to store a
certain type of information,
for example, dates, names, dollar amounts, and numbers.


Tables:

Tables are database objects that contain all the data in a database. In tables, data is logically
organized in a row-and-column format similar to a spreadsheet. Each row represents a
unique record,
and each column represents a field in the record.


DDL commands
Data Definition Language (DDL) statements are used to define the database structure or
schema. Data Definition Language describes how the data should exist in the database.

DDL includes commands such as CREATE, ALTER, and DROP statements. DDL are
used to CREATE, ALTER, OR DROP the database objects (Table, Views, Users).

Integrity constraints
In Database Management Systems, integrity constraints are pre-defined set of rules that are
applied on the table fields(columns) or relations to ensure that the overall validity, integrity,
and consistency of the data present in the database table is maintained. There are 6 integrity
constraints primary key, not null, check, default, unique, foreign key. ➢

Commands used in DDL are as follows:

1. Command: CREATE DATABASE

Purpose: This command is used to create a new database for the user.

Syntax: CREATE DATABASE databasename;

2. Command: SHOW DATABASE

Purpose: The command is used to display the existing databases for the user.

Syntax: SHOW DATABASES;


2. Command: USE DATABASE

Purpose: The command is used to use a particular database for creation of tables.

Syntax: USE databasename

3. Command: DROP DATABASE

Purpose: The command is used to remove an existing database or a particular database.

Syntax: DROP DATABASE databasename

4. Command: CREATE TABLE

Purpose: The command is used to create a table in a particular database with provided entities
bearing respective data types.

Syntax: CREATE TABLE table_name


( column1 datatype,
column2 datatype,

....
);

5. Command: SHOW TABLE

Purpose: This command is used to display the list of tables in a particular database.

Syntax: show tables;

6. Command: ALTER TABLE


Purpose: The alter table statement is used to add, delete, or modify columns in an existing table. It
can also be used to add and drop various constraints on an existing table

• ADD
To add data to column or table.

Syntax:
ALTER TABLE table_name
ADD column_name datatype;

• MODIFY

To change the data type of a column in a table

Syntax:

ALTER TABLE table_name


MODIFY COLUMN column_name datatype;
• DROP

To delete a column in a table

Syntax:

ALTER TABLE table_name


DROP COLUMN column_name;

8. Command: DROP TABLE

Purpose: This command is used to drop the table from the existing database.

Syntax:

DROP TABLE tablename;

9. Command: DROP DATABASE


Purpose: This command is used to drop the database from the
memory. Syntax:

DROP DATABASE databasename


PROCEDURE:

APPLICATIONS OF THE ABOVE SQL COMMANDS ON CASE STUDY:

1) Before executing any commands on Sql one must create a database ,in order to
execute other or any further commands easily.

1) CREATE DATABASE:- create database b_30

ENLIST ALL THE DATABASES ON SYSTEM:- show databases;

2) In order to see if the database if made use show database: to view and to use or access
a particular database instruction use_database_name ; is done.
3) Then we need to create tables for the all the entities.
Create suitable tables for the desired database.

Creating Hospital entity table:

Creating Branch entity table:

Creating Account entity table:

Creating Customer entity table :


Creating Loan entity table :

Creating Staff entity table :

5) Using ALTER command for the given case


a).add:-- alter table Staff add s_sal int;
b).modify:-- alter table staff modify s_name char(25);

c).drop:--alter table staff drop s_sal;


6)Using. RENAME table cmd:-- rename table customer to cust;

7).Using DROP cmd:- drop database b_30;

CONCLUSION: Therefore, created a database using Data Definition Language (DDL) and
applied integrityconstraints for the specified System.

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks)
EXPERIMENT NO: 04
Date of performance:
Date of submission:

AIM: To apply DML Commands for the specified system.

PROBLEM STATEMENT: To execute DML commands for a Bank Management system


consisting of a set of bank, a set of branch, a set of loan ,a set of account and set of customer.

THEORY:

DML Commands:
• DML is an abbreviation for Data Manipulation Language.
• Data Manipulation Language or DML represents a collection of programming languages
explicitly used to make changes in the database, such as: o CRUD operations to create,
read, update, and delete data o Using the INSERT, SELECT, UPDATE and
Delete commands.
• DML commands are often part of a more extensive database language, for instance, SQL
(Structure Query Language). These DML commands may have a specific syntax to
manage data in that language.
• DML Commands provide a way to read, update, delete, or merge data precisely. In the
beginning, DML commands were part of computer programs only, but with the
popularity ofSQL, they have now become a part of database management.
• Data Manipulation Languages (DML) have two primary classifications: Procedural and
Non- procedural programming (declarative programming).

Commands used in DML are as follows:

1. Command: INSERT:

Purpose: The INSERT query command in SQL provides a way to add new rows of
information or data inside a specific database.

Syntax:

INSERT INTO table_name (column1,


column2, column3, ...) VALUES (value1,
value2, value3, ...);
2. Command: UPDATE:

Purpose:The UPDATE command provides a way to make changes/update or modify


the values present in a table‟s column.

Syntax:

UPDATE table_name
SET column1 = value1, column2
= value2, ...
WHERE condition;
3. Command: DELETE:

Purpose: DELETE command provides a way to delete a single column or multiple


columns from a table‟s specific row.

Syntax:

DELETE FROM table_name


WHERE condition;

4. Command: SELECT:

Purpose:

SELECT is the primary fundamental query command used with FROM


and WHERE to give direction to the commands.

SELECT: Command to choose/select an attribute from its condition


defined by the WHERE condition.

FROM: Defines the relation for taking input or values for


selection in the query.

WHERE: Defines the conditions to get specific results.

Syntax:

SELECT column1, column2, ... FROM table_name;

SELECT column1, column2, ... FROM


table_name WHERE condition;

5. SPECIAL OPERATORS:

Special operators are the keywords which are reserved in MySQL for particular
functions. Some ofthem are in, like, between.

I. Command: IN OPERATOR

Purpose:
It is a logical operator. It allows to test whether a specified value matches any
value in a list. The IN returns 1 when the search value present within the range
otherwise returns 0.

Syntax:

SELECT column_name(s) FROM table_name


WHERE column_name IN (value1, value2, ...);
II. Command: LIKE OPERATOR
Purpose:

It is a logical operator. It is used to search for a specified pattern in a column. The


LIKE operator is used in the Where clause of the Select , Update and Delete.

Syntax:

SELECT column1, column2, ... FROM


table_name WHERE column N LIKE pattern;

III. Command: BETWEEN OPERATOR

Purpose:

It is a logical operator. This operator is used to select values within a given range.

Syntax:

SELECT column_name(s) FROM table_name


WHERE column_name BETWEEN value1 AND value2;

6. Command: NULL:

Purpose:

A field with a NULL value is a field with no value. If a field in a table is


optional, it is possible to insert a new record or update a record without adding
a value to this field. Then, the field will be saved with a NULL value.

Syntax:

SELECT column_name FROM table_name


WHERE column_name IS NULL;
SELECT column_name FROM table_name
WHERE column_name IS NOT NULL;

7. Command: ALIAS:

Purpose:

ALIASES are used to give a table, or a column in a table, a temporary name.


Aliases are often used to make column names more readable. An alias only exists
for the duration of that query.

Syntax:

SELECT column_name AS alias_name FROM table_name;


8. Command: ORDER BY:
Purpose:

The ORDER BY keyword is used to sort the result-set in ascending or descending


order.
The ORDER BY keyword sorts the records in ascending order by default. To
sort the records in descending order, use the DESC keyword.

Syntax:

SELECT column1, column2, ... FROM table_name


ORDER BY column1, column2, ... ASC/DESC;

PROCEDURE:

APPLICATIONS OF THE ABOVE SQL COMMANDS ON CASE STUDY:

1) Using INSERT cmd in order to insert data in tables

A) INSERTING TUPLES IN BRACNH


B) INSERTING TUPLES IN ACCOUNT TABLE

C) INSERTING IN LOAN TABLE

D) INSERTING IN CUST TABLE


2) USING DELETE CMD :-

QUERY: To remove c_id = 14 from cust table


3) USINGUPDATECMD:-
QUERY:To updatec_name = PDC where c_id = 2

4).USINGSELECTcmds with the help of certain querie-Qs:UERY1) List down all


the Banks.

QUERY2) Displayall theloan id and loan type details between 21000 and 800000

QUERY3) Display all thecustomer details name starting with. P

QUERY4) List down number of loan given by ba.nk

CONCLUSION: Therefore, applied DML commands for the specified system.

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks0
EXPERIMENT NO: 05
Date of performance:
Date of submission:

AIM: To Perform Simple queries, string manipulation operations and aggregate functions.

PROBLEM STATEMENT: To execute functions-based commands for a Bank Management


system consisting of a set of bank, a set of branch, a set of loan ,a set of account and set of
customer.

THEORY:

➢ Arithmetic Functions
An arithmetic function executes a mathematical operation usually based on input values
that are provided as arguments, and return a numeric value as the result of the operation.
Arithmetic functions operate on numeric data such as decimal, integer, float, real,
smallint, and tinyint. By default, the precision of built-in operations on float data type data
is six decimal places. Following are different types of arithmetic functions
o ADD o SUB o MUL
o DIV
o MOD


String Functions
The SQL Server provides various SQL String Functions. They allow us to alter the
individual characters in a string, compare strings, search strings, to extract substrings,
copy of a string. You can also use these SQL String Functions to convert strings to
lowercase or uppercase. Following are list of string functions
Like
o Not Like o Substring o In string
o Length o Concatenation o Replace

SQL Aggregate Functions
SQL aggregate functions return a single value, calculated from values in a column.
Following is list of aggregate functions.
AVG(), COUNT(),FIRST() L,AST(),MAX(),MIN(),SUM()

Group by

The GROUP BY clause is a SQL command that is used to group rows that have the same
values. The GROUP BY clause is used in the SELECT statement . Optionally it is used in
conjunction with aggregate functions to produce summary reports from the database. That's
what it does, summarizing data from the database. The queries that contain the GROUP

BY clause are called grouped queries and only return a single row for every grouped item.

Having by
The HAVING clause is used in the SELECT statement to specify filter conditions for a
group of rows or aggregates. The HAVING clause is often used with the GROUP BY clause
to filter groups based on a specified condition. If the GROUP BY clause is omitted, the
HAVING clause behaves like the WHERE clause. specify a condition in the HAVING
clause. If a row, which is generated bythe group by clause, causes the group condition to
evaluate to true, the query will include it in the result set. Notice that the HAVING clause
applies a filter condition to each group of rows, while the WHERE clause applies the filter
condition to each individual row. MySQL evaluates the HAVING clause after the FROM,
WHERE, SELECT and GROUP BY clauses and before ORDER BY, and LIMIT clauses.

Commands used are as follows:


Arithmetic Functions

1. Command: ADD

Purpose:

Addition function is used to add value in any column irrespective

Syntax:

SELECT <Expression>+<expression>... FROM


[table_name] WHERE [expression];

2. Command: SUB

Purpose:
Subtraction function is used to subtract value in any column irrespective of the
tuple.

Syntax:

SELECT <Expression>-<expression>... FROM


[table_name] WHERE [expression];
3. Command: MUL

Purpose:

Multiplication function is used to multiply value in any column irrespective of the


tuple.

Syntax:

SELECT <Expression>*<expression>... FROM


[table_name] WHERE [expression];

4. Command: DIV

Purpose:

Division function is used to divide value in any column irrespective of the tuple.

Syntax:

SELECT <Expression>/<expression>... FROM


[table_name] WHERE [expression];

5. Command: MOD

Purpose:

Modulus function is used to mod value in any column irrespective.

Syntax:

SELECT <Expression>%<expression>... FROM


[table_name] WHERE [expression];

String Functions
6. Command: LIKE

Purpose:

Like operator is used to display the values which are similar to the pattern which
is provided in where clause. The pattern includes starting with value, ending with
value, in between value, value at n th position etc.

Syntax:

SELECT column1, column2, ... FROM


table_name WHERE column LIKE pattern;
7. Command: NOT LIKE

Purpose:

Not Like operator is used to display the values which are not similar to the pattern
which is provided in where clause. The pattern includes starting with value,
ending with value, in between value, value at n th position etc.

Syntax:

SELECT column1, column2, ... FROM


table_name WHERE column NOT LIKE pattern;

8. Command: SUBSTRING

Purpose:

Substring function is used to print output of any column from given position after
column name.

Syntax:

SUBSTRING(string, start, length)

9. Command: INSTRING

Purpose:

This function is used to display the position of the value provided after the
column name in the syntax.

Syntax:
INSTR(substring, string, start)

10. Command: LENGTH

Purpose:

This function is used to display the length of the string in the provided column.

Syntax:
LENGTH(column_name)

11. Command: CONCATENATION

Purpose:

This function is used to join two strings. The string which is to be


concatenated is given afterthe column name.

Syntax:

CONCAT(string1, string2,…., string_n)


12. Command: REPLACE

Purpose:

Replace function is used to replace the characters in column with where


condition.

Syntax:

REPLACE(string, old_string, new_string)

Aggregate Functions

13. Command: COUNT

Purpose:

The COUNT function returns the total number of values in the specified field. It
works on both numeric and non-numeric data types. All aggregate functions by
default exclude nulls values before working on the data.
Syntax:

SELECT COUNT(column_name) FROM


table_name WHERE condition;

14. Command: SUM

Purpose:

MySQL SUM function which returns the sum of all the values in the
specified column. SUM works on numeric fields only. Null values are
excluded from the result returned.

Syntax:

SELECT SUM(column_name) FROM


table_name WHERE condition;

15. Command: MIN

Purpose:

The MIN function returns the smallest value in the specified table field.

Syntax:

SELECT MIN(column_name) FROM


table_name WHERE condition;
16. Command: MAX

Purpose:

Just as the name suggests, the MAX function is the opposite of the MIN function.
It returns the largest value from the specified table field.

Syntax:

SELECT MAX(column_name) FROM


table_name WHERE condition;

17. Command: AVG

Purpose:
MySQL AVG function returns the average of the values in a specified
column. Just like the SUM function, it works only on numeric data types.

Syntax:

SELECT AVG(column_name) FROM


table_name WHERE condition;

18. Command: Group By

Purpose:

The GROUP BY clause is used in the SELECT statement. Optionally it is


used in conjunction with aggregate functions to produce summary reports
from the database.

Syntax:

SELECT column_name(s) FROM table_name WHERE


condition GROUP BY column_name(s) ORDER BY
column_name(s);

19. Command: Having

Purpose:

The HAVING clause was added to SQL because the WHERE keyword
cannot be used with aggregate functions.

Syntax:

SELECT column_name(s) FROM table_name WHERE


condition GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
APPLICATIONS OF THE ABOVE SQL COMMANDS ON CASE STUDY:

QUERIES:

• Using aggregate function display the number of loan given by bank.

• Using aggregate function display the number of patients whose gender is male.

• Display the total salary of Doctor.

• Display the maximum amount of loan given by bank.

• Display the minimum amount of loan given by bank.

• Display the overall average amount of loan given by bank.


//USING GROUP BY CLAUSE//

• Display the number of customer.

• Display the avg of l_amt .

Display the number of r_id who have a common Examination date and arrange the result in
an descending order.

• Display the count along with the doctor id of those doctor whose sum of salary is less than
54 K. The count should be greater than 2.

//USING SOME OF THE ARITHMETIC FUNCTIONS//

• Sqrt(n):-This command is used to find the square root of the value n

• Mod(n1,n2)- This command is used to find the difference between values n1 and n2
• Sign():-this cmd is used to check the sign flag for the mentioned value.

//APPLYING SOME OF THE STRING FUNCTIONS//

• char_length():- This is used to find the length of the entered string

• concat(): - This is used to join two strings.


• elt():- It is used to returns the string which is at index number specified in the argument
list.
• upper():

reverse(): It is used to reverse a string.

// USING DATE FUNCTIONS//

• curdate(),curtime():-It displays current time and date.


• id()
• QUERY: Display the pno of numbers.
CONCLUSION: Therefore, Perform Simple queries, string manipulation operations and
aggregate functions.

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks)
EXPERIMENT NO: 06
Date of performance:
Date of submission:

AIM: To implement various Join operations.

PROBLEM STATEMENT: To implement various Join operations commands for a Bamk


Management system consisting of a set of bank, a set of branch, a set of loan and a set of
account and set of customer.

THEORY:


Join command
JOINS in SQL are commands which are used to combine rows from two or more tables,
based on a related column between those tables. There are predominantly used when a user
is trying to extract data from tables which have one-to-many or many-to-many relationships
between them. A JOIN clause is used to combine rows from two or more tables, based on a
related column between them. It creates a set that can be saved as a table or used as it is. A
JOIN is a means for combining columns from one (self-join) or more tables by using
values common to each. ANSI-standard SQL specifies five types of JOINS:

• Inner Join
• Left Outer Join
• Right Outer Join
• Full outer Join
• Natural join

Commands used are as follows:
1. Command: Inner

Purpose:

This type of join returns those records which have matching values in both tables.
So, if you perform an INNER join operation between the Bank table and the
Projects table, all the tuples which have matching values in both the tables will be
given as output.

Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....

FROM Table1 INNER JOIN Table2

ON Table1.MatchingColumnName = Table2.MatchingColumnName;
2. Command: Left outer join

Purpose:

The LEFT JOIN or the LEFT OUTER JOIN returns all the records from the left
table and also those records which satisfy a condition from the right table. Also,
for the records having no matching values in the right table, the output or the
result-set will contain the NULL values.

Syntax:

SELECT Table1.Column1,Table1.Column2,Table2.Column1,....

FROM Table1 LEFT JOIN Table2

ON Table1.MatchingColumnName = Table2.MatchingColumnName;

3. Command: Right outer join

Purpose:

The RIGHT JOIN or the RIGHT OUTER JOIN returns all the records from the
right table and also those records which satisfy a condition from the left table.
Also, for the records having no matching values in the left table, the output or the
result-set will contain the NULL values.

Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1 RIGHT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
4. Command: Full outer join

Purpose:

Full Join or the Full Outer Join returns all those records which either have a
match in the left(Table1) or the right(Table2) table.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
UNION Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
5. Command: Self Join
Purpose:
A self -join is a join in which a table is joined with itself (which is also called
Unary relationships), especially when the table has a FOREIGN KEY which
references its own PRIMARY KEY. To join a table itself means that each row of
the table is combined with itself and with every other row of the table.
Syntax:
SELECT a.column_name,
b.column_name.. FROM table1 a, table1 b
Where a.common_field=b.common_field;

APPLICATIONS OF THE ABOVE SQL COMMANDS ON CASE STUDY:

QUERIES:
• Using inner join, join c_add from cust and branch.

• Using left join, join c_name from cust and branch .

• Using right join, join c_add from cust and branch.

• Using full outer join, join .


• Using natural join, join br_add from br_id and br_name

CONCLUSION: Therefore, implemented various Join operations.

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks)
EXPERIMENT NO: 07
Date of performance:
Date of submission:

AIM: To perform Nested and Complex queries.

PROBLEM STATEMENT: To perform Nested and Complex queries for a Bank


Management system consisting of a set of bank, a set of branch, a set of loan , a set of account
and set of customer.

THEORY:

Nested queries
A nested query is a query that has another query embedded within it. The embedded
query is called a subquery. A subquery typically appears within the WHERE clause of

a query. It can sometimes appear in the FROM clause or HAVING clause.


Union
The SQL UNION operator is used to combine the result sets of 2 or more SELECT
statements. It removes duplicate rows between the various SELECT statements.
Each SELECT statement within the UNION must have the same number of fields

in the result sets with similar data types.


Union all
The SQL UNION ALL operator is used to combine the result sets of 2 or more
SELECT statements. It does not remove duplicate rows between the various
SELECT statements (all rows are returned). Each SELECT statement within the
UNION ALL must have the same number of fields in the result sets with similar
data types.


Intersect
The SQL INTERSECT operator is used to return the results of 2 or more SELECT
statements. However, it only returns the rows selected by all queries or data sets. If
a record exists in one query and not in the other, it will be omitted from the
INTERSECT results.

Minus
The SQL MINUS operator is used to return all rows in the first SELECT statement
that are not returned by the second SELECT statement. Each SELECT statement
will define a dataset. The MINUS operator will retrieve all records from the first
dataset and then remove from the results all records from the second dataset.

Commands used are as follows:
1. Command: Nested queries

Purpose:

A nested query is a query that has another query embedded within it. The embedded
query is called a subquery. A subquery typically appears within the WHERE clause
of a query. It can sometimes appear in the FROM clause or HAVING clause.

2. Command: Union

Purpose:

The UNION operator is used to combine the result-set of two or more SELECT
statements.

Syntax:
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
3. Command: Union all

Purpose:
The UNION all operator allows duplicate values to store. .
Syntax:
SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;
4. Command: Intersect

Purpose:

The SQL INTERSECT operator is used to return the results of 2 or more


SELECT statements. However, it only returns the rows selected by all queries or
data sets. If a record exists in one query and not in the other, it will be omitted
from the INTERSECT results.

Syntax:

SELECT expression1, expression2, ... expression_n FROM


tables [WHERE conditions] INTERSECT

SELECT expression1, expression2, ... expression_n FROM


tables [WHERE conditions];
5. Command: Minus
Purpose:
MINUS compares the data in two tables and returns only the rows of data using
the specified columns that exist in the first table but not the second It would be
poss1"ble to get all of the results from the second table that don't exist in the
first by switching the table order in the query.
Syntu:
SELECT expression!, expression2, ... expression_n FROM
tables [WHERE conditions] MINUS

SELECT expression!, expression2, ... expression_n FROM

tables [WHERE conditions];

APPLICATIONS OF THE ABOVE SQL COMMANDS ON CASE STIJDY:

QUERIES;
.Find alt details of1oen id and customer name.

CONCLUSION: Therefore, perfo1med Nested and Complex queries.

Rl R2 R3 R4 R5 TOTAL

5 5 5 5 s 25

SIGN:
GRADE:
DATE:
Experiment no.8
Date of performance:
Date of submission:

Aim: To perform DCL and TCL commands

Theory:
Data Control Language (DCL):
DCL is the abstract of Data Control Language. Data Control Language includes commands
such as GRANT, and concerns with rights, permissions and other controls of the database system.
DCL is used to grant / revoke permissions on databases and their contents. DCL is simple, but
MySQL permissions are a bit complex. DCL is about security. DCL is used to control the database
transaction. DCL statement allow you to control who has access to specific object in your database.
List of DCL commands. DCL includes commands such as GRANT and REVOKE which mainly
deals with the rights, permissions and other controls of the database system.

Examples of DCL commands:

1. GRANT-gives user‟s access privileges to database.


2. REVOKE-withdraw user‟s access privileges given by using the GRANT command.

Transaction Control Languages (TCL)


TCL stands for Transaction Control Languages. These commands are used for maintaining
consistency of the database and for the management of transactions made by the DML commands. A
Transaction is a set of SQL statements that are executed on the data stored in DBMS. Whenever any
transaction is made these transactions are temporarily happen in database. So to make the changes
permanent, we use TCL commands.

The TCL commands are:

1. COMMIT
2. ROLLBACK

Commands:

1. Command: GRANT.
Purpose: It provides the user's access privileges to the database. In the MySQL database
offers both the administrator and user a great extent of the control options.
Syntax:
GRANT { ALL | statement [ ,...n ] } TO security_account [ ,...n ]
[Document title]

2. Command: REVOKE.
Purpose: The REVOKE statement enables system administrators and to revoke the
privileges from MySQL accounts.
Syntax:
REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user] ...

3. Command: COMMIT.
Purpose: This command is used to save the data permanently.
Syntax:
commit;

4. Command: ROLLBACK.
Purpose: This command is used to get the data or restore the data to the last save point or
last committed state.
Syntax:
rollback;

- Applications

1. Grant Update permission to user „temp‟


-> grant update on customer to temp;

2. Revoke Update permission to user „temp‟


-> revoke update on customer to temp;

3. Perform commit on table customer after inserting values


->
SELECT * FROM customers;
commit;

4. Perform rollback after deleting values


->
delete from customer where
cust_id=‟CSID001‟; rollback;

Conclusion:
Therefore, performed DCL and TCL commands

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks)
[Document title]

EXPERIMENT NO.9:
Date of performance:
Date of submission:

AIM:
To write PL/SQL(Functions)and to understand stored procedures in SQL.

Theory:-

FUNCTION:
A function is a subprogram that computes a value.syntax
Create or replace function<function_name>[argument]
Return datatype is
(local declaration)
begin
(executable statements)[Exception]
(exception handlers)End

PROCEDURE:
create [or replace] procedure procedurename
[parameter[in/out/in/in out] datatype [:=/default
expression]
[(parameter)]is/as
declaration begin
pl/sql codes
[exception]
end

Input:-
DELIMITER $$
create procedure temp_function()
begin
select * from Customer;
END $$
DELIMITER ;

CALL temp_function();

Output:-

RESULT: Thus the functions and stored procedures are executed in SQL.
Problems:
1) procedure to find whether a given number is odd or even
2) procedure to display 1-10 using while
3) Procedure to display some numbers lesser than given number.

RESULT: The trigger procedure has been executed successfully for both before and after
sequences.

R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature


marks) marks) marks) marks) marks) marks)
[Document title]
EXPERIMENT NO.10
Date of performance:
Date of submission:

AIM:
Implementation of Views and Triggers.

OBJECTIVES:
To implement views

THEORY:
A view is the tailored presentation of data contained in one or more table andcan also be
said as restricted view to the data‟s in the tables. A view is a “virtual table” or a “stored
query”
which takes the output of a query and treats it as a table. The table upon which a view is
created
is called as base table . A view is a logical table based on a table or another view. A view
contains no data of itsown but is like a window through which data from tables can be
viewed
or changed. The tables on which a view is based are called base tables. The view is stored as
a
SELECT statement in the data dictionary .

Advantages of a view:
a. Additional level of table security.
b. Hides data complexity.
c. Simplifies the usage by combining multiple tables into a single table

Creating a view:
Syntax:
Create[or replace] view <view name>
AS
Sub query
[with check option]
Create or Replace a view:
Create or replace view
<view name>
AS
SUB QUERY
[with check option]
[with read only];

Dropping a view:
Drop view <view name>;
[Document title]

Applications :

1. Create a view of students who are in the ABC BANK

create view Branch_name as select * from branch where br_name="ABC BANK";


select * from Branch_name;

Output:-

3. Replace a view of Students from course Computer to Mechanical.

CREATE or Replace view Branch_name as select * from branch where br_add =


"AIROLI";
select * from Branch _name;

Output:-
3. Drop the created view

DROP VIEW Branch_name;

Result
Thus the view creation commands are executed successfully.

TRIGGER
AIM
Create a Trigger for EMP table it will update another table SALARY while
insertingvalues

OBJECTIVES
To develop and execute a Trigger for Before and After update/Delete/Insertoperations on
a table

THEORY:

PROCEDURE:
step 1: start
step 2: initialize the trigger with specific table id.
[Document title]

step 3:specify the operations (update, delete, insert) for which the trigger has tobe
executed.
step 4: execute the trigger procedure for both before and after sequences
step 5:carryout the operation on the table to check for trigger execution.
step 6: stop

Trigger Syntax
CREAE[OR REPLACE] TRIGGER <Trigger_name>
[<ENABLE | DISABLE>]
<BEFORE | AFTER>
<INSERT | UPDATE | DELETE>
ON <Table_Name>
[FOR EACH ROW]
DECLARE
<Variable_name>;
BEGIN
<Trigger _code>;
END

1. Create a trigger to insert a values in customer section when update operation is carried out
in customer table whose cus_id < 10.

->delimeter $$
create trigger
upd_customer after update
on customer for each row
begin
if new.cus_id < 10 then
insert into customer values(new.cus_id);
end if;
end;
$$

2. Drop the created trigger


Drop trigger upd_customer;

RESULT:

The trigger procedure has been executed successfully for both before and after sequences
R1(5 R2(5 R3(5 R4(5 R5(5 Total(25 Signature
marks) marks) marks) marks) marks) marks)

You might also like