DM Lab Manual DI03016041
DM Lab Manual DI03016041
Laboratory Manual
Database Management
DI03016041
Institute’s Vision:
Institute’s Mission:
Department’s Vision:
Department’s Mission:
Database Management (DI03016041)
Certificate
(DI03016041)” for the academic year: ……………………….… Term: Odd prescribed in the
GTU curriculum.
Place: ………………………….
Date: ………………………….
4 | Page
Database Management (DI03016041)
Sr.
Practical Outcome/Title of experiment CO1 CO2 CO3 CO4 CO5
No.
1. Basics of Database, its applications and
Data Models
a. Prepare a report on Current Database
Trends. - - - -
b. Prepare a list of most famous websites
and Mobile Applications with
Database Tools used in it.
2. Entity Relationship Diagrams
a. Draw ER-Diagram for Banking
Management System - - - -
b. Convert ER-Diagram to relational
schema.
3. SQL Commands
a. Design the below given schemas
using SQL Command – “Create”.
Decide the appropriate data type for
each column.
b. Insert data in above tables using
SQL Command “Insert”. - - - -
c. Retrieve data from tables in
Practical 2 using Data SQL
command- “Select”.
a. Write SQL queries to use Update,
alter, rename, delete, truncate and
distinct
4. In-built Functions (Part – 1)
a. Write SQL queries to use various
date functions. - - - -
a. Write SQL queries to use various
numeric functions
5 | Page
Database Management (DI03016041)
6 | Page
Database Management (DI03016041)
7 | Page
Database Management (DI03016041)
8 | Page
Database Management (DI03016041)
9 | Page
Database Management (DI03016041)
10 | Page
Database Management (DI03016041)
11 | Page
Database Management (DI03016041)
Date: _________________
A. Objective:
DBMS helps to understand how data is stored, organized, and accessed in computer
systems, and its applications in managing large amounts of information efficiently
through the use of data models.
E. Practical Outcome(PRo)
G. Prerequisite Theory:
What is Data?
Data refers to the raw facts and figures that are collected and stored for future use. It
can be in any form, such as text, numbers, images, or sound.
12 | Page
Database Management (DI03016041)
What is Information?
What is DBMS?
DBMS stands for Database Management System. It is a software system that allows
users to create, maintain, and manage databases.
What is Metadata?
Metadata refers to the data that describes other data. It provides information about the
structure, content, and context of data.
Data items are the smallest unit of information in a database. They represent a single
fact or piece of information.
Fields are the columns or attributes of a table in a database. They represent the
different types of information that can be stored in a table.
Records are the rows or instances of a table in a database. They represent a collection
of related data items.
A data dictionary is a centralized repository that stores metadata about the data
elements and data structures in a database. It provides information about the data
types, relationships, constraints, and other properties of the database.
13 | Page
Database Management (DI03016041)
A schema is a logical structure that defines how data is organized and stored in a
database. It includes the description of tables, attributes, relationships, and
constraints.
What is a Sub-schema?
A sub-schema is a subset of the schema that describes the part of the database that is
relevant to a particular user or group of users. It provides a view of the database that is
tailored to the needs of the user.
DBMS Architecture
The DBMS design depends upon its architecture. The basic client/server architecture
is used to deal with a large number of PCs, web servers, database servers and other
components that are connected with networks.
The client/server architecture consists of many PCs and a workstation which are
connected via the network. DBMS architecture depends upon how users are connected
to the database to get their request done.
14 | Page
Database Management (DI03016041)
o 1-Tier Architecture
o 2-Tier Architecture
15 | Page
Database Management (DI03016041)
o 3-Tier Architecture
The 3-Tier architecture contains another layer between the client and
server. In this architecture, client can't directly communicate with the server.
The application on the client-end interacts with an application server which
further communicates with the database system. End user has no idea about
the existence of the database beyond the application server. The database also
has no idea about any other user beyond the application. The 3-Tier
architecture is used in case of large web application.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Hardware: Computer Computer (i3-i5 preferable), RAM minimum
1
System 2 GB and onwards
2 As Per
Operating System Windows/ Linux
Batch
3 Software Oracle Size
16 | Page
Database Management (DI03016041)
NA
J. Report:
17 | Page
Database Management (DI03016041)
Prepare a list of most famous websites and Mobile Applications with Database
Tools used in it.
18 | Page
Database Management (DI03016041)
3) A schema is a structure.
4) In tier, the database is directly available to the user.
L. References / Suggestions
1. [Link]
2. [Link]
3. [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
19 | Page
Database Management (DI03016041)
Date: _________________
Practical No.2: Entity Relationship Diagrams
a. Draw ER-Diagram for Banking Management System
b. Convert ER-Diagram to relational schema.
A. Objective:
20 | Page
Database Management (DI03016041)
E. Practical Outcome(PRo)
Students will be able to create E-R Diagram for any system and its conversion to
relational schema.
G. Prerequisite Theory:
Entity A real-world object or concept that has a unique identity and can be
distinguished from other objects or concepts in the system.
For example, id, age, contact number, name, etc. can be attributes of a
student.
21 | Page
Database Management (DI03016041)
Primary key A unique identifier for an entity that is used to ensure its uniqueness
and enable efficient data retrieval, such as an employee ID or a
customer account number. Primary key is represented by and ellipse
with the text underlined.
Foreign key A field in one table that refers to the primary key of another table,
creating a relationship between the two tables and enabling data
retrieval and manipulation.
Candidate key A minimal super key that uniquely identifies an entity, meaning that
it cannot be further reduced without losing its uniqueness.
Weak entity An entity set that cannot be uniquely identified by its own attributes
set alone, but depends on a related entity set and a partial key, called a
discriminator.
An attribute that composed of many other attributes is known as a
Composite composite attribute. The composite attribute is represented by an
22 | Page
Database Management (DI03016041)
An attribute can have more than one value. These attributes are
Multivalued known as a multivalued attribute. The double oval is used to
Attribute represent multivalued attribute.
For example, a student can have more than one phone number.
23 | Page
Database Management (DI03016041)
Superclass
A general entity type that has one or more specialized entity types that inherit
its attributes and relationships.
Subclass
Types of Relationships
a. One-to-One Relationship
b. One-to-many relationship
When only one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then this is
known as a one-to-many relationship. For example, Scientist can invent many
inventions, but the invention is done by the only specific scientist.
24 | Page
Database Management (DI03016041)
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one
instance of an entity on the right associates with the relationship then it is
known as a many-to-one relationship. For example, Student enrolls for only
one course, but a course can have many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than
one instance of an entity on the right associates with the relationship then it is
known as a many-to-many relationship. For example, Employee can assign by
many projects and project can have many employees.
Generalization
25 | Page
Database Management (DI03016041)
Specialization
Inheritance
We use all the above features of ER-Model in order to create classes of objects
in object-oriented programming. The details of entities are generally hidden from the
user; this process known as abstraction.
26 | Page
Database Management (DI03016041)
For example, the attributes of a Person class such as name, age, and
gender can be inherited by lower-level entities such as Student or Teacher.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Hardware: Computer Computer (i3-i5 preferable), RAM minimum
1
System 2 GB and onwards
2 As Per
Operating System Windows/ Linux
Batch
3 Software Oracle Size
NA
27 | Page
Database Management (DI03016041)
J. Source code:
28 | Page
Database Management (DI03016041)
29 | Page
Database Management (DI03016041)
2) What is a cardinality?
a) Attribute type b) Entity type
c) Relationship type d) Primary key
3) What is an attribute?
a) Column name b) Primary key
c) Foreign key d) Data type
L. References / Suggestions
[Link]
[Link]
[Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
Date: _________________
30 | Page
Database Management (DI03016041)
A. Objective:
SQL commands is to facilitate efficient data management in databases by providing
functionalities such as inserting new data, retrieving specific information, updating
existing records, deleting unnecessary data, and altering table structures.
31 | Page
Database Management (DI03016041)
CO4: Apply SQL Commands for creating, manipulating and controlling databases.
E. Practical Outcome(PRo)
Students will be able to create and manipulate SQL tables.
G. Prerequisite Theory:
SQL Commands
SQL commands are instructions. It is used to communicate with the database. It
is also used to perform specific tasks, functions, and queries of data.
SQL can perform various tasks like create a table, add data to tables, drop the
table, modify the table, set permission for users.
32 | Page
Database Management (DI03016041)
DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc. All the command of DDL are auto-committed that means it
permanently save all the changes in the database. Here are some commands that
come under DDL:
a. CREATE
b. ALTER
c. DROP
d. TRUNCATE
a. CREATE:
It is used to create a new table in the database.
Syntax : CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[, .... ]);
Example : CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email
VARCHAR2(100), DOB DATE);
b. DROP:
It is used to delete both the structure and record stored in the table.
Syntax : DROP TABLE table_name;
Example : DROP TABLE EMPLOYEE;
c. ALTER :
It is used to alter the structure of the database. This change could be either to modify
the characteristics of an existing attribute or probably to add a new attribute.
Syntax: To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
d. TRUNCATE :
It is used to delete all the rows from the table and free the space containing the table.
Syntax : TRUNCATE TABLE table_name;
Example : TRUNCATE TABLE EMPLOYEE;
33 | Page
Database Management (DI03016041)
a. INSERT
b. UPDATE
c. DELETE
a. INSERT :
The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax: INSERT INTO TABLE_NAME (col1, col2, col3, ..... col N) VALUES (value1,
value2, value3, ..... valueN);
Or
INSERT INTO TABLE_NAME VALUES (value1, value2, value3, ...... valueN);
For example: INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");
b. UPDATE :
This command is used to update or modify the value of a column in the table.
For example : UPDATE students SET User_Name = 'Sonoo' WHERE Student_Id = '3'
c. DELETE :
It is used to remove one or more row from a table.
a. Grant
b. Revoke
34 | Page
Database Management (DI03016041)
SELECT : This is the same as the projection operation of relational algebra. It is used
to select the attribute based on the condition described by WHERE clause.
4. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Hardware: Computer Computer (i3-i5 preferable), RAM minimum
1
System 2 GB and onwards
2 As Per
Operating System Windows/ Linux
Batch
3 Software Oracle Size
I. Source code:
A) Design the below given schemas using SQL Command - ”Create”. Decide the
appropriate data type for each column.
(a) Create a table ACCOUNT with column account number, name, city,
balance, loan taken.
(b) Create a LOAN table with column loan number, account number, loan
amount, interest rate, loan date, remaining loan. (c)Create table
INSTALLMENT with column loan number, installment number, installment
date and amount.
(d) Create table TRANSACTION with column account number, transaction
date, amount, type of transaction, mode of payment.
(e) Show the structure of above tables using “Describe” command.
35 | Page
Database Management (DI03016041)
36 | Page
Database Management (DI03016041)
37 | Page
Database Management (DI03016041)
38 | Page
Database Management (DI03016041)
B) Input-Output:
C) Retrieve data from tables in Practical 2 using Data SQL command- “Select”.
(a) Display all rows and all columns of table Transaction.
(b) Display all rows and selected columns of table Installment.
(c) Display selected rows and selected columns of table Account.
(d) Display selected rows and all columns of table loan.
(e) Display the branch wise balance from account table.
(f) Display list of those branches that have balance greater than 1 Lakh rupees.
(g) Display the list of customers in descending order of their name from
account table.
(h) Display those records where mode of payment is “cheque”.
39 | Page
Database Management (DI03016041)
C) Input-Output:
D) Write SQL queries to use Update, alter, rename, delete, truncate and distinct.
Table: ACCOUNT.
(a) Change the name ‘pateljigar’ to ‘patelhiren’.
(b) Change the name and city where account number is A005. (new name =
‘kothari nehal’and new city = ‘patan’).
(c) Display only those records where loan taken status is ‘YES’.
(d) Add the new column (address varchar2 (20)) into table ACCOUNT.
(e) Create another table ACCOUNT_TEMP (acc_no, name, balance) from table
ACCOUNT.
(f) Rename the table ACCOUNT to ACCOUNT_MASTER.
(g) Update the column balance for all the account holders. (Multiply the balance by
2 foreach account holders)
(h) Delete the records whose account no is A004
Table: LOAN.
(a) For each loan holders Add 100000 Rs. Amount into the column loan_amt.
(b) For each loan holders Increase the interest rate 2%.
(c) Display only those records where loan holder taken a loan in month of January.
(d) Modify the structure of table LOAN by adding one column credit_no varchar2
(4).
(e) Display the Loan amount*2 of table LOAN.
(f) Display the records of table LOAN by date wise in ascending order.
(g) Display the records of table LOAN by account number wise in descending
Order.
(h) Increase the size 5 to 7 of column acc_no.
40 | Page
Database Management (DI03016041)
Table: INSTALLMENT.
(a) Change the Inst_Date ‘2-Feb-04’ to ’3-Mar-04’.
(b) Reduce 5000 amount from all Installment holders.
(c) Add the amount 5000 where loan no is ‘L003’ and ‘L002’.
(d) Change the column size of 5 to 7 where column name is Loan_no.
(e) Delete row where inst_no is ‘I001’.
(f) Only create a structure of table installment1 from table installment.
Table: TRANSACTION.
(a) Insert any duplicate value and display all the records without any duplicate
rows.
(b) Select all the records in descending order(account number wise).
(c) Display amt, date, and type of transaction by date wise
41 | Page
Database Management (DI03016041)
D) Input-Output:
3) Which SQL command is used to remove all data from a table in a database while
keeping the table structure intact?
a) TRUNCATE b) DELETE
c) REMOVE d) CLEAN
K. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
42 | Page
Database Management (DI03016041)
L. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
43 | Page
Database Management (DI03016041)
Date: _________________
Practical No.4: In-built Functions (Part – 1)
a. Write SQL queries to use various date functions.
b. Write SQL queries to use various numeric functions
A. Objective:
To proficiently use SQL queries with various date functions and numeric
functions to effectively manipulate and analyse date-related and numeric data in the
database.
44 | Page
Database Management (DI03016041)
1) Skill in using advanced numeric functions such as POWER, SQRT, LOG, and
TRUNC to perform complex calculations and generate insights from numerical
data.
E. Practical Outcome(PRo)
Students will be able to understand and use various date and numeric function.
G. Prerequisite Theory:
Numeric Function :-
1. ABS() : Returns the absolute value of numeric expression.
2. ACOS(): Returns the arccosine of numeric expression. Returns NULL if the value is
not in the range -1 to 1.
3. ASIN() : Returns the arcsine of numeric expression. Returns NULL if value is not in
the range -1 to 1
4. ATAN() : Returns the arctangent of numeric expression.
5. ATN2() : Returns the arctangent of the two variables passed to it.
6. CEILING() : Returns the smallest (closest to negative infinity) integer value that is
greater than or equal to this value.
7. COS() : Returns the trigonometric cosine of the given value.
8. COT() : Returns the trigonometric cotangent of the given value.
9. DEGREES() : Returns numeric expression converted from radians to degrees.
10. EXP() : Returns the base of the natural logarithm (e) raised to the power of passed
numeric expression.
11. FLOOR() : Returns the largest integer value that is not greater than passed numeric
expression.
45 | Page
Database Management (DI03016041)
12. LOG() : Returns the natural logarithm of the passed numeric expression.
13. LOG10() : Returns the base-10 logarithm of the passed numeric expression.
14. PI() : Returns the value of pi
15. POWER() : Returns the value of one expression raised to the power of another
expression
16. RADIANS() : Returns the value of passed expression converted from degrees to
radians.
17. RAND() : Returns the random value between 0 and 1.
18. ROUND() : Returns numeric expression rounded to an integer. Can be used to
round an expression to a number of decimal points
19. SIGN() : Returns the sign of a number, indicating whether it is positive, negative, or
zero.
20. SIN() : Returns the sine of numeric expression given in radians.
21. SQRT() : Returns the non-negative square root of numeric expression.
22. TAN() : Returns the tangent of numeric expression expressed in radians.
Date Function :
1. ADDDATE(): It returns a date after a certain time/date interval has been added.
2. ADDTIME(): It returns a time / date time after a certain time interval has been
added.
3. CURDATE(): It returns the current date.
4. CURRENT_DATE(): It returns the current date.
5. CURRENT_TIME(): It returns the current time.
6. CURRENT_TIMESTAMP(): It returns the current date and time.
7. CURTIME(): It returns the current time.
8. DATE(): It extracts the date value from a date or date time expression.
9. DATEDIFF(): It returns the difference in days between two date values.
10. DATE_ADD(): It returns a date after a certain time/date interval has been added.
11. DATE_FORMAT(): It formats a date as specified by a format mask.
46 | Page
Database Management (DI03016041)
12. DATE_SUB(): It returns a date after a certain time/date interval has been
subtracted.
13. DAY(): It returns the day portion of a date value.
14. DAYNAME(): It returns the weekday name for a date.
15. DAYOFMONTH(): It returns the day portion of a date value.
16. DAYWEEK(): It returns the weekday index for a date value.
17. DAYOFYEAR(): It returns the day of the year for a date value.
18. EXTRACT(): It extracts parts from a date.
19. FROM_DAYS(): It returns a date value from a numeric representation of the day.
20. HOUR(): It returns the hour portion of a date value.
21. LAST_DAY(): It returns the last day of the month for a given date.
22. LOCALTIME(): It returns the current date and time.
23. LOCALTIMESTAMP(): It returns the current date and time.
24. MAKEDATE(): It returns the date for a certain year and day-of-year value.
25. MAKETIME(): It returns the time for a certain hour, minute, second combination.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
As Per
2 Operating System Windows/ Linux/ MAC
Batch
3 Software Oracle Size
J. Source code:
A) Write SQL queries to use various date functions.
(a)Add 3 months in current date.
47 | Page
Database Management (DI03016041)
48 | Page
Database Management (DI03016041)
A) Input-Output:
49 | Page
Database Management (DI03016041)
B) Input-Output:
50 | Page
Database Management (DI03016041)
2) Which SQL function can be used to add or subtract a specified interval of time
from a given date?
a) DATEDIFF b) DATEADD
c) DATEPART d) DATETIME
3) Which Oracle numeric function can be used to calculate the absolute value of a
number?
A) ROUND B) CEIL
C) ABS D) MOD
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
51 | Page
Database Management (DI03016041)
Date: _________________
Practical No.5: In-built Function (Part 2)
a. Write SQL queries to use various character functions.
(1) Find out length of string “hello world”.
(2) Change the case of ‘HELLO WORLD’ string to lower case.
(3) Change the case of ‘hello world’ to upper case.
(4) Display each word initial letter as capital letter : government
polytechnic for girls.
(5) Find ‘put’ from string ‘computer’.
(6) Add 10 star on left side of India string.
(7) Add 10 star on right side of India string.
(8) Trim ‘ion’ from ‘information’.
(9) Trim ‘info’ from ‘information’.
A. Objective:
To gain the ability to manipulate and transform character data efficiently, perform data
formatting and validation, and enhance sorting and comparison operations for
character data within the database. These functions enable effective data
manipulation, formatting, and analysis, improving overall data management and
decision-making processes.
52 | Page
Database Management (DI03016041)
E. Practical Outcome(PRo)
Students will be able to understand and use various character and conversion function.
G. Prerequisite Theory:
Character Function :
ASCII() : Returns numeric value of left-most character
CHAR() : Returns the character for each integer passed
CHARINDEX() : Returns the position of a substring within the given string.
CONCAT_WS() : Returns concatenate with separator
CONCAT() : Returns concatenated string
53 | Page
Database Management (DI03016041)
Conversion function :
TO_CHAR :TO_CHAR function is used to typecast a numeric or date input to character
type with a format model
TO_NUMBER : Convert a character string to a number format using the TO_NUMBER
function :TO_NUMBER(char[, ’format_model’])
TO_DATE : Convert a character string to a date format using the TO_DATE function:
TO_DATE(char[, ’format_model’])
I. Source code:
A) Write SQL queries to use various character functions.
(1) Find out length of string “hello world”.
(2) Change the case of ‘HELLO WORLD’ string to lower case.
(3) Change the case of ‘hello world’ to upper case.
54 | Page
Database Management (DI03016041)
55 | Page
Database Management (DI03016041)
A) Input/Output:
56 | Page
Database Management (DI03016041)
B) Input/Output:
K. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
57 | Page
Database Management (DI03016041)
L. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
58 | Page
Database Management (DI03016041)
Date: _________________
Practical No.6: Group Functions and Operators
a. Write SQL queries to use various group function and operators
using tables created.
A. Objective:
Gain proficiency in utilizing various group functions and operators in Oracle for data
aggregation, analysis, and manipulation in SQL queries.
59 | Page
Database Management (DI03016041)
E. Practical Outcome(PRo)
Students will be able to understand group function and operators.
G. Prerequisite Theory:
Operators in Oracle:
Operators in Oracle are used to perform various operations on data, such as
arithmetic calculations, logical comparisons, and string manipulations. Here are some
commonly used operators in Oracle:
Arithmetic Operators:
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
60 | Page
Database Management (DI03016041)
Comparison Operators:
Equal to (=)
Not equal to (<> or !=)
Greater than (>)
Less than (<)
Greater than or equal to (>=)
Less than or equal to (<=)
Logical Operators:
AND: Returns true if all conditions are true.
OR: Returns true if any of the conditions are true.
NOT: Negates a condition, returns true if the condition is false.
Concatenation Operator:
The concatenation operator (||) is used to concatenate two or more strings.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
As Per
2 Operating System Windows/ Linux/ MAC
Batch
3 Software Oracle Size
61 | Page
Database Management (DI03016041)
J. Source code:
A) Write SQL queries to use various group function using tables created in Practical
3.
(a) Retrieve specified information for the account holder who are not in
‘Ahmedabad’.
(b) Retrieve specified information for the account holder who are not in
‘Ahmedabad ’or ‘Vadodara’.
(c) Retrieve those records of Account holder whose balance between is 50000
and 100000.
(d) Retrieve those records of Account holder whose balance not between is 50000
and 100000.
(e) Display only those records whose amount is 5000, 25000, 30000.
(f) Display only those records whose amount not in 5000, 25000, 30000.
(g) Find the total transaction amount of account holder from transaction table.
(h) Find minimum amount of transaction.
(i) Find maximum amount of transaction.
(j) Count the total account holders.
(k) Count only that recordthat’s made of payment is ‘cash’.
(l) Count only those records whose transaction made in the month of ‘MAY’
(m) Find the average value of transaction.
(n) Display total balance for each branch from account table.
(o) Display total balance for account in Ahmadabad city.
(p) Find total amount of mode of pay ‘cash’ from transaction table.
62 | Page
Database Management (DI03016041)
63 | Page
Database Management (DI03016041)
A) Input/Output:
3) Which group function is used to find the average value of a column in a table?
a) COUNT b) SUM
c) AVG d) MAX
64 | Page
Database Management (DI03016041)
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
4) Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
65 | Page
Database Management (DI03016041)
Date: _________________
Practical No.7: Set and Join Operators.
a. Write SQL query for set operators and join operations.
A. Objective:
The objective of learning set and join operators in SQL is to efficiently retrieve and
combine data from multiple tables, enabling complex data analysis and reporting.
E. Practical Outcome(PRo)
Students will be able to use set and join operators in database tables.
66 | Page
Database Management (DI03016041)
G. Prerequisite Theory:
Set Operators:
UNION:
The UNION operator combines the result sets of two or more SELECT statements,
eliminating duplicate rows. The syntax is as follows:
SELECT column1, column2, ... FROM table1 UNION SELECT column1, column2,
... FROM table2;
INTERSECT:
The INTERSECT operator returns the common rows between two result sets,
excluding duplicates. The syntax is:
EXCEPT/MINUS:
The EXCEPT or MINUS operator returns the rows present in the first SELECT
statement but not in the second SELECT statement. The syntax is:
Join Operators:
INNER JOIN:
The INNER JOIN operator retrieves rows from two or more tables that have matching
values in the specified columns. The syntax is:
67 | Page
Database Management (DI03016041)
LEFT JOIN:
The LEFT JOIN operator returns all rows from the left table and the matching rows
from the right table. If no match is found, NULL values are returned for the right table.
The syntax is:
RIGHT JOIN:
The RIGHT JOIN operator returns all rows from the right table and the matching rows
from the left table. If no match is found, NULL values are returned for the left table. The
syntax is:
FULL JOIN:
The FULL JOIN operator returns all rows from both tables, including the non-matching
rows. If no match is found, NULL values are returned for the unmatched table. The
syntax is:
These operators provide powerful ways to manipulate and combine data from
multiple tables in SQL queries.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
2 Operating System Windows/ Linux/ MAC As Per
Batch Size
3 Software Oracle
68 | Page
Database Management (DI03016041)
J. Source code:
A) Write SQL query for set operators and join operations.(Use tables of Practical 3)..
69 | Page
Database Management (DI03016041)
A) Input/Output:
1. Which set operator in SQL is used to combine the results of two SELECT
statements and remove duplicates?
a) UNION b) INTERSECT
c) EXCEPT/MINUS d) JOIN
70 | Page
Database Management (DI03016041)
2. Which join operator in SQL returns only the matching rows from both tables based
on a specified condition?
3. Which join operator in SQL returns all rows from the left table and the matching
rows from the right table, with NULL values for non-matching rows?
4. Which join operator in SQL returns all rows from both tables, including non-
matching rows with NULL values?
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
71 | Page
Database Management (DI03016041)
Date: _________________
Practical No.8: SQL Constraint
a. Apply the concept of integrity/data constraints while
creating/altering a table.
A. Objective:
72 | Page
Database Management (DI03016041)
2) you can develop skills in data consistency maintenance, enhancing your overall
database management abilities and ensuring accurate and reliable data storage.
CO4: Apply SQL Commands for creating, manipulating and controlling databases.
E. Practical Outcome(PRo)
Students will be able to use Integrity constraints on tables and also maintain data
constraint.
G. Prerequisite Theory:
Constraints in SQL:
1. Primary Key Constraint:
The primary key constraint ensures that each record in a table has a unique
identifier. It is defined when creating a table or altering an existing table. The syntax
is as follows:
2. Unique Constraint:
73 | Page
Database Management (DI03016041)
4. Check Constraint:
The check constraint allows you to specify a condition that must be satisfied
for the data in a column. It is defined when creating a table or using the ALTER
TABLE statement. The syntax is:
74 | Page
Database Management (DI03016041)
These syntax examples demonstrate how to apply integrity and data constraints in SQL
during table creation or alteration.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
2 Operating System Windows/ Linux/ MAC As Per
Batch Size
3 Software Oracle
NA
J. Source code:
(b) Create table Customer where cnum varchar2(4) P.K(first letter should start with
C), Cname varchar2(20) NOT NULL,city varchar2(20),Rating number(3) DEFAULT
10,Snum number(4) F.K (where snum refers salespeople table)
(c) Create table Order where Order_No number(4) P.K, Amount number(5), odate
varchar2(10), cnum varchar2(4) F.K,(where cnum refers customer table), snum
varchar2(4) F.K (where snum refers Salespeople table)
75 | Page
Database Management (DI03016041)
76 | Page
Database Management (DI03016041)
A) Input/Output:
1. Which constraint ensures that each record in a table has a unique identifier?
a) Primary Key Constraint b) Unique Constraint
c) Foreign Key Constraint d) Check Constraint
2. Which constraint ensures that values in a column or a group of columns are unique
across the table?
a) Primary Key Constraint b) Unique Constraint
c) Foreign Key Constraint d) Check Constraint
4. Which constraint allows you to specify a condition that must be satisfied for the data
in a column?
a) Primary Key Constraint b) Unique Constraint
c) Foreign Key Constraint d) Check Constraint
77 | Page
Database Management (DI03016041)
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. sAssessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
78 | Page
Database Management (DI03016041)
Date: _________________
Practical No.9: Privilege Commands
a. Write SQL queries for CREATE USER, GRANT, REVOKE AND DROP
USER command.
A. Objective:
“Write SQL queries for CREATE USER, GRANT, REVOKE AND DROP USER command”
This practical is expected to develop the following skills.
1. develop skills in user management, access control, security management, and user
administration.
2. enabling you to effectively manage user accounts, control permissions, maintain
security, and troubleshoot access-related issues in a database environment.
79 | Page
Database Management (DI03016041)
CO4: Apply SQL Commands for creating, manipulating and controlling databases.
E. Practical Outcome(PRo)
G. Prerequisite Theory:
GRANT Command:
The GRANT command is used to grant specific privileges or permissions to a
user. It allows users to perform operations on database objects.
The syntax is: GRANT privilege_type ON object_name TO username;
Example: GRANT SELECT, INSERT ON Employees TO johnsmith;
REVOKE Command:
The REVOKE command is used to revoke or remove specific privileges or
permissions from a user. It restricts the user's ability to perform certain operations
on database objects.
The syntax is: REVOKE privilege_type ON object_name FROM username;
Example: REVOKE INSERT ON Employees FROM johnsmith;
80 | Page
Database Management (DI03016041)
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
2 Operating System Windows/ Linux/ MAC As Per
Batch Size
3 Software Oracle
NA
J. Source code:
A) Write SQL queries for CREATE USER, GRANT, REVOKE AND DROP USER commands.
(a) Create a new user User1.
(b) Grant connect, resource and dba rights to user1.
(c) Grant all permissions of account table to user1.
(d) Remove select permission on account table for user1.
(e) Delete user1.
81 | Page
Database Management (DI03016041)
A) Input/Output:
82 | Page
Database Management (DI03016041)
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
83 | Page
Database Management (DI03016041)
Date: _________________
Practical No.10: PL/SQL Concepts
a. Write a program in PL/SQL to show the user of Cursor
b. Write a program in PL/SQL to show the user of Stored Procedures.
c. Write a program in PL/SQL to show the user of Stored Function.
d. Write a program in PL/SQL to show the user of Database Triggers
A. Objective:
Understand how to iterate over result sets and perform row-level operations in
database queries. Learn to create reusable code blocks for executing complex database
operations with parameters and error handling. Gain knowledge of creating and using
functions to encapsulate logic for data manipulation and retrieval within SQL
statements. Understand how to enforce data integrity, automate tasks, and perform
actions based on predefined events or conditions in the database.
84 | Page
Database Management (DI03016041)
CO4: Apply SQL Commands for creating, manipulating and controlling databases.
E. Practical Outcome(PRo)
Students will be able to create, store, fetch, delete cookies and session.
G. Prerequisite Theory:
Cursor:
A cursor in Oracle is a database object that provides a way to retrieve and
manipulate result sets in a systematic manner.
85 | Page
Database Management (DI03016041)
DECLARE
IS
select_statement;
BEGIN
-- Cursor operations
END;
Example:
DECLARE
emp_record emp_cursor%ROWTYPE;
BEGIN
OPEN emp_cursor;
LOOP
-- ...
END LOOP;
CLOSE emp_cursor;
END;
86 | Page
Database Management (DI03016041)
Stored Function:
A stored function in Oracle is a named PL/SQL block that can accept input
parameters, perform calculations, and return a single value.
Stored functions encapsulate reusable logic that can be called within SQL
statements or other PL/SQL blocks.
They are typically used to perform complex calculations, data manipulation, or
data retrieval tasks.
RETURN return_data_type
IS
[local_variable_declarations]
BEGIN
[RETURN expression;]
END;
Example:
IS
bonus NUMBER := 0;
BEGIN
-- ...
RETURN bonus;
END;
87 | Page
Database Management (DI03016041)
Stored Procedure:
A stored procedure in Oracle is a named PL/SQL block that can accept input
parameters and perform a series of actions.
Stored procedures encapsulate a set of SQL statements or business logic that
can be executed as a unit.
They are often used to perform database operations such as inserting, updating,
or deleting records.
Syntax for creating a stored procedure:
IS
[local_variable_declarations]
BEGIN
END;
Example:
IS
BEGIN
END;
88 | Page
Database Management (DI03016041)
Trigger:
A database trigger in Oracle is a named PL/SQL block that is automatically
executed in response to a specific event or action on a table.
Triggers are used to enforce business rules, maintain data integrity, and
automate actions within the database.
They can be triggered by events such as insertions, updates, or deletions on a
table.
Syntax for creating a database trigger:
ON table_name
DECLARE
-- Declaration of variables
BEGIN
END;
89 | Page
Database Management (DI03016041)
DECLARE
audit_message VARCHAR2(100);
BEGIN
END;
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
2 Operating System Windows/ Linux/ MAC As Per
Batch Size
3 Software Oracle
NA
90 | Page
Database Management (DI03016041)
J. Source code:
91 | Page
Database Management (DI03016041)
A) Input/Output:
92 | Page
Database Management (DI03016041)
B) Input/Output:
93 | Page
Database Management (DI03016041)
C) Input/Output:
94 | Page
Database Management (DI03016041)
95 | Page
Database Management (DI03016041)
D) Input/Output:
96 | Page
Database Management (DI03016041)
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
97 | Page
Database Management (DI03016041)
Date: _________________
Practical No.11: Refining database design through normalization
a. Normalization of database.
Consider the following relational schema:
a)Employee(eid, ename, salary, mngr id, mngrname, mngrage,ecity)
b)Student(no,name, bdate, city, semester, subname, submarks,
percentage)
A. Objective:
“Normalization of database.”
This practical is expected to develop the following skills.
1. Analyzing data dependencies and relationships.
2. Designing and creating normalized database schemas.
98 | Page
Database Management (DI03016041)
E. Practical Outcome(PRo)
G. Prerequisite Theory:
Functional Dependency:
Functional dependency describes the relationship between attributes in a table. A
functional dependency exists when the value of one or more attributes determines the
value of another attribute.
For example, consider a table called "Employees" with attributes: EmployeeID,
FirstName, LastName, and Department. Here, EmployeeID uniquely identifies each
employee, so we can say that EmployeeID functionally determines the FirstName,
LastName, and Department attributes.
Normal Forms:
a. First Normal Form (1NF): This form ensures that each attribute within a table
contains only atomic values. In other words, there are no repeating groups or arrays
within an attribute. To achieve 1NF, we break down the table into smaller, more
granular tables.
For example, let's say we have a table called "Students" with attributes: StudentID,
Name, and Courses (which stores multiple courses for each student). To convert it to
1NF, we split it into two tables:
Table 1: Students (StudentID, Name)
Table 2: Courses (StudentID, Course)
99 | Page
Database Management (DI03016041)
b. Second Normal Form (2NF): In addition to 1NF, 2NF ensures that each non-key
attribute is functionally dependent on the entire primary key. If an attribute is only
functionally dependent on part of the primary key, it should be moved to a separate
table.
For example, consider a table called "Orders" with attributes: OrderID, ProductID,
ProductName, and Quantity. Here, OrderID and ProductID together form the primary
key. Since ProductName is functionally dependent only on ProductID, we split the table
into two:
Table 1: Orders (OrderID, ProductID, Quantity)
Table 2: Products (ProductID, ProductName)
c. Third Normal Form (3NF): In addition to 2NF, 3NF ensures that there are no
transitive dependencies. Transitive dependencies occur when an attribute depends on
another attribute through a separate attribute. To achieve 3NF, we further split tables
to remove transitive dependencies.
For example, consider a table called "Employees" with attributes: EmployeeID,
DepartmentID, DepartmentName, and ManagerName. Here, DepartmentName is
transitively dependent on EmployeeID through DepartmentID. We split the table into
three:
Table 1: Employees (EmployeeID, DepartmentID)
Table 2: Departments (DepartmentID, DepartmentName)
Table 3: Managers (DepartmentID, ManagerName)
Primary Key:
A primary key uniquely identifies each record in a table. It ensures that there are no
duplicate entries and allows establishing relationships with other tables. Primary keys
can be single attributes or a combination of attributes.
For example, in the "Customers" table, the primary key could be "CustomerID," which
uniquely identifies each customer.
100 | Page
Database Management (DI03016041)
Denormalization:
While normalization aims to reduce redundancy, there are cases where
denormalization may be used to improve performance. Denormalization involves
selectively reintroducing redundancy by combining tables or duplicating data.
For example, let's consider a normalized database with separate tables for
"Customers" and "Orders." If frequent joins between these tables impact performance,
we may denormalize by adding the "CustomerName" attribute directly into the
"Orders" table. This denormalization eliminates the need for joins in some scenarios,
improving query performance.
It's important to note that denormalization should be used judiciously and carefully to
balance performance gains with the potential for data inconsistency.
101 | Page
Database Management (DI03016041)
Understanding the theory of normalization and applying it correctly enables the design
of efficient, maintainable, and reliable databases that minimize data redundancy,
ensure data integrity, and optimize performance.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
2 Operating System Windows/ Linux/ MAC As Per
Batch Size
3 Software Oracle
NA
J. Source code:
A) Normalization of database.
102 | Page
Database Management (DI03016041)
103 | Page
Database Management (DI03016041)
A) Input/Output:
2. Which normal form ensures that there are no repeating groups or arrays within an
attribute?
a) 1NF (First Normal Form)
b) 2NF (Second Normal Form)
c) 3NF (Third Normal Form)
d) BCNF (Boyce-Codd Normal Form)
104 | Page
Database Management (DI03016041)
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
105 | Page
Database Management (DI03016041)
Date: _________________
Practical No.12: Transaction Management
a. Prepare a report on transaction management concepts for
concurrent access of database by multiple users.
A. Objective:
E. Practical Outcome(PRo)
Students will be able to ensure data integrity, consistency, and reliability by effectively
managing and controlling database transactions.
106 | Page
Database Management (DI03016041)
G. Prerequisite Theory:
Transactions are a set of operations used to perform a logical set of work. It is the
bundle of all the instructions of a logical operation. A transaction usually means that
the data in the database has changed. One of the major uses of DBMS is to protect the
user’s data from system failures. It is done by ensuring that all the data is restored to a
consistent state when the computer is restarted after a crash. The transaction is any
one execution of the user program in a DBMS. One of the important properties of the
transaction is that it contains a finite number of steps. Executing the same program
multiple times will generate multiple transactions.
107 | Page
Database Management (DI03016041)
All instructions before committing come under a partially committed state and
are stored in RAM. When the commit is read the data is fully accepted and is stored on
Hard Disk.
108 | Page
Database Management (DI03016041)
A – Atomicity
C – Consistency
I – Isolation
D – Durability
Transaction States
Transactions can be implemented using SQL queries and Servers. In the below-
given diagram, you can see how transaction states work.
The transaction has the four properties. These are used to maintain consistency
in a database, before and after the transaction.
Property of Transaction:
1. Atomicity
2. Consistency
3. Isolation
4. Durability
109 | Page
Database Management (DI03016041)
Atomicity:
It states that all operations of the transaction take place at once if not, the
transactions aborted.
There is no midway, i.e., the transaction cannot occur partially. Each transaction
is treated as one unit and either run to completion or is not executed at all.
Atomicity involves the following two operations:
Abort: If a transaction aborts, then all the changes made are not visible.
Commit: If a transaction commits then all the changes made are visible.
Consistency:
The integrity constraints are maintained so that the database is consistent
before and after the transaction.
The execution of a transaction will leave a database in either its prior stable
state or anew stable state.
The consistent property of database states that every transaction sees a
consistent database instance.
The transaction is used to transform the database from one consistent state to
another consistent state.
Isolation:
It shows that the data which is used at the time of execution of a transaction
cannot be used by the second transaction until the first one is completed.
In isolation, if the transaction T1 is being executed and using the data item X,
then that data item can’t be accessed by any other transaction T2 until the
transaction T1ends.
The concurrency control subsystem of the DBMS enforced the isolation
property
Durability:
The durability property is used to indicate the performance of the database’s
consistent state. It states that the transaction made the permanent changes.
They cannot be lost by the erroneous operation of a faulty transaction or by the
system failure. When a transaction is completed, then the database reaches a
110 | Page
Database Management (DI03016041)
state known as the consistent state. That consistent state cannot be lost, even in
the event of a system’s failure.
The recovery subsystem of the DBMS has the responsibility of Durability
property.
H. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Computer (i3-i5 preferable), RAM
1 Hardware: Computer System
minimum 2 GB and onwards
2 Operating System Windows/ Linux/ MAC As Per
Batch Size
3 Software Oracle
NA
J. Source code:
111 | Page
Database Management (DI03016041)
112 | Page
Database Management (DI03016041)
A) Input/Output:
a) Consistency b) Complexity
c) Concurrency d) Conformity
2. What does the ACID acronym stand for in the context of transaction management?
3. Which concept in transaction management ensures that all changes made within a
transaction are saved permanently, even in the event of a system failure?
c) Durability d) Isolation
113 | Page
Database Management (DI03016041)
L. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
M. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
114 | Page