You are on page 1of 93

17YCS412-Database Management Systems Laboratory

Laboratory Manual

School of Computing
Name of the School:
Sciences and Engineering
Name of the Department: Computer Science and
Engineering
Name of the Programme: BTech CSE

Class: CSE

Database Management
Course/ Course Code:
System Lab 17YCS412

Academic Year: 2022-23

COVER PAGE
17YCS412-Database Management Systems Laboratory

Guidelines
Laboratory rules

1. Attendance is required for all lab classes. Students who do not attend lab will not
receive credit.

2. Ensure that you are aware of the test and its procedure before each lab class. You will
NOT be allowed to attend the class if you a renort unprepared!

3. Personal safety is top priority. Do not use equipment that is not assigned to you.

4. All accidents must be reported to your instructor or laboratory supervisor.

5. The surroundings near the equipment must be cleaned before leaving each lab class.

6. Ensure that readings are checked and marked by your TA for each lab period.

Laboratory report

1. Each student has to submit the report for each experiment.


2. Your report is to be written only in the space provided in the manual
3. Please write your number and, batch and group number.
4. Your report must be neat, well organized, and make a professional impact. Label all
axes and include proper units.
5. Your reports should be submitted within 7 days and before the beginning of the lab
class of the next batch.
6. Your reports will be as per rubrics provided at the end of each experiment
7. Anyone caught plagiarizing work in the laboratory report, from a current or past
student's notebook, will receive 0 on the grading scale.

INSIDE COVER PAGE


17YCS412-Database Management Systems Laboratory

NameofStudent ……………………………………

AcademicYear ……………………………………

Programme ……………………………………

Class/Div/RollNo. ……………………………………
PRNNo. ……………………………………
17YCS412-Database Management Systems Laboratory

CERTIFICTAE

This is to certify that


Mr./Miss……………………………..…………………………………
Roll no…………………... PRN No…………………………………

of class…...........................has satisfactorily/unsatisfactorily
completed the Term Work of Course ……………………………….
in this School during academic year ………………….

CourseTeacher HeadofDepartment DeanAcademics


17YCS412-Database Management Systems Laboratory

Table of Contents

Sr. Page
Title of Experiment Date Remark Sign
No. No
1. Study of Open Source Databases: MySQL/
MongoDB/CouchDB etc. 2

2. Design and Develop SQL DDL statements which


demonstrate the use of SQL objects 8

3. Design 10 SQL queries for suitable database application


using SQL DML statements: Insert, Select, Update, 14
Delete with operators
4. Design at least 10 SQL queries for suitable database
application using SQL DML statements: all types of 18
Join, Sub-Query and View
5. Write a PL/SQL block to calculate the student grades.
24

6. Write a PL/SQL block to implement types of cursors.


30

7. Write a PL/SQL stored procedure and function.


38

8. Write a database Trigger.


50

9. Implement aggregation and indexing with suitable


example using MongoDB 56

10. Implement Map reduces operation with suitable example


using MongoDB. 64

11. Design and Implement any 5 query using MongoDB


70
Experiment No: 1 Date: …………….

Title Study of Open Source Databases: MySQL/ MongoDB/CouchDB etc.

Aim This study experiment demonstrates use of open source databases.

Objective Demonstrate the use of open source databases such as MySQL/


MongoDB/CouchDB

Theory:
What is Database?
A database is a separate application that stores a collection of data.Each database has one or more
distinct APIs for creating, accessing, managing, searching and replicating the data it holds.
So nowadays, we use relational database management systems (RDBMS) to store and manage huge
Volume of data. This is called relational database because all the data is stored into different tables
and Relations are established using primary keys or other keys known as foreign keys.

What is DBMS?
A software system that enables users to define, create, maintain, and control access to the database.
The DBMS is the software that interacts with the users’ application programs and the database.
Typically, a DBMS provides the following facilities:
 It allows users to define the database, usually through a Data Definition Language (DDL).
The DDL allows users to specify the data types and structures and the constraints on the data
to be stored in the database.

 It allows users to insert, update, delete, and retrieve data from the database, usually through a
Data Manipulation Language(DML). The most common query language is the Structured
Query Language (SQL, pronounced ‘S-Q-L’, or sometimes ‘See-Quel’), which is now both
the formal and de facto standard language for relational DBMSs.

 It provides controlled access to the database. For example, it may provide:


– A security system, which prevents unauthorized users accessing the database;
– An integrity system, which maintains the consistency of stored data;
– A concurrency control system, which allows shared access of the database;
– A recovery control system, which restores the database to a previous consistent state
following a hardware or software failure

– A user-accessible catalog, which contains descriptions of the data in the database.


RDBMS Terminology:
Before we proceed to explain MySQL database system, let's revise few definitions related to database.
 Database: A database is a collection of tables, with related data.
 Table: A table is a matrix with data. A table in a database looks like a simple spread sheet.
YCA412/YCF412/YCI412-Database Management Systems Laboratory

 Column: One column(data element) contains data of one and the same kind, for example the
Column post code.
 Row: A row(=tuple, entry or record) is a group of related data, for example the data of one
subscription.
 Redundancy: Storing data twice, redundantly to make the system faster.
 Primary Key: A primary key is unique. A key value cannot occur twice in one table.
With a key, you can find at most one row.
 Foreign Key: A foreign key is the linking pin between two tables.
 Compound Key: A compound key(composite key) is a key that consists of multiple columns,
Because one column is not sufficiently unique.

MySQL Database:
MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses. MySQL is
developed, marketed, and supported by MySQL AB, which is a Swedish company. MySQL is
becoming so popular because of many good reasons:
• MySQL is released under an open-source license. So you have nothing to pay to use it.
• MySQL is a very powerful program in its own right. It handle salarge subset of the functionality of
the most expensive and powerful database packages.
• MySQL uses a standard form of the well-known SQL data language.
• MySQLworksonmanyoperatingsystemsandwithmanylanguagesincludingPHP, PERL, C,C++,
JAVA,etc.
• MySQL works very quickly and works well even with large datasets. MySQL is very friendly to
PHP, the most appreciated language for web development.
• MySQL supports large databases, upto50millionrowsormoreinatable. The default file size limit for
atableis4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of
8million terabytes(TB).
• MySQL is customizable. The open-source GPL license allows programmers to modify the MySQL
software to fit their own specific environments.

MongoDB Database:
MongoDB is a powerful, flexible, and scalable data store. It combines the ability to scale out with
many of the most useful features of relational databases, such as secondary indexes, range queries, and
sorting.

Features of MongoDB :
 built-in support for MapReduce-style aggregation
 geospatial indexes
o MongoDB is a document-oriented database, not a relational one.
o MongoDB is also schema-free
 Indexing: MongoDB supports generic secondary indexes, allowing a variety of fast queries,
and provides unique, compound, and geospatial indexing capabilities as well.
 Stored JavaScript: Instead of stored procedures, developers can store and use JavaScript
functions and values on the server side.
 Aggregation : MongoDB supports MapReduce and other aggregation tools.
 Fixed-size collections:Capped collections are fixed in size and are useful for certain types of
data, such as logs.
 File storage : MongoDB supports an easy-to-use protocol for storing large files and file
metadata.

3
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Procedure:
Basic commands of MYSQL
mysql> CREATE DATABASE MyDatabase;
Query OK, 1 row affected (0.06 sec) //To create own databse
mysql> Show Databases;
+ +
| Database |
+ +
| info |
| mydatabase |
| mysql |
| test |
+ +
3 rows in set (0.00 sec)

mysql> use MyDatabase;


Database changed
mysql> Show TABLES;
mysql> SELECT DATABASE( );// Determining the Current Database
+ +
| DATABASE( ) |
+ +
| MyDatabase |
+ +
1 row in set (0.00 sec)

mysql> Quit // to exit form MYSQL


mysql> Exit;

Basic commands of MongoDB


> db.createCollection("teachers_info") // To create own databse
{ "ok" : 1 }

>show dbs //show database names

>show collections //show collections in current database

>show users //show users in current database

>show profile //show recent system.profile entries w. time >= 1ms

>use < teachers_info >// set current database to <db name>

>db.help() //help on DB methods

4
YCA412/YCF412/YCI412-Database Management Systems Laboratory

>db. teachers_info.help() // help on collection methods

>db. teachers_info.find() //list objects in collection foo

>db.foo.find( { a : 1 } ) //list objects in foo where a == 1

5
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:
Hence we learned use of open source databases.

6
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 2 Date: …………….

Title Design and Develop SQL DDL statements which demonstrate the use of SQL
objects.

Aim To demonstrate the use of SQL objects such as Table, View, Index, Sequence,
Synonym.

Objective Demonstrate use of DML clauses such as create, alter, delete clauses

Theory:

About MySQL

MySQL is open source database management software that helps users store, organize, and
retrieve data. It is a very powerful program with a lot of flexibility.

How to Install MySQL on Ubuntu

If you don't have MySQL installed on your droplet, you can quickly download it.

How to Access the MySQL shell

Once you have MySQL installed on your droplet, you can access the MySQL shell by typing
the following command into terminal:

mysql -u root -p

After entering the root MySQL password into the prompt, you will be able to start building
your MySQL database.

Two points to keep in mind:

1. All MySQL commands end with a semicolon; if the phrase does not end with a semicolon, the
command will not execute.
2. Also, although it is not required, MySQL commands are usually written in uppercase and
databases, tables, usernames, or text are in lowercase to make them easier to distinguish.
However, the MySQL command line is not case sensitive.

How to Create and Delete a MySQL Database

MySQL organizes its information into databases; each one can hold tables with specific data.

You can quickly check what databases are available by typing:

7
YCA412/YCF412/YCI412-Database Management Systems Laboratory

SHOW DATABASES;

How to Access a MySQL Database

Once we have a new database, we can begin to fill it with information.

The first step is to create a new table within the larger database.

Let’s open up the database we want to use:

USE events;

In the same way that you could check the available databases, you can also see an overview
of the tables that the database contains.

SHOW tables;

Since this is a new database, MySQL has nothing to show, and you will get a message that
says, “Empty set”

How to Create a MySQL Table

Let’s imagine that we are planning a get together of friends. We can use MySQL to track the
details of the event.

This command accomplishes a number of things:

1. It has created a table called potluck within the directory, events.


2. We have set up 5 columns in the table—id, name, food, confirmed, and signup date.
3. The “id” column has a command (INT NOT NULL PRIMARY KEY AUTO_INCREMENT)
that automatically numbers each row.
4. The “name” column has been limited by the VARCHAR command to be under 20 characters
long.
5. The “food” column designates the food each person will bring. The VARCHAR limits text to
be under 30 characters.
6. The “confirmed” column records whether the person has RSVP’d with one letter, Y or N.
7. The “date” column will show when they signed up for the event. MySQL requires that dates
be written as yyyy-mm-dd

Keep in mind throughout that, although the MySQL command line does not pay attention to
cases, the table and database names are case sensitive: potluck is not the same as POTLUCK
or Potluck.

mysql>DESCRIBE potluck;

A view can be created from many kinds of SELECT statements. It can refer to base tables or other

8
YCA412/YCF412/YCI412-Database Management Systems Laboratory

views. It can use joins, UNION, and subqueries. The SELECT need not even refer to any tables.

Procedure:
sudo apt-get install mysql-server
mysql> SHOW DATABASES;
+ +
| Database |
+ +
| information_schema |
| mysql |
| performance_schema |
| test |
+ +
4 rows in set (0.01 sec)
CREATE DATABASE database name;

mysql> SHOW DATABASES;


+ +
| Database |
+ +
| information_schema |
| events |
| mysql |
| performance_schema |
| test |
+ +
5 rows in set (0.00 sec)

DROP DATABASE database name;

Let’s create a new MySQL table:

CREATE TABLE potluck (id INT NOT NULL PRIMARY KEY


AUTO_INCREMENT,
name VARCHAR(20),
food VARCHAR(30),
confirmed CHAR(1),
signup_date DATE);

Let’s take a look at how the table appears within the database using the "SHOW TABLES;"
command:

mysql> SHOW TABLES;


+ +
| Tables_in_events |

9
YCA412/YCF412/YCI412-Database Management Systems Laboratory

+ +
| potluck |
+ +
1 row in set (0.01 sec)

We can remind ourselves about the table’s organization with this command:

DESCRIBE potluck;

+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | YES | | NULL | |
| food | varchar(30) | YES | | NULL | |
| confirmed | char(1) | YES | | NULL | |
| signup_date | date | YES | | NULL | |
+ + + + + + +
5 rows in set (0.01 sec)

The following example defines a view that selects two columns from another table as well as an
expression calculated from those columns:

mysql> CREATE TABLE t (qty INT, price INT);

mysql> INSERT INTO t VALUES(3, 50);

mysql> CREATE VIEW v AS SELECT qty, price, qty*price AS value


FROM t;

mysql> SELECT * FROM v;

+ + + +

| qty | price | value |

+ + + +

| 3 | 50 | 150 |

+ + + +

10
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

11
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:
Hence we learned to design and execute DDL statements in mysql.

12
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 3 Date: …………….

Title Design 10 SQL queries for suitable database application using SQL DML
statements.

Aim To demonstrate use of DML queries.

Objective To learn use of Insert, Select, Update, Delete with operators


.
Theory:

Use this format to insert information into each row:

INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL,


"John", "Casserole","Y", '2012-04-11');

Once you input that in, you will see the words:

Query OK, 1 row affected (0.00 sec)

We can take a look at our table:

mysql> SELECT * FROM potluck;


+ + + + + +
| id | name | food | confirmed | signup_date |
+ + + + + +
| 1 | John | Casserole |Y | 2012-04-11 |
| 2 | Sandy | Key Lime Tarts | N | 2012-04-14 |
| 3 | Tom | BBQ |Y | 2012-04-18 |
| 4 | Tina | Salad |Y | 2012-04-10 |
+ + + + + +
4 rows in set (0.00 sec)

How to Update Information in the Table

Now that we have started our potluck list, we can address any possible changes. For example:
Sandy has confirmed that she is attending, so we are going to update that in the table.

UPDATE `potluck`
SET
`confirmed` = 'Y'
WHERE `potluck`.`name` ='Sandy';

You can also use this command to add information into specific cells, even if they are empty.

How to Add and Delete a Column

We are creating a handy chart, but it is missing some important information: our attendees’
emails.

We can easily add this:


13
YCA412/YCF412/YCI412-Database Management Systems Laboratory

ALTER TABLE potluck ADD email VARCHAR(40);

This command puts the new column called "email" at the end of the table by default, and the
VARCHAR command limits it to 40 characters.

However, if you need to place that column in a specific spot in the table, we can add one more
phrase to the command.

ALTER TABLE potluck ADD email VARCHAR(40) AFTER name;

Now the new “email” column goes after the column “name”.

Just as you can add a column, you can delete one as well:

ALTER TABLE potluck DROP email;

How to Delete a Row

If needed, you can also delete rows from the table with the following command:

DELETE from [table name] where [column name]=[field text];

For example, if Sandy suddenly realized that she will not be able to participate in the potluck
after all, we could quickly eliminate her details.

mysql> DELETE from potluck where name='Sandy';


Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM potluck;


+ + + + + +
| id | name | food | confirmed | signup_date |
+ + + + + +
| 1 | John | Casserole | Y | 2012-04-11 |
| 3 | Tom | BBQ |Y | 2012-04-18 |
| 4 | Tina | Salad | Y | 2012-04-10 |
+ + + + + +
3 rows in set (0.00 sec)

Notice that the id numbers associated with each person remain the same.

14
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

15
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:
Hence we learned to design and execute DML statements in mysql.

16
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 4 Date: …………….

Title Design at least 10 SQL queries for suitable database application using SQL
DML statements: all types of Join, Sub-Query and View

Aim To learn all types of Join, Sub-Query and View

Objective To implement concept of joins in SQL queries.

Theory:
MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN

In a database such as MySQL, data is divided into a series of tables which are then connected together
in SELECT commands to generate the output required. People often get confused between all the join
flavors. Let us consider an example to see how it works.

First, some sample data:

Mr Brown, Person number 1, has a phone number 01225 708225

Miss Smith, Person number 2, has a phone number 01225 899360

Mr Pullen, Person number 3, has a phone number 01380 724040

and also:

Person number 1 is selling property number 1 - Old House Farm

Person number 3 is selling property number 2 - The Willows

Person number 3 is (also) selling property number 3 - Tall Trees

Person number 3 is (also) selling property number 4 - The Melksham Florist

Person number 4 is selling property number 5 - Dun Roamin.

Create Tables which looks like:

mysql>select*fromdemo_people; +------------+--------------+------+

| name | phone | pid |

17
YCA412/YCF412/YCI412-Database Management Systems Laboratory

+ + + +

| Mr Brown | 01225 708225 | 1 |

| Miss Smith | 01225 899360 | 2 |

| Mr Pullen | 01380 724040 | 3 |

+ + + +

Table 1

mysql>select*fromdemo_property; +------+------+--------------------- +

| pid | spid | selling |

+ + + +

| 1 | 1 | Old House Farm |

| 3 | 2 | The Willows |

| 3 | 3 | Tall Trees |

| 3 | 4 | The Melksham Florist |

| 4 | 5 | Dun Roamin |

+ + + +

Table 2

If we do a regular JOIN (with none of the keywords INNER, OUTER, LEFT or RIGHT), then we get
all records that match in the appropriate way in the two tables, and records in both incoming tables
that do not match are not reported:

mysql> select name, phone, selling from demo_people join demo_property on

demo_people.pid = demo_property.pid;

If we do a LEFT JOIN, we get all records that match in the same way and IN ADDITION we get an
extra record for each unmatched record in the left table of the join - thus ensuring that every PERSON
gets a mention:

mysql> select name, phone, selling from demo_people left join demo_property

on demo_people.pid = demo_property.pid;

If we do a RIGHT JOIN, we get all the records that match and IN ADDITION we get an extra record
for each unmatched record in the right table of the join - in example, that means that each property
gets a mention even if we don't have seller details:
18
YCA412/YCF412/YCI412-Database Management Systems Laboratory

mysql> select name, phone, selling from demo_people right join demo_property

on demo_people.pid = demo_property.pid;

An INNER JOIN does a full join, just like the first example, and the word OUTER may be added

after the word LEFT or RIGHT in the last two examples - it's provided for ODBC compatibility

and doesn't add an extra capabilities.

MySQL SubQuery

A MySQL subquery is a query that is nested inside another query such as SELECT, INSERT,
UPDATE or DELETE. A MySQL subquery is also can be nested inside another subquery. A MySQL
subquery is also called an inner query, while the query that contains the subquery is called an outer
query.

For example, the following query returns the customer who has the maximum payment.

SELECT customerNumber, checkNumber, amount FROM Payments WHERE

amount= (SELECT MAX(amount) FROM payments)

MySQL View:

A database view is a virtual table or logical table which is defined as a SQL SELECT query with
joins. Because a database view is similar to a database table, which consists of rows and columns, so
you can query data against it.

19
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Mysql>create view X as

Where demo_people.pid=demo_people.pid;

Calling View:

SELECT * FROM X;

20
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

21
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:
Hence we learned to design and execute DML join statements in mysql.

22
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 5 Date: …………….

Title Write a PL/SQL block to calculate the grade of minimum 10 students

Aim To demonstrate the concept of PL/SQL block.

Objective To learn the PL/SQL basic programming.

Theory:
PL/SQL is a block structured language that enables developers to combine the power of SQL
with procedural statements.All the statements of a block are passed to oracle engine all at
once which increases processing speed and decreases the traffic.

Disadvantages of SQL:

SQL doesn’t provide the programmers with a technique of condition checking, looping and
branching.
SQL statements are passed to Oracle engine one at a time which increases traffic and
decreases speed.
SQL has no facility of error checking during manipulation of data.

Features of PL/SQL:

 PL/SQL is basically a procedural language, which provides the functionality of


decision making, iteration and many more features of procedural programming
languages.
 PL/SQL can execute a number of queries in one block using single command.
 One can create a PL/SQL unit such as procedures, functions, packages, triggers, and
types, which are stored in the database for reuse by applications.
 PL/SQL provides a feature to handle the exception which occurs in PL/SQL block
known as exception handling block.
 Applications written in PL/SQL are portable to computer hardware or operating
system where Oracle is operational.
 PL/SQL Offers extensive error checking.

Differences between SQL and PL/SQL:


SQL PL/SQL
PL/SQL is a block of codes that used to write
SQL is a single query that is used to perform
the entire program blocks/ procedure/ function,
DML and DDL operations.
etc.
It is declarative, that defines what needs to PL/SQL is procedural that defines how the
be done, rather than how things need to be things needs to be done.

23
YCA412/YCF412/YCI412-Database Management Systems Laboratory

done.
Execute as a single statement. Execute as a whole block.
Mainly used to manipulate data. Mainly used to create an application.
It is an extension of SQL, so it can contain SQL
Cannot contain PL/SQL code in it.
inside it.

Structure of PL/SQL Block:

PL/SQL extends SQL by adding constructs found in procedural languages, resulting in a


structural language that is more powerful than SQL. The basic unit in PL/SQL is a block. All
PL/SQL programs are made up of blocks, which can be nested within each other.

Typically, each block performs a logical action in the program. A block has the following
structure:

DECLARE
declaration statements;

BEGIN
executable statements

EXCEPTIONS
exception handling statements

END;

 Declare section starts with DECLARE keyword in which variables, constants, records
as cursors can be declared which stores data temporarily. It basically consists
definition of PL/SQL identifiers. This part of the code is optional.
 Execution section starts with BEGIN and ends with END keyword.This is a
mandatory section and here the program logic is written to perform any task like loops
and conditional statements. It supports all DML commands, DDL commands and
SQL*PLUS built-in functions as well.
 Exception section starts with EXCEPTION keyword.This section is optional which
contains statements that are executed when a run-time error occurs. Any exceptions
can be handled in this section.

Procedure:
Create a table student
Mysql>CREATE TABLE student
(stud_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

24
YCA412/YCF412/YCI412-Database Management Systems Laboratory

, m1 INT,m2 int,m3 int);


Mysql>show tables;

Insert records in the table


Mysql> insert into student (m1,m2,m3)values
(40,40,40),
(50,50,50),
(60,60,60);
Mysql>select * from student;

Change delimiter before writing procedure


Mysql>DELIMITER $$

Create a procedure in MySQL


Create procedure cal_grade()
Begin
DECLARE pid,pm1,pm2,pm3,pm INT;

/*declare a local variable for a subsequent handler*/

DECLARE fetched INT DEFAULT 0;


DECLARE student_cursor CURSOR FOR
Select *FROM student;

/* start tranction context.*/

START TRANSACTION;

/*set save point.*/

SAVEPOINT all_or_none;

/* open a student cursor.*/

OPEN student_cursor;
Cursor_stud:LOOP

/*Fetch a row at a time.*/

FETCH student_cursor
INTO pid,pm1,pm2,pm3;

/* PLACE THE CATCH HANDLER FOR NO MORE ROW FOUND


IMMEDIATELY AFTER THE FETCHOPERATION*/

IF fetched =1 THEN LEAVE cursor_stud;


END IF;
Set pm =(pm1+pm2+pm3)/3;
25
YCA412/YCF412/YCI412-Database Management Systems Laboratory

If pm>=70 then
Select concat(‘distinction’,pm)as “rows”;
End if;
If pm>=60 then
Select concat(‘First’,pm)as “rows”;
End if;
If pm>=50 then
Select concat(‘second’,pm)as “rows”;
End if;
If pm<50 then
Select concat(‘Fail’,pm)as “rows”;
End if;
END LOOP;
CLOSE student_cursor;
END;
$$

Reset the delimiter back to a semicolon to work again.


DELIMITER;
//call the procedure
SELECT ‘CALL debug_loop’ AS “ststement”;

Call the procedure.


CALL debug_loop();

26
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

27
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned to write and execute PL/SQL block to calculate the grade of minimum 10
students.

28
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 6 Date: …………….

Title Write a PL/SQL block to implement all types of cursors.

Aim To study use of cursors in PL/SQL block+

Objective To demonstrate Concept of Cursors

Theory:

Cursors:

A cursor is a temporary work area created in the system memory when a SQL statement is
executed. A cursor contains information on a select statement and the rows of data accessed
by it.

This temporary work area is used to store the data retrieved from the database, and
manipulate this data. A cursor can hold more than one row, but can process only one row at a
time. The set of rows the cursor holds is called the active set.

MySQL cursor contain 3-properties :

 Asensitive: Asensitive cursor focus on genuine data. These cursors work faster than
the insensitive cursor. Asensitive cursor doesn’t need any duplicate copy of data. Any
alteration done in the data through dead end should effect the data contain in
asensitive cursors.
 Read only: In read only data,there is only permission to read the data.And it doen’t
contain any permissions to updated the data or alter the data.
 One directional: MySQL cursor moves only in one direction. Data fetching can be
done in only one direction,and cannot fetch data in opposite direction.

Creating the cursor


Creating Cursor in MySQL is used to create a cursor with all the specifications.

 Declare a Cursor

The syntax to declare a cursor in MySQL is:

Declare <cursor_name>cursor for<select statement>

Where,

cursor_name - The name to assign to the cursor.

29
YCA412/YCF412/YCI412-Database Management Systems Laboratory

select_statement - The SELECT statement associated with the cursor.

 Open Statement

The syntax to open a cursor using the OPEN statement in MySQL is:

open <cursor_name>;

Where,

cursor_name - The name of the cursor that you wish to open.

 Fetch Statement

The syntax for the FETCH statement in MySQL is:

fetch<cursor_name>into<variable1>,<variable2>;

Where,

cursor_name - The name of the cursor that you wish to fetch rows.

variable_list - The list of variables, comma separated, that you wish to store the cursor result
set in.

 Close Statement

The syntax to close a cursor in MySQL is:

close<cursor_name>;

Where,

cursor_name - The name of the cursor that you wish to close. '

 Close Cursor

Close Cursor is used to close the Cursor upto some extent, when the open cursor is not
required. The keyword close in the cursor will discharge the present records to close and then
open the open cursor.

The following diagram illustrates how MySQL cursor works.

30
YCA412/YCF412/YCI412-Database Management Systems Laboratory

 Set Handler for Cursor's NOT FOUND Condition

When working with MySQL cursor, you must also declare a NOT FOUND handler to handle
the situation when the cursor could not find any row. Because each time you call the FETCH
statement, the cursor attempts to read the next row in the result set. When the cursor reaches
the end of the result set, it will not be able to get the data, and a condition is raised. The
handler is used to handle this condition.

The syntax to set up a handler for the NOT FOUND condition for a cursor in MySQL is:

DECLARE CONTINUE HANDLER FOR NOT FOUND [ set_condition ];

Where,

set_condition- The condition to set when the NOT FOUND condition is encountered by the cursor.

MySQL supports two types of cursors: Implicit Cursor and Explicit Cursor

1. Implicit cursors

When ever a client get a connection with the server by default Oracle server provides an
implicit work area to each client for it’s internal processing of MySQL statements. This work
area is dedicated to a specific client. This implicit work area is called as implicit cursor.

These are created by default when DML statements like, INSERT, UPDATE, and DELETE
statements are executed. They are also created when a SELECT statement that returns just
one row is executed.

A client can access the implicit cursor with the name MySQL. Cursors are used for rows
repetition returned by a query on a row-by-row process. SQL commands will function on all
the rows at one time in the program. Cursors can be created inside the triggers, functions and
stored procedures.

For Example: Consider the MySQL Block that uses implicit cursor attributes as shown
below:

2. Explicit cursors

They must be created when you are executing a SELECT statement that returns more than
one row. Even though the cursor stores multiple records, only one record can be processed at
a time, which is called as current row. When you fetch a row the current row position moves
to next row.

31
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Procedure:
Implicit cursor:
mysql> select * from CUSTOMERS;
+ + + + + +
| ID | NAME | AGE | ADDRESS | SALARY |
+ + + + + +
| 1 | Ramesh | 32 | Ahmedabad | 3500.00 |
| 2 | Khilan | 25 | Delhi | 3000.00 |
| 3 | kaushik | 23 | Kota | 3500.00 |
| 4 | Chaitali | 25 | Mumbai | 8000.00 |
| 5 | Hardik | 27 | Bhopal | 10000.00 |
| 6 | Komal | 22 | MP | 6000.00 |
+ + + + + +
6 rows in set (0.00 sec)

mysql> delimiter $$
mysql> CREATE PROCEDURE CUR3()
-> BEGIN
-> DECLARE total_rows INT;
-> UPDATE CUSTOMERS SET SALARY = SALARY + 500;
->
-> END;
-> $$
Query OK, 0 rows affected (0.01 sec)

mysql> call CUR3();


-> $$
Query OK, 6 rows affected (0.04 sec)

mysql> select * from CUSTOMERS;


-> $$
+ + + + + +
| ID | NAME | AGE | ADDRESS | SALARY |
+ + + + + +
| 1 | Ramesh | 32 | Ahmedabad | 4000.00 |
| 2 | Khilan | 25 | Delhi | 3500.00 |
| 3 | kaushik | 23 | Kota | 4000.00 |
| 4 | Chaitali | 25 | Mumbai | 8500.00 |
| 5 | Hardik | 27 | Bhopal | 10500.00 |
| 6 | Komal | 22 | MP | 6500.00 |
+ + + + + +
6 rows in set (0.00 sec)

Explicit Cursor
Both implicit and explicit cursors have the same functionality, but they differ in the way they
are accessed.
mysql> CREATE PROCEDURE build_email_list1 (INOUT email_list varchar(4000))
32
YCA412/YCF412/YCI412-Database Management Systems Laboratory

-> BEGIN
-> DECLARE v_finished INTEGER DEFAULT 0;
-> DECLARE v_email varchar(100) DEFAULT "";
-> DEClARE email_cursor CURSOR FOR
-> SELECT email_list FROM employees;
-> DECLARE CONTINUE HANDLER
-> FOR NOT FOUND SET v_finished = 1;
-> OPEN email_cursor;
-> get_email: LOOP
-> FETCH email_cursor INTO v_email;
-> IF v_finished = 1 THEN
-> LEAVE get_email;
-> END IF;
-> SET email_list = CONCAT(v_email,";",email_list);
-> END LOOP get_email;
-> CLOSE email_cursor;
-> END
-> $$
Query OK, 0 rows affected (0.01 sec)

mysql> SET @email_list="xyz@abc.com";


-> $$
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @email_list;


-> $$
+ +
| @email_list |
+ +
| xyz@abc.com|
+ +
1 row in set (0.00 sec)

mysql> CALL build_email_list1(@email_list);SELECT


@email_list;$$Query OK, 0 rows affected (0.00 sec)

+
+
| @email_list |
+
+

33
YCA412/YCF412/YCI412-Database Management Systems Laboratory

| xyz@abc.com ;xyz@abc.com;xyz@abc.com;sxyz@abc.com;xyz@abc.com;xyz@abc.com|
+
+
1 row in set (0.00 sec)

mysql> SET @email_list="xyz@abc.com";


-> $$
Query OK, 0 rows affected (0.00 sec)

34
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

35
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned to write a PL/SQL block to create all types of Cursors.

36
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 7 Date: …………….

Title Write a PL/SQL stored procedure and function.

Aim To learn use of PL/SQL stored procedure and function

Objective To demonstrate use of stored procedure and function in PL/SQL.


.

Theory:

A stored procedure or in simple a proc is a named PL/SQL block which performs one or
more specific task. This is similar to a procedure in other programming languages.

A procedure has a header and a body. The header consists of the name of the procedure and
the parameters or variables passed to the procedure. The body consists or declaration section,
execution section and exception section similar to a general PL/SQL Block.

A stored procedure is a segment of declarative SQL statements stored inside the database
catalog. A stored procedure can be invoked by triggers, other stored procedures, and
applications such as Java, Python, PHP, etc.

MySQL stored procedures advantages

 Typically stored procedures help increase the performance of the applications. Once
created, stored procedures are compiled and stored in the database. However, MySQL
implements the stored procedures slightly different. MySQL stored procedures are
compiled on demand. After compiling a stored procedure, MySQL puts it into a cache.
37
YCA412/YCF412/YCI412-Database Management Systems Laboratory

And MySQL maintains its own stored procedure cache for every single connection. If
an application uses a stored procedure multiple times in a single connection, the
compiled version is used, otherwise, the stored procedure works like a query.

 Stored procedures help reduce the traffic between application and database server
because instead of sending multiple lengthy SQL statements, the application has to
send only name and parameters of the stored procedure.
 Stored procedures are reusable and transparent to any applications. Stored procedures
expose the database interface to all applications so that developers don’t have to
develop functions that are already supported in stored procedures.
 Stored procedures are secure. The database administrator can grant appropriate
permissions to applications that access stored procedures in the database without
giving any permissions on the underlying database tables.

General Syntax to create a procedure is:

CREATE [OR REPLACE] PROCEDURE proc_name [list of parameters]

IS

Declaration section

BEGIN

Execution section

EXCEPTION

Exception section

END;

IS - marks the beginning of the body of the procedure and is similar to DECLARE in
anonymous PL/SQL Blocks. The code between IS and BEGIN forms the Declaration section.

The syntax within the brackets [ ] indicate they are optional. By using CREATE OR
REPLACE together the procedure is created if no other procedure with the same name exists
or the existing procedure is replaced with the current code.

3. How to execute a Stored Procedure?

There are two ways to execute a procedure.

1) From the SQL prompt.

EXECUTE [or EXEC] procedure_name;


38
YCA412/YCF412/YCI412-Database Management Systems Laboratory

2) Within another procedure – simply use the procedure name.

procedure_name;

4. Procedures: Passing Parameters

In PL/SQL, we can pass parameters to procedures and functions in three ways.

1) IN type parameter: These types of parameters are used to send values to stored
procedures.
2) OUT type parameter: These types of parameters are used to get values from stored
procedures. This is similar to a return type in functions.
3) IN OUT parameter: These types of parameters are used to send values and get values
from stored procedures.

NOTE: If a parameter is not explicitly defined a parameter type, then by default it is an IN


type parameter.

1) IN parameter:

It is the default mode. When you define an IN parameter in a stored procedure, the calling program has to
pass an argument to the stored procedure. In addition, the value of an IN parameter is protected. It means
that even the value of the IN parameter is changed inside the stored procedure, its original value is retained
after the stored procedure ends. In other words, the stored procedure only works on the copy of the IN
parameter.

General syntax to pass a IN parameter is


CREATE [OR REPLACE] PROCEDURE procedure_name

(param_name1 IN datatype, param_name12 IN datatype ... )

 param_name1, • param_name2... are unique parameter names.


 datatype - defines the datatype of the variable.
 IN - is optional, by default it is a IN type parameter.

Table used for given example is:

mysql> select * from CUSTOMERS;

+ + + + + +

| ID | NAME | AGE | ADDRESS | SALARY |

+ + + + + +

| 1 | Ramesh | 32 | Ahmedabad | 4000.00 |

39
YCA412/YCF412/YCI412-Database Management Systems Laboratory

| 2 | Khilan | 25 | Delhi | 3500.00 |

| 3 | kaushik | 23 | Kota | 4000.00 |

| 4 | Chaitali | 25 | Mumbai | 8500.00 |

| 5 | Hardik | 27 | Bhopal | 10500.00 |

| 6 | Komal | 22 | MP | 6500.00 |

+ + + + + +

6 rows in set (0.04 sec)

IN parameter Example:

mysql> delimiter $$

mysql> create procedure GetAddress(IN custaddress varchar(100))

-> begin

-> select * from CUSTOMERS

-> where ADDRESS=custaddress;

-> end;

-> $$

Query OK, 0 rows affected (0.07 sec)

mysql> call GetAddress('Mumbai');

-> $$

+ + + + + +

| ID | NAME | AGE | ADDRESS | SALARY |

+ + + + + +

| 4 | Chaitali | 25 | Mumbai | 8500.00 |

+ + + + + +

1 row in set (0.02 sec)

40
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Query OK, 0 rows affected (0.02 sec)

2) OUT Parameter:

the value of an OUT parameter can be changed inside the stored procedure and its new value is
passed back to the calling program. Notice that the stored procedure cannot access the initial
value of the OUT parameter when it starts.

The General syntax to create an OUT parameter is

CREATE [OR REPLACE] PROCEDURE proc2 (param_name OUT datatype)

The parameter should be explicity declared as OUT parameter.

Table used for given example is:

mysql> select * from CUSTOMERS;

+ + + + + +

| ID | NAME | AGE | ADDRESS | SALARY |

+ + + + + +

| 1 | Ramesh | 32 | Ahmedabad | 4000.00 |

| 2 | Khilan | 25 | Delhi | 3500.00 |

| 3 | kaushik | 23 | Kota | 4000.00 |

| 4 | Chaitali | 25 | Mumbai | 8500.00 |

| 5 | Hardik | 27 | Bhopal | 10500.00 |

| 6 | Komal | 22 | MP | 6500.00 |

| 101 | vivek | 28 | nashik | 1000.00 |

| 102 | vivek | 28 | nashik | 1000.00 |

+ + + + + +

8 rows in set (0.00 sec)

OUT parameter Example:

mysql> DELIMITER $$

41
YCA412/YCF412/YCI412-Database Management Systems Laboratory

mysql> CREATE PROCEDURE c(IN custadd char(25),

-> OUT total INT)

-> BEGIN

-> SELECT count(ID)

-> INTO total

-> FROM CUSTOMERS

-> WHERE address=custadd;

-> END$$

Query OK, 0 rows affected (0.00 sec)

mysql> CALL c('nashik',@total); SELECT

@total;$$Query OK, 1 row affected (0.00 sec)

+ +

| @total |

+ +

|2|

+ +

1 row in set (0.00 sec)

3) IN OUT Parameter:

The IN OUT parameter allows us to pass values into a procedure and get output values from
the procedure. This parameter is used if the value of the IN parameter can be changed in the
calling program.

By using IN OUT parameter we can pass values into a parameter and return a value to the
calling program using the same parameter. But this is possible only if the value passed to the

42
YCA412/YCF412/YCI412-Database Management Systems Laboratory

procedure and output value have a same datatype. This parameter is used if the value of the
parameter will be changed in the procedure.

The General syntax to create an IN OUT parameter is

CREATE [OR REPLACE] PROCEDURE proc3 (param_name IN OUT datatype)

mysql> DELIMITER $$

mysql> CREATE PROCEDURE set_counter(INOUT count INT(4),IN inc INT(4))

-> BEGIN

-> SET count = count + inc;

-> END$$

Query OK, 0 rows affected (0.00 sec)

mysql> SET @counter=1;

-> $$

Query OK, 0 rows affected (0.00 sec)

mysql> select @counter;

-> $$

+ +

| @counter |

+ +

|1|

+ +

1 row in set (0.00 sec)

mysql> call set_counter(@counter,1);

-> $$

Query OK, 0 rows affected (0.00 sec)

43
YCA412/YCF412/YCI412-Database Management Systems Laboratory

mysql> select @counter;

-> $$

+ +

| @counter |

+ +

|2|

+ +

1 row in set (0.00 sec)

Stored Function
A stored function is a special kind stored program that returns a single value. You use stored
functions to encapsulate common formulas or business rules that are reusable among SQL
statements or stored programs.

Different from a stored procedure, you can use a stored function in SQL statements wherever
an expression is used. This helps improve the readability and maintainability of the
procedural code.

The following illustrates the simplest syntax for creating a new stored function:

General Syntax to create stored function is

CREATE FUNCTION function_name(param1,param2,…)

RETURNS datatype

[NOT] DETERMINISTIC

statements

First, you specify the name of the stored function after CREATE FUNCTION clause.

44
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Second, you list all parameters of the stored function inside the parentheses. By default, all
parameters are IN parameters. You cannot specify IN , OUT or INOUT modifiers to the
parameters.

Third, you must specify the data type of the return value in the RETURNS statement. It can be
any valid MySQL data types.

Fourth, for the same input parameters, if the stored function returns the same result, it is
considered deterministic and otherwise the stored function is not deterministic. You have to
decide whether a stored function is deterministic or not. If you declare it incorrectly, the
stored function may produce an unexpected result, or the available optimization is not used
which degrades the performance.

Fifth, you write the code in the body of the stored function. It can be a single statement or a
compound statement. Inside the body section, you have to specify at least one RETURN
statement. The RETURN statement returns a value to the caller. Whenever the RETURN
statement is reached, the stored function’s execution is terminated immediately.

The following example is a function that returns the level of a customer based on credit limit.
We use the IF statement to decide the credit limit.

Refer above Table for given example:

mysql> CREATE FUNCTION CustomerLevel(cust_salary decimal) RETURNS


VARCHAR(10)

-> DETERMINISTIC

-> BEGIN

-> DECLARE lvl varchar(10);

-> IF cust_salary > 10000 THEN

-> SET lvl = 'PLATINUM';

-> ELSEIF (cust_salary <= 10000 AND cust_salary >= 5000) THEN

-> SET lvl = 'GOLD';

-> ELSEIF cust_salary < 5000 THEN

45
YCA412/YCF412/YCI412-Database Management Systems Laboratory

-> SET lvl = 'SILVER';

-> END IF;

->

-> RETURN (lvl);

-> END $$

Query OK, 0 rows affected (0.00 sec)

mysql> SELECT NAME,CustomerLevel(SALARY) FROM CUSTOMERS ORDER BY


NAME;$$

+ + +

| NAME | CustomerLevel(SALARY) |

+ + +

| Chaitali | GOLD |

| Hardik | PLATINUM |

| kaushik | SILVER |

| Khilan | SILVER |

| Komal | GOLD |

| Ramesh | SILVER |

| vivek | SILVER |

| vivek | SILVER |

+ + +

8 rows in set (0.00 sec)

46
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Result

47
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned to write a PL/SQL block to create Stored Procedure and Cursor.

48
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No:8 Date: …………….

Title Write a database Trigger

Aim To learn concept of trigger.

Objective To implement trigger.

Theory:

SQL Trigger
A SQL trigger is a set of SQL statements stored in the database catalog. A SQL trigger is
executed or fired whenever an event associated with a table occurs e.g., insert, update or
delete.

A SQL trigger is a special type of stored procedure. It is special because it is not called
directly like a stored procedure. The main difference between a trigger and a stored procedure
is that a trigger is called automatically when a data modification event is made against a table
whereas a stored procedure must be called explicitly.

In MySQL, a trigger is a set of SQL statements that is invoked automatically when a change
is made to the data on the associated table. A trigger can be defined to be invoked either
before or after the data is changed by INSERT, UPDATE or DELETE statement. Before
MySQL version 5.7.2, you can to define maximum six triggers for each table.

 BEFORE INSERT – activated before data is inserted into the table.

 AFTER INSERT – activated after data is inserted into the table.

 BEFORE UPDATE – activated before data in the table is updated.

 AFTER UPDATE – activated after data in the table is updated.

 BEFORE DELETE – activated before data is removed from the table.

 AFTER DELETE – activated after data is removed from the table

Advantages of using SQL triggers

 SQL triggers provide an alternative way to check the integrity of data.


 SQL triggers can catch errors in business logic in the database layer.
 SQL triggers provide an alternative way to run scheduled tasks. By using SQL
triggers, you don’t have to wait to run the scheduled tasks because the triggers are
invoked automatically before or after a change is made to the data in the tables.
 SQL triggers are very useful to audit the changes of data in tables.

49
YCA412/YCF412/YCI412-Database Management Systems Laboratory

MySQL trigger limitations

MySQL triggers cover all features defined in the standard SQL. However, there are some
limitations that you should know before using them in your applications.

MySQL triggers cannot:

 Use SHOW, LOAD DATA, LOAD TABLE, BACKUP DATABASE, RESTORE, FLUSH and
RETURN statements.
 Use statements that commit or rollback implicitly or explicitly such as COMMIT ,
ROLLBACK , START TRANSACTION , LOCK/UNLOCK TABLES , ALTER ,
CREATE , DROP , RENAME , etc.
 Use prepared statements such as PREPARE, EXECUTE, etc.
 Use dynamic SQL statements.

MySQL Trigger syntax

In order to create a new trigger, you use the CREATE TRIGGER statement. The following
illustrates the syntax of the CREATE TRIGGER statement:

CREATE TRIGGER trigger_name trigger_time trigger_event

ON table_name

FOR EACH ROW

BEGIN

...

END;

Let’s examine the syntax above in more detail.

 You put the trigger name after the CREATE TRIGGER statement. The trigger name
should follow the naming convention [trigger time]_[table name]_[trigger event], for
example before_employees_update.
 Trigger activation time can be BEFORE or AFTER. You must specify the activation time
when you define a trigger. You use the BEFORE keyword if you want to process action
prior to the change is made on the table and AFTER if you need to process action after
the change is made.
 The trigger event can be INSERT, UPDATE or DELETE. This event causes the trigger to
be invoked. A trigger only can be invoked by one event. To define a trigger that is
invoked by multiple events, you have to define multiple triggers, one for each event.
 A trigger must be associated with a specific table. Without a table trigger would not
exist therefore you have to specify the table name after the ON keyword.

50
YCA412/YCF412/YCI412-Database Management Systems Laboratory

 You place the SQL statements between BEGIN and END block. This is where you
define the logic for the trigger.

There are two categories of triggers:

1) Row Level Triggers: Row level trigger executes each time when an row is affected. If
zero rows affected then no row level trigger will execute. Suppose if you want to delete one
employye from emp table whose department is HR and you want as soon as employee deleted
from emp table the count in dept table from HR section should be reduce by 1 then row level
trigger will execute.

2) Statement Level Triggers: This kind of trigger fires when a SQL statement affects the
rows of the table. The trigger activates and performs its activity irrespective of number of
rows affected due to SQL statement.

Procedure:

To perform below trigger query you have refer previous table employees. Table is as follows:

mysql> select * from employees;

+ + + +

| id | employee_no | lastname |

+ + + +

| 101 | 1 | patil |

| 102 | 2 | chavan |

| 103 | 4 | Pawar |

+ + + +

3 rows in set (0.00 sec)

Create trigger for above table:

mysql> CREATE TRIGGER before_employee_update BEFORE UPDATE ON employees


FOR EACH ROW BEGIN INSERT INTO employees_audit SET action = 'update',
employee_no = OLD.employee_no, lastname = OLD.lastname, changedat = NOW(); END;$$

Query OK, 0 rows affected (0.10 sec)

Show Trigger

mysql> mysql> show triggers;

51
YCA412/YCF412/YCI412-Database Management Systems Laboratory

-> $$

+ + + +
+
-+ + + + + +
+

| Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer |


character_set_client | collation_connection | Database Collation |

+ + + +
+
-+ + + + + +
+

| before_employee_update | UPDATE | employees | BEGIN INSERT INTO employees_audit


SET action = 'update', employee_no = OLD.employee_no, lastname = OLD.lastname,
changedat = NOW(); END | BEFORE | NULL | NO_ENGINE_SUBSTITUTION |
root@localhost | utf8 | utf8_general_ci | latin1_swedish_ci |

+ + + +
+
-+ + + + + +
+

1 row in set (0.01 sec)

Update employee table

mysql> UPDATE employees SET lastname = 'Khan' WHERE employee_no = 4;


$$Query OK, 0 rows affected (0.03 sec)
Rows matched: 1 Changed: 0 Warnings: 0

Check trigger is invoked

mysql> select * from employees_audit;

-> $$
+ + + + + +

| id | employee_no | lastname | changedat | action |

+ + + + + +

| 1 | 4 | Khan | 2016-08-05 00:17:46 | update |

+ + + + + +

2 rows in set (0.00 sec)

52
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

53
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned to write a database Trigger.

54
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 9 Date: …………….

Title Implement aggregation and indexing with suitable example using MongoDB

Aim To Learn the basic concepts of MongoDB.

Objective To demonstrate use of aggregation and indexing in MongoDB.

Theory:

AGGREGATION

Aggregations operations process data records and return computed results. Aggregation
operations group values from multiple documents together, and can perform a variety of
operations on the grouped data to return a single result. In sql count(*) and with group by is
an equivalent of mongodb aggregation.

For the aggregation in mongodb you should use aggregate() method.

There is a list available aggregation expressions is as follows:

Expression Description Example


$sum Sums up the defined value from all db.mycol.aggregate([{$group : {_id
documents in the collection. : "$by_user", num_tutorial : {$sum :
"$likes"}}}])
$avg Calculates the average of all given db.mycol.aggregate([{$group : {_id
values from all documents in the : "$by_user", num_tutorial : {$avg :
collection. "$likes"}}}])
$min Gets the minimum of the db.mycol.aggregate([{$group : {_id
corresponding values from all : "$by_user", num_tutorial : {$min :
documents in the collection. "$likes"}}}])
$max Gets the maximum of the db.mycol.aggregate([{$group : {_id
corresponding values from all : "$by_user", num_tutorial : {$max :
documents in the collection. "$likes"}}}])
$push Inserts the value to an array in the db.mycol.aggregate([{$group : {_id
resulting document. : "$by_user", url : {$push:
"$url"}}}])
$addToSet Inserts the value to an array in the db.mycol.aggregate([{$group : {_id
resulting document but does not : "$by_user", url : {$addToSet :
create duplicates. "$url"}}}])

55
YCA412/YCF412/YCI412-Database Management Systems Laboratory

$first Gets the first document from the db.mycol.aggregate([{$group : {_id


source documents according to the : "$by_user", first_url : {$first :
grouping. Typically this makes only "$url"}}}])
sense together with some previously
applied “$sort”-stage.
$last Gets the last document from the db.mycol.aggregate([{$group : {_id
source documents according to the : "$by_user", last_url : {$last :
grouping. Typically this makes only "$url"}}}])
sense together with some previously
applied “$sort”-stage.

INDEXING

Indexes support the efficient resolution of queries. Without indexes, MongoDB must scan
every document of a collection to select those documents that match the query statement. This
scan is highly inefficient and require the mongodb to process a large volume of data.

Indexes are special data structures, that store a small portion of the data set in an easy to
traverse form. The index stores the value of a specific field or set of fields, ordered by the
value of the field as specified in index.

Procedure:

Aggregation Syntax:

Basic syntax of aggregate() method is as follows

>db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)

> db.createCollection("staffit")

> db.staffit.find();

{ "_id" : ObjectId("57a8609010c7bf432e93d52d"), "id" : 1311, "name" : "tushar", "subject" :


"Computer Network" }

{ "_id" : ObjectId("57a860c410c7bf432e93d52e"), "id" : 1083, "name" : "bhushan", "subject"


: "database management system" }

{ "_id" : ObjectId("57a8612a10c7bf432e93d52f"), "id" : 1127, "name" : "vivek", "subject" :


"Web Engineering Technology" }

56
YCA412/YCF412/YCI412-Database Management Systems Laboratory

{ "_id" : ObjectId("57a8615710c7bf432e93d531"), "id" : 1187, "name" : "pravin", "subject" :


"Computer Network" }

{ "_id" : ObjectId("57a8617810c7bf432e93d532"), "id" : 1413, "name" : "prajakta", "subject"


: "database management system" }

{ "_id" : ObjectId("57a861aa10c7bf432e93d533"), "id" : 1224, "name" : "swati", "subject" :


"Cloud Computing" }

> db.staffit.aggregate([{$group : {_id : "$subject", num_subject : {$sum : 1}}}]);

OUTPUT:

{ "result" : [ { "_id" : "Cloud Computing", "num_subject" : 1 },

{ "_id" : "Web Engineering Technology", "num_subject" : 1 },

{ "_id" : "database management system", "num_subject" : 2 },

{ "_id" : "Computer Network", "num_subject" : 2 } ],

"ok" : 1 }

EXAMPLE WITH LIST OF OTHER AGGREGATION VARIABLES:

In the collection you have the following data:

{
_id: ObjectId(7df78ad8902c)
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by_user: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
},
{
_id: ObjectId(7df78ad8902d)
title: 'NoSQL Overview',
description: 'No sql database is very fast',
by_user: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 10
},
{
_id: ObjectId(7df78ad8902e)
title: 'Neo4j Overview',
description: 'Neo4j is no sql database',
by_user: 'Neo4j',
57
YCA412/YCF412/YCI412-Database Management Systems Laboratory

url: 'http://www.neo4j.com',
tags: ['neo4j', 'database', 'NoSQL'],
likes: 750
},

INDEXING

1. Creation of Index

Syntax for creation:

db.collection.createIndex(keys, options)

Parameter Type Description

keys document : For each field to index, a key-value pair with the field and the index order:
1 for ascending or -1 for descending.

options document: Optional. One or more key-value pairs that specify index options. For a
list of options,

The ensureIndex() Method

To create an index you need to use ensureIndex() method of mongodb.

1. Syntax:

Basic syntax of ensureIndex() method is as follows()

>db.COLLECTION_NAME.ensureIndex({KEY:1})

Here key is the name of field on which you want to create index and 1 is for ascending order.
To create index in descending order you need to use -1.

2. Example

> db.staffit.ensureIndex({id:1})

OUTPUT:

> db.staffit.find().sort({id:1})

58
YCA412/YCF412/YCI412-Database Management Systems Laboratory

{ "_id" : ObjectId("57a860c410c7bf432e93d52e"), "id" : 1083, "name" : "bhushan", "subject"


: "database management system" }

{ "_id" : ObjectId("57a8612a10c7bf432e93d52f"), "id" : 1127, "name" : "vivek", "subject" :


"Web Engineering Technology" }

{ "_id" : ObjectId("57a8615710c7bf432e93d531"), "id" : 1187, "name" : "pravin", "subject" :


"Computer Network" }

{ "_id" : ObjectId("57a861aa10c7bf432e93d533"), "id" : 1224, "name" : "swati", "subject" :


"Cloud Computing" }

{ "_id" : ObjectId("57a8609010c7bf432e93d52d"), "id" : 1311, "name" : "tushar", "subject" :


"Computer Network" }

{ "_id" : ObjectId("57a8617810c7bf432e93d532"), "id" : 1413, "name" : "prajakta", "subject"


: "database management system" }

Unique Indexes

Unique indexes guarantee that, for a given key, every document in the collection will have a
unique value.

> db.staffit.createIndex( { "name":- 1 }, { unique: true } )

> db.staffit.find().sort( { name:- 1 } )

{ "_id" : ObjectId("57a8612a10c7bf432e93d52f"), "id" : 1127, "name" : "vivek", "subject" :


"Web Engineering Technology" }

{ "_id" : ObjectId("57a8609010c7bf432e93d52d"), "id" : 1311, "name" : "tushar", "subject" :


"Computer Network" }

{ "_id" : ObjectId("57a861aa10c7bf432e93d533"), "id" : 1224, "name" : "swati", "subject" :


"Cloud Computing" }

{ "_id" : ObjectId("57a8615710c7bf432e93d531"), "id" : 1187, "name" : "pravin", "subject" :


"Computer Network" }

{ "_id" : ObjectId("57a8617810c7bf432e93d532"), "id" : 1413, "name" : "prajakta", "subject"


: "database management system" }
59
YCA412/YCF412/YCI412-Database Management Systems Laboratory

{ "_id" : ObjectId("57a860c410c7bf432e93d52e"), "id" : 1083, "name" : "bhushan", "subject"


: "database management system" }

2. Deletion of Index

Syntax for Deletion:

db.collection.dropIndex(index)

Drops or removes the specified index from a collection. The db.collection.dropIndex()method


provides a wrapper around the dropIndexes command.

60
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

61
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned aggregation and indexing using MongoDB.

62
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No: 10 Date: …………….

Title Implement Map reduce operation with suitable example using MongoDB.

Aim To learn mapreduce in MongoDB.

Objective To demonstrate mapreduce in MongoDB

Theory:

MapReduce

Map-reduce is a data processing paradigm for condensing large volumes of data into useful
aggregated results. MongoDB uses mapReduce command for map-reduce operations.
MapReduce is generally used for processing large data sets. Everything described with count,
distinct, and group can be done with MapReduce, and more. It is a method of aggregation that
can be easily parallelized across multiple servers. It splits up a problem, sends chunks of it to
different machines, and lets each machine solve its part of the problem. When all of the
machines are finished, they merge all of the pieces of the solution back into a full solution.
The map function is a JavaScript function that associates or “maps” a value with a key and
emits the key and value pair during a map-reduce operation.

Steps of MapReduce :

First is map step: which maps an operation onto every document in a collection. That
operation could be either “do nothing” or “emit these keys with Xvalues.”

Second step called the shuffle step: keys are grouped and lists of emitted values are created
for each key.

Third is the reduce takes this list of values and reducesit to a single element. This element is
returned to the shuffle step until each key has a list containing a single value: the result.

In map Reduce we have to write 3 functions.

1. Map Function (Ex.Person to each city to count population)

2. Reduce Function (Ex. Reducing the total population count to single value)

3. Map Reduce Function ( it will create a new collection it contains the total population)

Following is the syntax of the basic mapReduce command −

>db.collection.mapReduce(
function() {emit(key,value);}, //map function
63
YCA412/YCF412/YCI412-Database Management Systems Laboratory

function(key,values) {return reduceFunction}, { //reduce functionout:


collection,
query: document,
sort: document,
limit: number
}
)

The map-reduce function first queries the collection, then maps the result documents to emit
key-value pairs which is then reduced based on the keys that have multiple values.

In the above syntax

 map is a javascript function that maps a value with a key and emits a key-valur pair
 reduce is a javscript function that reduces or groups all the documents having the
same key
 out specifies the location of the map-reduce query result
 query specifies the optional selection criteria for selecting documents
 sort specifies the optional sort criteria
 limit specifies the optional maximum number of documents to be returned

Procedure:

Consider the following document structure storing student status. The document stores name
of the student, satus and remark.

> db.studentstatus.find()

{ "_id" : ObjectId("57a9397f08fd36bd71144a06"), "name" : "sahil", "status" : "Pass",


"Remark" : "First Class with distinction" }

{ "_id" : ObjectId("57a939d608fd36bd71144a07"), "name" : "soham", "status" : "fail",


"Remark" : "Allow To keep Term" }

{ "_id" : ObjectId("57a939f408fd36bd71144a08"), "name" : "rohan", "status" : "Pass",


"Remark" : "First Class" }

{ "_id" : ObjectId("57a93a1708fd36bd71144a09"), "name" : "vrudhi", "status" : "Pass",


"Remark" : "Higher second class Class" }

64
YCA412/YCF412/YCI412-Database Management Systems Laboratory

{ "_id" : ObjectId("57a93a3608fd36bd71144a0a"), "name" : "raj", "status" : "Fail", "Remark"


: "Year Drop" }

Now, we will use a mapReduce function on our studentstatus collection to select all the pass
students, group them on the basis of name and status and count the number of pass student
using the following code −

> db.studentstatus.mapReduce(

... function() { emit(this.user_id,1); },

... function(key, values) {return Array.sum(values)}, {

... query:{status:"Pass"},

... out:"Pass_List_total"

... }

... )

The above mapReduce query outputs the following result −

{ "result" : "Pass_List_total",

"timeMillis" : 57,

"counts" : {

"input" : 3,

"emit" : 3,

"reduce" : 1,

"output" : 1

},

"ok" : 1,

The result shows that a total of 3 documents matched the query (status:"Pass"), the map
function emitted 3 documents with key-value pairs and finally the reduce function grouped
mapped documents having the same keys into 1.
65
YCA412/YCF412/YCI412-Database Management Systems Laboratory

To see the result of this mapReduce query use the find operator −

> db.studentstatus.mapReduce(

... function() { emit(this.name,this.status); },

... function(key, values) {return Array.sum(values)}, {

... query:{status:"Pass"},

... out:"Pass_List_total"

... }

...

... ).find()

The above query gives the following result which indicates that students rohan, sahil and
vrudhi have three stuatus in Pass state −

{ "_id" : "rohan", "value" : "Pass" }

{ "_id" : "sahil", "value" : "Pass" }

{ "_id" : "vrudhi", "value" : "Pass" }

66
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

67
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned to Implement Map reduce operation using MongoDB.

68
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Experiment No:11 Date: …………….

Title Design and Implement any 5 query using MongoDB

Aim To Study MongoDB Queries.

Objective To learn use of basic MongoDB queries..

Theory:

MongoDB

MongoDB is a cross-platform, document oriented database that provides, high performance,


high availability, and easy scalability. MongoDB works on concept of collection and
document.

Database

Database is a physical container for collections. Each database gets its own set of files on the
file system. A single MongoDB server typically has multiple databases.

Collection

Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A


collection exists within a single database. Collections do not enforce a schema. Documents
within a collection can have different fields. Typically, all documents in a collection are of
similar or related purpose.

Doccument

A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema
means that documents in the same collection do not need to have the same set of fields or
structure, and common fields in a collection's documents may hold different types of data.

1) The USE Command:

MongoDB use DATABASE_NAME is used to create database. The command will create a
new database, if it doesn't exist otherwise it will return the existing database.

Syntax:

Basic syntax of use DATABASE statement is as follows:

>use DATABASE_NAME

1. Example:

69
YCA412/YCF412/YCI412-Database Management Systems Laboratory

If you want to create a database with name <mydb>, then use DATABASE statement would
be as follows:

>use student

switched to db student

To check your currently selected database use the command db

>db
mydb

If you want to check your databases list, then use the command show dbs.

>show dbs
local 0.78125GB
test 0.23012GB

2) The dropDatabase() Method:

MongoDB db.dropDatabase() command is used to drop a existing database.

2. Syntax:

Basic syntax of dropDatabase() command is as follows:

>db.dropDatabase()

This will delete the selected database. If you have not selected any database, then it will
delete default 'test' database

3. Example:

First, check the list available databases by using the command show dbs

> show dbs

admin (empty)

dbs 0.0625GB

local 0.03125GB

prajakta 0.0625GB

test 0.0625GB

70
YCA412/YCF412/YCI412-Database Management Systems Laboratory

If you want to delete new database <mydb>, then dropDatabase() command would be as
follows:

> use test

switched to db test

> db.dropDatabase()

{ "dropped" : "test", "ok" : 1 }

Now check list of databases,

> show dbs

admin (empty)

dbs 0.0625GB

local 0.03125GB

prajakta 0.0625GB

3) The createCollection() Method:

MongoDB db.createCollection(name, options) is used to create collection.

Syntax:

Basic syntax of createCollection() command is as follows :

>db.createCollection(name, options)

In the command, name is name of collection to be created. Options is a document and used
to specify configuration of collection

Parameter Type Description

Name String Name of the collection to be created

Options Document (Optional) Specify options about memory size and


indexing

71
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Options parameter is optional, so you need to specify only name of the collection. Following
is the list of options you can use:

Field Type Description

capped Boolean (Optional) If true, enables a capped collection. Capped


collection is a collection fixed size collecction that
automatically overwrites its oldest entries when it
reaches its maximum size. If you specify true, you
need to specify size parameter also.

autoIndexID Boolean (Optional) If true, automatically create index on _id


field.s Default value is false.

size number (Optional) Specifies a maximum size in bytes for a


capped collection. If If capped is true, then you need
to specify this field also.

max number (Optional) Specifies the maximum number of


documents allowed in the capped collection.

While inserting the document, MongoDB first checks size field of capped collection, then it
checks max field.

Examples:

Basic syntax of createCollection() method without options is as follows:

> use prajakta

switched to db prajakta

> db.createCollection("stud_info")

{ "ok" : 1 }

> show collections

72
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Pass_List_total

mycol

mycollection

stud_info

studentstatus

system.indexes

4) The dropCollection() Method:

MongoDB's db.collection.drop() is used to drop a collection from the database.

Syntax:

Basic syntax of drop() command is as follows :

>db.COLLECTION_NAME.drop()

drop the collection with the name stud_info

> db.stud_info.drop()
true

drop() method will return true, if the selected collection is dropped successfully otherwise it
will return false

5) The insert() Method:

To insert data into MongoDB collection, you need to use MongoDB's insert() or
save()method.

7. Syntax:

Basic syntax of insert() command is as follows −

>db.COLLECTION_NAME.insert(document)

Example

> db.createCollection("stud_info")

73
YCA412/YCF412/YCI412-Database Management Systems Laboratory

{ "ok" : 1 }

OUTPUT:

> db.stud_info.insert({stud_id:101,name:'shravani',year:'FE'})

> db.stud_info.insert({stud_id:102,name:'yash',year:'SE'})

> db.stud_info.insert({stud_id:103,name:'rohit',year:'BE'})

> db.stud_info.insert({stud_id:104,name:'yamini',year:'TE'})

> db.stud_info.insert({stud_id:105,name:'swati',year:'TE'})

> db.stud_info.insert({stud_id:106,name:'amit',year:'BE'})

Here stud_info is our collection name. If the collection doesn't exist in the database, then
MongoDB will create this collection and then insert document into it. In the inserted
document if we don't specify the _id parameter, then MongoDB assigns an unique ObjectId
for this document.

find()

To query data from MongoDB collection, you need to use MongoDB's find() method.

8. Syntax

Basic syntax of find() method is as follows:

>db.COLLECTION_NAME.find()

find() method will display all the documents in a non structured way.

The pretty() Method

To display the results in a formatted way, you can use pretty() method.

9. Syntax
>db.mycol.find().pretty()

Example:

a. Simple Find

> db.stud_info.find().pretty()

74
YCA412/YCF412/YCI412-Database Management Systems Laboratory

OUTPUT:

"_id" : ObjectId("57a96edf7f0d28785b0bfce1"),

"stud_id" : 101,

"name" : "shravani",

"year" : "FE"

"_id" : ObjectId("57a96ef37f0d28785b0bfce2"),

"stud_id" : 102,

"name" : "yash",

"year" : "SE"

"_id" : ObjectId("57a96f057f0d28785b0bfce3"),

"stud_id" : 103,

"name" : "rohit",

"year" : "BE"

"_id" : ObjectId("57a96f147f0d28785b0bfce4"),

"stud_id" : 104,

"name" : "yamini",

"year" : "TE"

75
YCA412/YCF412/YCI412-Database Management Systems Laboratory

"_id" : ObjectId("57a96f247f0d28785b0bfce5"),

"stud_id" : 105,

"name" : "swati",

"year" : "TE"

"_id" : ObjectId("57a96f327f0d28785b0bfce6"),

"stud_id" : 106,

"name" : "amit",

"year" : "BE"

Apart from find() method there is findOne() method, that returns only one document.

b. Find with condition

> db.stud_info.find({name:"rohit"}).pretty()

"_id" : ObjectId("57a96f057f0d28785b0bfce3"),

"stud_id" : 103,

"name" : "rohit",

"year" : "BE"

c. Find with not equal to

76
YCA412/YCF412/YCI412-Database Management Systems Laboratory

> db.stud_info.find({year:{$ne:"TE"}}).pretty()

OUTPUT:

"_id" : ObjectId("57a96edf7f0d28785b0bfce1"),

"stud_id" : 101,

"name" : "shravani",

"year" : "FE"

"_id" : ObjectId("57a96ef37f0d28785b0bfce2"),

"stud_id" : 102,

"name" : "yash",

"year" : "SE"

"_id" : ObjectId("57a96f057f0d28785b0bfce3"),

"stud_id" : 103,

"name" : "rohit",

"year" : "BE"

"_id" : ObjectId("57a96f327f0d28785b0bfce6"),

"stud_id" : 106,

"name" : "amit",

77
YCA412/YCF412/YCI412-Database Management Systems Laboratory

"year" : "BE"

d. Find with Count

> db.stud_info.find().count()

6) The Update() Method:

MongoDB's update() and save() methods are used to update document into a collection. The
update() method update values in the existing document while the save() method replaces the
existing document with the document passed in save() method.

The update() method updates values in the existing document.

Syntax

Basic syntax of update() method is as follows

>db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)

Example:

> db.stud_info.update({name:'amit'},{$set:{name:'rajesh'}})

> db.stud_info.find().pretty()

OUTPUT:

"_id" : ObjectId("57a96edf7f0d28785b0bfce1"),

"stud_id" : 101,

"name" : "shravani",

"year" : "FE"

78
YCA412/YCF412/YCI412-Database Management Systems Laboratory

"_id" : ObjectId("57a96ef37f0d28785b0bfce2"),

"stud_id" : 102,

"name" : "yash",

"year" : "SE"

"_id" : ObjectId("57a96f057f0d28785b0bfce3"),

"stud_id" : 103,

"name" : "rohit",

"year" : "BE"

"_id" : ObjectId("57a96f147f0d28785b0bfce4"),

"stud_id" : 104,

"name" : "yamini",

"year" : "TE"

"_id" : ObjectId("57a96f247f0d28785b0bfce5"),

"stud_id" : 105,

"name" : "swati",

"year" : "TE"

79
YCA412/YCF412/YCI412-Database Management Systems Laboratory

"_id" : ObjectId("57a96f327f0d28785b0bfce6"),

"name" : "rajesh",

"stud_id" : 106,

"year" : "BE"

7) The remove() Method

MongoDB's remove() method is used to remove document from the collection. remove()
method accepts two parameters. One is deletion criteria and second is justOne flag

1. deletion criteria : (Optional) deletion criteria according to documents will be


removed.

2. justOne : (Optional) if set to true or 1, then remove only one document.

Syntax: Basic syntax of remove() method is as follows

>db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)

Example:

> db.stud_info.remove({'year':'BE'})

OUTPUT:

> db.stud_info.find().pretty()

"_id" : ObjectId("57a96edf7f0d28785b0bfce1"),

"stud_id" : 101,

"name" : "shravani",

"year" : "FE"

80
YCA412/YCF412/YCI412-Database Management Systems Laboratory

"_id" : ObjectId("57a96ef37f0d28785b0bfce2"),

"stud_id" : 102,

"name" : "yash",

"year" : "SE"

"_id" : ObjectId("57a96f147f0d28785b0bfce4"),

"stud_id" : 104,

"name" : "yamini",

"year" : "TE"

"_id" : ObjectId("57a96f247f0d28785b0bfce5"),

"stud_id" : 105,

"name" : "swati",

"year" : "TE"

Remove All documents

If you don't specify deletion criteria, then mongodb will delete whole documents from the
collection. This is equivalent of SQL's truncate command.

>db.stud_info.remove()
>db.stud_info.find()

81
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Results:

82
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Conclusion:

Hence we learned to write queries for MongoDB.

Please Note:
83
YCA412/YCF412/YCI412-Database Management Systems Laboratory

Right Hand Side Page Left Hand Side Page


Aim Experimental Set up
Title Observation table
Objective Sample Calculation
Theory Graphs
Apparatus
Procedure
Results
Conclusions
Questions
Answers
Assessment

Assessment

Understanding Quiz Timely Total Signature


(05 marks) (03 marks) Submission (10 Marks) With Date
(02 Marks)

Right Side Page

84
Department of Computer Science and Engineering

DEPARTMENT VISION

To build global leaders in computer science and engineering profession with research and
innovation skills to meet the needs of the industry and society.

DEPARTMENT MISSION

DM1: To provide academic environment which instill practical knowledge and use of modern
tools in computer science.

DM2: To promote the research by facilitating the cutting edge technologies and innovative
methods.

DM3: To develop centre of excellence for computer science and engineering to fulfill needs of
industry and society.

PROGRAMME EDUCATIONAL OBJECTIVES

PEO1: Graduates will attain the expertise of analyzing and specifying the requirements for any
computing system as well as capable of modeling, designing, implementing and verifying a
computing system to meet specified requirements using contemporary tools

PEO2: Graduates will possess diversified professional skills for successful career.

PEO3: Graduates of the programme will have the competencies for communicating, planning,
coordinating, organizing, decision making and leading a team

PEO4: Graduates of the programme will have knowledge of professional, interpersonal and
ethical responsibility and will contribute to society through active research.

GRADUATE ATTRIBUTES

1. Knowledge base for Engineering: Demonstrate competence in mathematics, natural


sciences, engineering fundamentals and specialized engineering knowledge appropriate to
the programme.

2. Analytical Skills: Identify, formulate, analyze and solve diverse engineering problems.
YCA412/YCF412/YCI412-Database Management Systems Laboratory

3. Design: Solution for complicated open–ended engineering problems and design the
components with appropriate standards to meet specified needs with proper attention to
public health, safety, environment and society.

4. Experimental Investigation: Technical skills to conduct investigation, interpretation of


observed data and provide solution for multifaceted problems.
5. Modern Engineering tools usage: Acquire, select, manipulate relevant techniques,
resources and advanced engineering ICT tools to operate simple to complex engineering
activities.
6. Impact of engineering on society: Provide a product / project for use by the public
towards their health, welfare, safety and legal issues to serve the society effectively.
7. Environment and Sustainability: Design eco-friendly and sustainable products in
demonstrating the technology development to meet present and future needs.
8. High Ethical Standards: Practice ethical codes and standards endorsed by professional
engineers.
9. Leadership and team work: Perform as an individual and as a leader in diverse teams
and in multi-disciplinary scenarios.
10. Communication Skills: Professional communication with the society to comprehend and
formulate reports, documentation, effective delivery of presentation and responsible to
clear instructions.
11. Project management and Finance: Appropriate in incorporating finance and business
practices including project, risk and change management in the practice of engineering by
understanding their limitations.
12. Life-long learners: Update the technical needs in a challenging world in equipping
themselves to maintain their competence.

87
YCA412/YCF412/YCI412-Database Management Systems Laboratory

PROGRAMME OUTCOMES

Programme Outcome

PO1 An ability to apply knowledge of computing and mathematics appropriate to the


discipline.

PO2 An ability to analyze a problem, interpret data, and define the computing system
requirements which would be appropriate to the solution.

PO3 An ability to design, implement, and evaluate a computer-based system, process,


component, or program to meet desired needs.

PO4 An ability to apply creativity in the design of systems which would help to
investigate the complex problem and provide software solution.

PO5 An ability to use the computing techniques, skills, and modern system tools
necessary for practice as a CSE professional

PO6 An ability to analyze the local and global impact of computing on individuals,
organizations, and society

PO7 An ability to develop and use the software systems within realistic constraints
environmental, health and safety, manufacturability, and sustainability considerations

PO8 An ability in an understanding of professional, ethical, legal, security and social issues
and responsibilities

PO9 An ability to function effectively on teams and individually to accomplish a common


goal

PO10 An ability to communicate effectively with a range of audiences by written and oral

ability to plan, organize and follow best practices and standards so that the project is
PO11 Completed as successfully by meeting performance, quality at CMM level, budget and
time

PO12 An ability to engage in Lifelong learning and continuing professional development

88
YCA412/YCF412/YCI412-Database Management Systems Laboratory

PROGRAMME SPECIFIC OUTCOMES

PSO1: Ability to employ latest computer languages, environments and platforms for
solving problems in the areas of emerging communication technologies.

PSO2 ability to use knowledge in data analytics and mining for industrial problems

Inside Back Page

89
Back Page

You might also like