Dbmslabmanual
Dbmslabmanual
Computer Engineering
Class: T.E. Computer Engineering
Subject: Database Management System Lab (310247)
2015 Pattern
Semester I
Savitribai Phule Pune University, one of the premier universities in India, is positioned in the
North-western part of Pune city. It occupies an area of about 411 acres. It was established on
10th February, 1949 under the Poona University Act. The university houses 46 academic
departments. It is popularly known as the 'Oxford of the East'. It has about 307 recognized
research institutes and 612 affiliated colleges offering graduate and under-graduate courses. The
university attracts many foreign students due to its excellent facilities. It offers good
accommodation facility. There is a provision of hostel for the students. There is a well-stocked
library containing plenty of books regarding various subjects. The university offers different
scholarships to the students. The university conducts seminars and conferences for the students.
About College
Bharati Vidyapeeth’s College of Engineering for Women was established in June 2000, with the
collective efforts of experts having long and outstanding academic experience in the field of
professional education with the mission 'Social transformation through dynamic education.'
Vision:
Women Empowerment through Technical Education.
Mission:
Develop women students to rise to their full potential.
Impart knowledge and prepare competent engineers.
About Course
A database-management system (DBMS) is a computer-software application that interacts
with end-users, other applications, and the database itself to capture and analyze data. A general-
purpose DBMS allows the definition, creation, querying, update, and administration of
databases. A database is generally stored in a DBMS-specific format which is not portable, but
different DBMSs can share data by using standards such as SQL and ODBC or JDBC.
Computer scientists may classify database-management systems according to the database
models that they support. Relational databasesbecame dominant in the 1980s. These model data
as rows and columns in a series of tables, and the vast majority use SQL for writing and querying
data. In the 2000s, non-relational databases became popular, referred to as NoSQL because they
use different query languages.
Course Objectives
EXPERIMENT 1
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : After completion of Assignment students are able to install Mysql database
THEORY:
What is MySQL?
MySQL, the most popular Open Source SQL database management system, is developed,
distributed, and supported by Oracle Corporation.
The MySQL Web site (http://www.mysql.com/) provides the latest information about MySQL
software.
• MySQL is a database management system.
A database is a structured collection of data. It may be anything from a simple shopping list to a
picture gallery or the vast amounts of information in a corporate network. To add, access, and
process data stored in a computer database, you need a database management system such as
MySQL Server. Since computers are very good at handling large amounts of data, database
management systems play a central role in computing, as standalone utilities, or as parts of other
applications.
• MySQL databases are relational.
A relational database stores data in separate tables rather than putting all the data in one big
storeroom. The database structures are organized into physical files optimized for speed. The
logical model, with objects such as databases, tables, views, rows, and columns, offers a flexible
programming environment. You set up rules governing the relationships between different data
fields, such as one-to-one, one-to-many, unique, required or optional, and “pointers” between
different tables. The database enforces these rules, so that with a well-designed database, your
application never sees inconsistent, duplicate, orphan, out-of-date, or missing data.
The SQL part of “MySQL” stands for “Structured Query Language”. SQL is the most common
standardized language used to access databases. Depending on your programming environment,
you might enter SQL directly (for example, to generate reports), embed SQL statements into
code written in another language, or use a language-specific API that hides the SQL syntax.
SQL is defined by the ANSI/ISO SQL Standard. The SQL standard has been evolving since
1986 and several versions exist. In this manual, “SQL-92” refers to the standard released in
1992, “SQL:1999” refers to the standard released in 1999, and “SQL:2003”refers to the current
version of the standard. We use the phrase “the SQL standard” to mean the current version of the
SQL Standard at any time.
• MySQL software is Open Source.
Open Source means that it is possible for anyone to use and modify the software. Anybody can
download the MySQL software from the Internet and use it without paying anything. If you
wish, you may study the source code and change it to suit your needs. The MySQL software uses
the GPL (GNU General Public License), http://www.fsf.org/licenses/, to define what you may
and may not do with the software in different situations. If you feel uncomfortable with the GPL
or need to embed MySQL code into a commercial application, you can buy a commercially
licensed version from us. See the MySQL Licensing Overview for more information
(http://www.mysql.com/company/legal/licensing/).
• The MySQL Database Server is very fast, reliable, scalable, and easy to use.
If that is what you are looking for, you should give it a try. MySQL Server can run comfortably
on a desktop or laptop, alongside your other applications, web servers, and so on, requiring little
or no attention. If you dedicate an entire machine to MySQL, you can adjust the settings to take
advantage of all the memory, CPU power, and I/O capacity available. MySQL can also scale up
to clusters of machines, networked together.
MySQL Server was originally developed to handle large databases much faster than existing
solutions and has been successfully used in highly demanding production environments for
several years. Although under constant development, MySQL Server today offers a rich and
useful set of functions. Its connectivity, speed, and security make MySQL Server highly suited
for accessing databases on the Internet.
• MySQL Server works in client/server or embedded systems.
The MySQL Database Software is a client/server system that consists of a multi-threaded SQL
server that supports different back ends, several different client programs and libraries,
administrative tools, and a wide range of application programming interfaces (APIs).
We also provide MySQL Server as an embedded multi-threaded library that you can link into
your application to get a smaller, faster, easier-to-manage standalone product.
• A large amount of contributed MySQL software is available.
MySQL Server has a practical set of features developed in close cooperation with our users. It is
very likely that your favorite application or language supports the MySQL Database Server.
Security
• A privilege and password system that is very flexible and secure, and that enables host-
based verification.
• Password security by encryption of all password traffic when you connect to a server.
Scalability and Limits
• Support for large databases. We use MySQL Server with databases that contain 50
million records. We also know of users who use MySQL Server with 200,000 tables and about
5,000,000,000 rows.
• Support for up to 64 indexes per table. Each index may consist of 1 to 16 columns or
parts of columns. The maximum index width for InnoDB tables is either 767 bytes or 3072 bytes.
See Section 14.8.1.7, “Limits on InnoDB Tables”. The maximum index width for MyISAM
tables is 1000 bytes. See Section 15.2, “The MyISAM Storage Engine”. An index may use a
prefix of a column for CHAR,VARCHAR, BLOB, or TEXT column types.
Connectivity
• Clients can connect to MySQL Server using several protocols:
• Clients can connect using TCP/IP sockets on any platform.
• On Windows systems, clients can connect using named pipes if the server is started with the -
-enable-named-pipe option. Windows servers also support shared-memory connections if
started with the --shared-memory option. Clients can connect through shared memory by
using the --protocol=memory option.
• On Unix systems, clients can connect using Unix domain socket files.
• MySQL client programs can be written in many languages. A client library written in C is
available for clients written in C or C++, or for any language that provides C bindings.
• APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and Tcl are available, enabling
MySQL clients to be written in many languages. See Chapter 27, Connectors and APIs.
• The Connector/ODBC (MyODBC) interface provides MySQL support for client programs that
use ODBC (Open Database Connectivity) connections. For example, you can use MS Access to
connect to your MySQL server. Clients can be run on Windows or Unix. Connector/ODBC
source is available. All ODBC 2.5 functions are supported, as are many others. See MySQL
Connector/ODBC Developer Guide.
• The Connector/J interface provides MySQL support for Java client programs that use JDBC
connections. Clients can be run on Windows or Unix. Connector/J source is available. See
MySQL Connector/J 5.1 Developer Guide.
• MySQL Connector/Net enables developers to easily create .NET applications that require
secure, high-performance data connectivity with MySQL. It implements the required ADO.NET
interfaces and integrates into ADO.NET aware tools. Developers can build applications using
their choice of .NET languages. MySQL Connector/Net is a fully managed ADO.NET driver
written in 100% pure C#. See MySQL Connector/Net Developer Guide.
Localization
• The server can provide error messages to clients in many languages. See Section 10.2,
“Setting the Error Message Language”.
• Full support for several different character sets, including latin1 (cp1252), german, big5,
ujis, several Unicode character sets, and more. For example, the Scandinavian characters “å”, “ä”
and “ö” are permitted in table and column names.
• All data is saved in the chosen character set.
• Sorting and comparisons are done according to the default character set and collation. is
possible to change this when the MySQL server is started (see Section 10.1.3.2, “Server
Character Set and Collation”). To see an example of very advanced sorting, look at the Czech
sorting code. MySQL Server supports many different character sets that can be specified at
compile time and runtime.
• The server time zone can be changed dynamically, and individual clients can specify their
own time zone. See Section 10.6, “MySQL Server Time Zone Support”.
Clients and Tools
• MySQL includes several client and utility programs. These include both command-line
programs such as mysqldump andmysqladmin, and graphical programs such as MySQL
Workbench.
• MySQL Server has built-in support for SQL statements to check, optimize, and repair
tables. These statements are available from the command line through the mysqlcheck client.
MySQL also includes myisamchk, a very fast command-line utility for performing these
operations on MyISAM tables. See Chapter 4, MySQL Programs.
• MySQL programs can be invoked with the --help or -? option to obtain online assistance.
History of MySQL
We started out with the intention of using the mSQL database system to connect to our tables
using our own fast low-level (ISAM) routines. However, after some testing, we came to the
conclusion that mSQL was not fast enough or flexible enough for our needs. This resulted in a
new SQL interface to our database but with almost the same API interface as mSQL. This API
was designed to enable third-party code that was written for use with mSQL to be ported easily
for use with MySQL.
MySQL is named after co-founder Monty Widenius's daughter, My.
The name of the MySQL Dolphin (our logo) is “Sakila,” which was chosen from a huge list of
names suggested by users in our “Name the Dolphin” contest. The winning name was submitted
by Ambrose Twebaze, an Open Source software developer from Swaziland, Africa. According to
Ambrose, the feminine name Sakila has its roots in SiSwati, the local language of Swaziland.
Sakila is also the name of a town in Arusha, Tanzania, near Ambrose's country of origin, Uganda
EXECUTION STEPS :
Installation of Mysql on Server
[root@localhost bvcoew]# yum install mysql-server
Loaded plugins: langpacks, refresh-packagekit
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-
transaction, or "yum history redo last", first to finish them. If that doesn't work you'll have to try
removing/installing packages by hand (maybe package-cleanup can help).
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.39-1.fc19 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.39-1.fc19 for package: 1:mariadb-
server-5.5.39-1.fc19.x86_64
--> Processing Dependency: mariadb(x86-64) = 1:5.5.39-1.fc19 for package: 1:mariadb-server-
5.5.39-1.fc19.x86_64
--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.39-1.fc19.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.39-
1.fc19.x86_64
--> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.39-1.fc19.x86_64
--> Processing Dependency: libjemalloc.so.1()(64bit) for package: 1:mariadb-server-5.5.39-
1.fc19.x86_64
--> Running transaction check
---> Package jemalloc.x86_64 0:3.6.0-1.fc19 will be installed
---> Package mariadb.x86_64 1:5.5.39-1.fc19 will be installed
---> Package mariadb-libs.x86_64 1:5.5.39-1.fc19 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.023-2.fc19 will be installed
---> Package perl-DBI.x86_64 0:1.623-2.fc19 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.623-
2.fc19.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.623-
2.fc19.x86_64
--> Processing Dependency: perl(Coro::Select) for package: perl-DBI-1.623-2.fc19.x86_64
--> Processing Dependency: perl(Coro::Handle) for package: perl-DBI-1.623-2.fc19.x86_64
--> Processing Dependency: perl(Coro) for package: perl-DBI-1.623-2.fc19.x86_64
--> Running transaction check
---> Package perl-Coro.x86_64 0:6.23-2.fc19 will be installed
--> Processing Dependency: perl(IO::AIO) >= 3.1 for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(Guard) >= 0.5 for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(Event) >= 1.08 for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(EV) >= 4 for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(AnyEvent::BDB) >= 1 for package: perl-Coro-6.23-
2.fc19.x86_64
--> Processing Dependency: perl(AnyEvent::AIO) >= 1 for package: perl-Coro-6.23-
2.fc19.x86_64
--> Processing Dependency: perl(AnyEvent) >= 7 for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(common::sense) for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(BDB) for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(AnyEvent::Util) for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(AnyEvent::Socket) for package: perl-Coro-6.23-2.fc19.x86_64
--> Processing Dependency: perl(AnyEvent::DNS) for package: perl-Coro-6.23-2.fc19.x86_64
---> Package perl-PlRPC.noarch 0:0.2020-13.fc19 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-
13.fc19.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-
13.fc19.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-
13.fc19.noarch
--> Running transaction check
---> Package perl-AnyEvent.x86_64 0:7.04-2.fc19 will be installed
--> Processing Dependency: perl(Task::Weaken) for package: perl-AnyEvent-7.04-
2.fc19.x86_64
---> Package perl-AnyEvent-AIO.noarch 0:1.1-11.fc19 will be installed
---> Package perl-AnyEvent-BDB.noarch 0:1.1-10.fc19 will be installed
---> Package perl-BDB.x86_64 0:1.90-4.fc19 will be installed
---> Package perl-EV.x86_64 0:4.11-2.fc19 will be installed
---> Package perl-Event.x86_64 0:1.21-2.fc19 will be installed
---> Package perl-Guard.x86_64 0:1.022-4.fc19 will be installed
---> Package perl-IO-AIO.x86_64 0:4.15-4.fc19 will be installed
---> Package perl-Net-Daemon.noarch 0:0.48-5.fc19 will be installed
---> Package perl-common-sense.noarch 0:3.6-4.fc19 will be installed
--> Running transaction check
---> Package perl-Task-Weaken.noarch 0:1.04-6.fc19 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================
=====================================================================
============
Package Arch Version Repository
Size
=====================================================================
=====================================================================
============
Installing:
mariadb-server x86_64 1:5.5.39-1.fc19 updates
11 M
Installing for dependencies:
jemalloc x86_64 3.6.0-1.fc19 updates
105 k
mariadb x86_64 1:5.5.39-1.fc19 updates
8.8 M
mariadb-libs x86_64 1:5.5.39-1.fc19 updates
749 k
perl-AnyEvent x86_64 7.04-2.fc19 fedora
427 k
perl-AnyEvent-AIO noarch 1.1-11.fc19 fedora
8.9 k
perl-AnyEvent-BDB noarch 1.1-10.fc19 fedora
8.9 k
perl-BDB x86_64 1.90-4.fc19 fedora
73 k
perl-Coro x86_64 6.23-2.fc19 fedora
254 k
perl-DBD-MySQL x86_64 4.023-2.fc19 fedora
140 k
perl-DBI x86_64 1.623-2.fc19 fedora
806 k
perl-EV x86_64 4.11-2.fc19 fedora
256 k
perl-Event x86_64 1.21-2.fc19 fedora
282 k
perl-Guard x86_64 1.022-4.fc19 fedora
19 k
perl-IO-AIO x86_64 4.15-4.fc19 fedora
111 k
perl-Net-Daemon noarch 0.48-5.fc19 fedora
51 k
perl-PlRPC noarch 0.2020-13.fc19 fedora
35 k
perl-Task-Weaken noarch 1.04-6.fc19 fedora
18 k
perl-common-sense noarch 3.6-4.fc19 fedora
28 k
Transaction Summary
=====================================================================
=====================================================================
============
Install 1 Package (+18 Dependent packages)
Total size: 23 M
Total download size: 23 M
Installed size: 116 M
Is this ok [y/d/N]: y
Downloading packages:
perl-AnyEvent-7.04-2.fc19.x86_ FAILED
https://ftp-stud.hs-
esslingen.de/pub/Mirrors/archive.fedoraproject.org/fedora/linux/releases/19/Everything/x86_64/
os/Packages/p/perl-AnyEvent-7.04-2.fc19.x86_64.rpm: [Errno 14] curl#60 - "Peer's Certificate
issuer is not recognized."
Trying other mirror.
mariadb-5.5.39-1.fc19.x86_64.r FAILED ] 0.0
B/s | 0 B --:--:-- ETA
https://ftp-stud.hs-
esslingen.de/pub/Mirrors/archive.fedoraproject.org/fedora/linux/updates/19/x86_64/mariadb-
5.5.39-1.fc19.x86_64.rpm: [Errno 14] curl#60 - "Peer's Certificate issuer is not recognized."
Trying other mirror.
(1/18): perl-AnyEvent-BDB-1.1-10.fc19.noarch.rpm
| 8.9 kB 00:00:06
(2/18): perl-BDB-1.90-4.fc19.x86_64.rpm
| 73 kB 00:00:05
(3/18): perl-AnyEvent-AIO-1.1-11.fc19.noarch.rpm
| 8.9 kB 00:00:12
(4/18): perl-Coro-6.23-2.fc19.x86_64.rpm |
254 kB 00:00:06
(5/18): perl-DBD-MySQL-4.023-2.fc19.x86_64.rpm
| 140 kB 00:00:09
(6/18): perl-DBI-1.623-2.fc19.x86_64.rpm
| 806 kB 00:00:10
(7/18): perl-Guard-1.022-4.fc19.x86_64.rpm
| 19 kB 00:00:00
(8/18): perl-Event-1.21-2.fc19.x86_64.rpm |
282 kB 00:00:04
(9/18): perl-Net-Daemon-0.48-5.fc19.noarch.rpm
| 51 kB 00:00:01
(10/18): perl-IO-AIO-4.15-4.fc19.x86_64.rpm
| 111 kB 00:00:06
(11/18): perl-Task-Weaken-1.04-6.fc19.noarch.rpm
| 18 kB 00:00:00
(12/18): perl-common-sense-3.6-4.fc19.noarch.rpm
| 28 kB 00:00:00
(13/18): perl-EV-4.11-2.fc19.x86_64.rpm |
256 kB 00:00:12
(14/18): perl-PlRPC-0.2020-13.fc19.noarch.rpm
| 35 kB 00:00:02
(15/18): mariadb-libs-5.5.39-1.fc19.x86_64.rpm
| 749 kB 00:00:33
(16/18): perl-AnyEvent-7.04-2.fc19.x86_64.rpm
| 427 kB 00:00:03
(17/18): mariadb-server-5.5.39-1.fc19.x86_64.rpm
| 11 MB 00:02:54
(18/18): mariadb-5.5.39-1.fc19.x86_64.rpm
| 8.8 MB 00:02:51
---------------------------------------------------------------------------------------------------------------------
---------------------------------
Total 117 kB/s | 23 MB
03:22
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 49 pre-existing rpmdb problem(s), 'yum check' output follows:
audit-libs-2.3.7-1.fc19.x86_64 is a duplicate with audit-libs-2.3.1-2.fc19.x86_64
augeas-libs-1.2.0-1.fc19.x86_64 is a duplicate with augeas-libs-1.0.0-2.fc19.x86_64
bash-4.2.53-1.fc19.x86_64 is a duplicate with bash-4.2.45-1.fc19.x86_64
boost-system-1.53.0-14.fc19.x86_64 is a duplicate with boost-system-1.53.0-6.fc19.x86_64
boost-thread-1.53.0-14.fc19.x86_64 is a duplicate with boost-thread-1.53.0-6.fc19.x86_64
coreutils-8.21-13.fc19.x86_64 is a duplicate with coreutils-8.21-11.fc19.x86_64
cyrus-sasl-lib-2.1.26-10.fc19.x86_64 is a duplicate with cyrus-sasl-lib-2.1.26-8.fc19.x86_64
dbus-glib-0.100-5.fc19.x86_64 is a duplicate with dbus-glib-0.100-4.fc19.x86_64
1:dbus-libs-1.6.28-1.fc19.x86_64 is a duplicate with 1:dbus-libs-1.6.8-5.fc19.x86_64
elfutils-libelf-0.160-1.fc19.x86_64 is a duplicate with elfutils-libelf-0.155-5.fc19.x86_64
file-libs-5.11-13.fc19.x86_64 is a duplicate with file-libs-5.11-9.fc19.x86_64
freetype-2.4.11-7.fc19.x86_64 is a duplicate with freetype-2.4.11-6.fc19.x86_64
glib2-2.36.4-1.fc19.x86_64 is a duplicate with glib2-2.36.3-2.fc19.x86_64
grep-2.14-4.fc19.x86_64 is a duplicate with grep-2.14-3.fc19.x86_64
gstreamer1-1.0.10-1.fc19.x86_64 is a duplicate with gstreamer1-1.0.7-1.fc19.x86_64
json-glib-0.16.2-1.fc19.x86_64 is a duplicate with json-glib-0.16.0-1.fc19.x86_64
keyutils-libs-1.5.9-1.fc19.x86_64 is a duplicate with keyutils-libs-1.5.5-4.fc19.x86_64
krb5-libs-1.11.3-25.fc19.x86_64 is a duplicate with krb5-libs-1.11.3-1.fc19.x86_64
lcms2-2.6-1.fc19.x86_64 is a duplicate with lcms2-2.4-6.fc19.x86_64
libacl-2.2.51-10.fc19.x86_64 is a duplicate with libacl-2.2.51-9.fc19.x86_64
libblkid-2.23.2-5.fc19.x86_64 is a duplicate with libblkid-2.23.1-3.fc19.x86_64
libbluray-0.6.2-1.fc19.x86_64 is a duplicate with libbluray-0.2.3-2.fc19.x86_64
libcap-ng-0.7.4-1.fc19.x86_64 is a duplicate with libcap-ng-0.7.3-3.fc19.x86_64
libdhash-0.4.3-20.fc19.x86_64 is a duplicate with libdhash-0.4.3-17.fc19.x86_64
libgcc-4.8.3-7.fc19.x86_64 is a duplicate with libgcc-4.8.1-1.fc19.x86_64
libgcrypt-1.5.3-2.fc19.x86_64 is a duplicate with libgcrypt-1.5.2-1.fc19.x86_64
libgomp-4.8.3-7.fc19.x86_64 is a duplicate with libgomp-4.8.1-1.fc19.x86_64
libicu-50.1.2-9.fc19.x86_64 is a duplicate with libicu-50.1.2-5.fc19.x86_64
libjpeg-turbo-1.3.1-2.fc19.x86_64 is a duplicate with libjpeg-turbo-1.2.90-2.fc19.x86_64
libmount-2.23.2-5.fc19.x86_64 is a duplicate with libmount-2.23.1-3.fc19.x86_64
libnl3-3.2.22-3.fc19.x86_64 is a duplicate with libnl3-3.2.21-1.fc19.x86_64
2:libpng-1.5.13-3.fc19.x86_64 is a duplicate with 2:libpng-1.5.13-2.fc19.x86_64
libproxy-0.4.11-7.fc19.x86_64 is a duplicate with libproxy-0.4.11-3.fc19.x86_64
libpwquality-1.2.3-1.fc19.x86_64 is a duplicate with libpwquality-1.2.1-2.fc19.x86_64
libsoup-2.42.3.1-1.fc19.x86_64 is a duplicate with libsoup-2.42.2-1.fc19.x86_64
libstdc++-4.8.3-7.fc19.x86_64 is a duplicate with libstdc++-4.8.1-1.fc19.x86_64
libtevent-0.9.19-1.fc19.x86_64 is a duplicate with libtevent-0.9.18-1.fc19.x86_64
libuuid-2.23.2-5.fc19.x86_64 is a duplicate with libuuid-2.23.1-3.fc19.x86_64
libxml2-2.9.1-2.fc19.x86_64 is a duplicate with libxml2-2.9.1-1.fc19.x86_64
nspr-4.10.7-1.fc19.x86_64 is a duplicate with nspr-4.9.6-1.fc19.x86_64
nss-util-3.17.2-1.fc19.x86_64 is a duplicate with nss-util-3.14.3-1.fc19.x86_64
pam-1.1.6-12.fc19.x86_64 is a duplicate with pam-1.1.6-11.fc19.1.x86_64
pcre-8.32-12.fc19.x86_64 is a duplicate with pcre-8.32-7.fc19.x86_64
popt-1.16-2.fc19.x86_64 is a duplicate with popt-1.13-14.fc19.x86_64
readline-6.2-8.fc19.x86_64 is a duplicate with readline-6.2-6.fc19.x86_64
shared-mime-info-1.1-6.fc19.x86_64 is a duplicate with shared-mime-info-1.1-4.fc19.x86_64
sqlite-3.8.3-1.fc19.x86_64 is a duplicate with sqlite-3.7.17-1.fc19.x86_64
systemd-libs-204-21.fc19.x86_64 is a duplicate with systemd-libs-204-8.fc19.x86_64
tcp_wrappers-libs-7.6-75.fc19.x86_64 is a duplicate with tcp_wrappers-libs-7.6-73.fc19.x86_64
Installing : perl-common-sense-3.6-4.fc19.noarch
1/19
Installing : 1:mariadb-libs-5.5.39-1.fc19.x86_64
2/19
Installing : perl-IO-AIO-4.15-4.fc19.x86_64
3/19
Installing : perl-BDB-1.90-4.fc19.x86_64
4/19
Installing : jemalloc-3.6.0-1.fc19.x86_64
5/19
Installing : 1:mariadb-5.5.39-1.fc19.x86_64
6/19
Installing : perl-EV-4.11-2.fc19.x86_64
7/19
Installing : perl-Task-Weaken-1.04-6.fc19.noarch
8/19
Installing : perl-AnyEvent-7.04-2.fc19.x86_64
9/19
Installing : perl-AnyEvent-AIO-1.1-11.fc19.noarch
10/19
Installing : perl-AnyEvent-BDB-1.1-10.fc19.noarch
11/19
Installing : perl-Event-1.21-2.fc19.x86_64
12/19
Installing : perl-Guard-1.022-4.fc19.x86_64
13/19
Installing : perl-Coro-6.23-2.fc19.x86_64
14/19
Installing : perl-Net-Daemon-0.48-5.fc19.noarch
15/19
Installing : perl-PlRPC-0.2020-13.fc19.noarch
16/19
Installing : perl-DBI-1.623-2.fc19.x86_64
17/19
Installing : perl-DBD-MySQL-4.023-2.fc19.x86_64
18/19
Installing : 1:mariadb-server-5.5.39-1.fc19.x86_64
19/19
Verifying : 1:mariadb-server-5.5.39-1.fc19.x86_64
1/19
Verifying : perl-AnyEvent-AIO-1.1-11.fc19.noarch
2/19
Verifying : perl-EV-4.11-2.fc19.x86_64
3/19
Verifying : 1:mariadb-5.5.39-1.fc19.x86_64
4/19
Verifying : perl-Coro-6.23-2.fc19.x86_64
5/19
Verifying : jemalloc-3.6.0-1.fc19.x86_64
6/19
Verifying : perl-Net-Daemon-0.48-5.fc19.noarch
7/19
Verifying : perl-AnyEvent-BDB-1.1-10.fc19.noarch
8/19
Verifying : 1:mariadb-libs-5.5.39-1.fc19.x86_64
9/19
Verifying : perl-AnyEvent-7.04-2.fc19.x86_64
10/19
Verifying : perl-DBI-1.623-2.fc19.x86_64
11/19
Verifying : perl-common-sense-3.6-4.fc19.noarch
12/19
Verifying : perl-Guard-1.022-4.fc19.x86_64
13/19
Verifying : perl-PlRPC-0.2020-13.fc19.noarch
14/19
Verifying : perl-IO-AIO-4.15-4.fc19.x86_64
15/19
Verifying : perl-Event-1.21-2.fc19.x86_64
16/19
Verifying : perl-Task-Weaken-1.04-6.fc19.noarch
17/19
Verifying : perl-DBD-MySQL-4.023-2.fc19.x86_64
18/19
Verifying : perl-BDB-1.90-4.fc19.x86_64
19/19
Installed:
mariadb-server.x86_64 1:5.5.39-1.fc19
Dependency Installed:
jemalloc.x86_64 0:3.6.0-1.fc19 mariadb.x86_64 1:5.5.39-1.fc19
mariadb-libs.x86_64 1:5.5.39-1.fc19
perl-AnyEvent.x86_64 0:7.04-2.fc19 perl-AnyEvent-AIO.noarch 0:1.1-11.fc19
perl-AnyEvent-BDB.noarch 0:1.1-10.fc19
perl-BDB.x86_64 0:1.90-4.fc19 perl-Coro.x86_64 0:6.23-2.fc19 perl-
DBD-MySQL.x86_64 0:4.023-2.fc19
perl-DBI.x86_64 0:1.623-2.fc19 perl-EV.x86_64 0:4.11-2.fc19 perl-
Event.x86_64 0:1.21-2.fc19
perl-Guard.x86_64 0:1.022-4.fc19 perl-IO-AIO.x86_64 0:4.15-4.fc19 perl-
Net-Daemon.noarch 0:0.48-5.fc19
perl-PlRPC.noarch 0:0.2020-13.fc19 perl-Task-Weaken.noarch 0:1.04-6.fc19
perl-common-sense.noarch 0:3.6-4.fc19
Complete!
II] On SERVER
[bvcoew@localhost ~]$ su
Password:
[root@localhost bvcoew]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@localhost bvcoew]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> Bye
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> Bye
[root@localhost bvcoew]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
[root@localhost bvcoew]#
ON CLIENT
[root@localhost bvcoew]# locate my.cnf
/etc/my.cnf
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf
[root@localhost bvcoew]#gedit /etc/my.cnf
// add a line below[mysqld] :-
//bind-address=server IP-address 172.24.3.23
mysql>
CONCLUSION : students have studied open source database management system and installed
Mysql database
GROUP A
EXPERIMENT 2
OBJECTIVE : Study Design and implementation of SQL DDL statements which demonstrate
the use of SQL objects such as Table, View, Index, Sequence, Synonym
PROBLEM STATEMENT: Design and Develop SQL DDL statements which demonstrate the
use of SQL objects such as Table, View, Index, Sequence, Synonym
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : Student are able to Design and Implement of SQL DDL statements for SQL
objects such as Table, View, Index, Sequence, Synonym
THEORY :
managing data held in a relational database management system (RDBMS).
Originally based upon relational algebra and tuple relational calculus, SQL consists of a data
definition language and a data manipulation language. The scope of SQL includes data insert,
query, update and delete, schema creation and modification, and data access control.
MySQL :-
MySQL officially, but also called is the world's second most widely used open-source relational
database management system . It is named after co-founder Michael Widenius's daughter, My.
The SQL phrase stands for Structured Query Language.
The MySQL development project has made its source code available under the terms of the
GNU General Public License, as well as under a variety of proprietary agreements. MySQL was
owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned
by Oracle Corporation.
Features :-
- High performance
- High availability
- Managment ease
Operators are used to specify conditions in an SQL statement and to serve as conjunctions for
multiple conditions in a statement.
- Arithmetic operators
- Comparison operators
- Logical operators
CREATE statement -
The create table command defines each column of the table yniquely. Each column has at least
three attributes : column name, datatypes, size
Syntax -
Desceribing tables _
Syntax -
desc<name of table>
ALTER statement :-
If you are adding constraints to the existing table then you have to use ALTER satement as you
are altering or changing the structure of the already existing table.
INSERT statement :-
To insert data into MySQL table, you would need to use SQL INSERT INTO command. You
can insert data into MySQL table by using mysql> prompt
Syntax -
The standard SQL commands to interact with relational databases are CREATE, SELECT,
INSERT, UPDATE, DELETE and DROP. These commands can be classified into groups based
on their nature:
DROP Deletes an entire table, a view of a table or other object in the database.
[bvcoew@localhost ~]$ su
Password:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
You can turn off this feature to get a quicker startup with -A
Database changed
+----------+------------+--------+---------+
+----------+------------+--------+---------+
| 1 | s1 | 15 | pune |
| 2 | s2 | 25 | chennai |
| 3 | s3 | 33 | mumbai |
+----------+------------+--------+---------+
+---------+-----------+--------+--------+---------+
+---------+-----------+--------+--------+---------+
+---------+-----------+--------+--------+---------+
+----------+---------+----------+
+----------+---------+----------+
| 1| 101 | 100 |
| 2| 201 | 500 |
| 3| 301 | 900 |
+----------+---------+----------+
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+------
--+------+------------+---------+---------------+
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+------
--+------+------------+---------+---------------+
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+------
--+------+------------+---------+---------------+
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+------
--+------+------------+---------+---------------+
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+------
--+------+------------+---------+---------------+
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+------
--+------+------------+---------+---------------+
Create a view form supplier having city chennai and status grater than 25
mysql> create view viewsup as select * from supplier where city='chennai' and status >25;
+--------+----------+--------+---------+
+--------+----------+--------+---------+
| p1 | Ajay | 200 | chennai |
+--------+----------+--------+---------+
+--------+----------+--------+---------+
+--------+----------+--------+---------+
+--------+----------+--------+---------+
Create a view form supplier having city chennai and status grater than 25
mysql> create view viewsup as select * from supplier where city='chennai' and status >25;
+--------+----------+--------+---------+
+--------+----------+--------+---------+
+--------+----------+--------+---------+
+--------+----------+--------+---------+
+--------+----------+--------+---------+
+--------+----------+--------+---------+
CONCLUSION : Student successfully Designed and Implemented of SQL DDL statements for
SQL objects such as Table, View, Index, Sequence, Synonym
GROUP A
EXPERIMENT 3
OBJECTIVE :To Study Design and implementation of at least 10 SQL queries for suitable
database application using SQL DML statements: Insert, Select, Update, Delete with operators,
functions, and set operator.
PROBLEM STATEMENT: Design at least 10 SQL queries for suitable database application
using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set
operator.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : After completion of assignment student are able to implement SQL queries for
Inserting, Selecting, Updating, Deleting with operators, functions, and set operator.
EXECUTION STEPS :
GET SUPPLIER NO. AND STATUS FOR SUPPLIERS IN CHENNAI WITH STATUS>20.
MariaDB [pearl]> select suppl_no,status from supplier where city='chennai' and status>20;
+----------+--------+
| suppl_no | status |
+----------+--------+
| 2| 25 |
+----------+--------+
1 row in set (0.00 sec)
Get all the pair of supplier numbers such that the suppliers concerned are
colocated(i.e located in the same city).
MariaDB [pearl]> select a.supp_no as sa, b.supp_no as sb from supplier as a, supplier as b where
a.city=b.city and a.supp_no<b.supp_no;
+----+----+
| sa | sb |
+----+----+
|1 |3 |
+----+----+
GET FULL SUPPLIER INFORMATION FOR SUPPLIER WHO SUPPLIES PART P2.
+---------+-----------+--------+
+---------+-----------+--------+
|2 | Aditi | Kolhar |
+---------+-----------+--------+
GET SUPPLIER NAME FOR SUPPLIER WHO SUPPLIES AT LEAST ONE RED
PART.
+------------+
| suppl_name |
+------------+
| s1 |
+------------+
GET SUPPLIER NAME FOR SUPPLIER WHO SUPPLY AT LEAST ONE PART
SUPPLIED BY SUPPLIER S2.
MariaDB [pearl]> select distinct supp_no from shipment where part_no in(select part_no from
shipment where supp_no=2);
+---------+
| supp_no |
+---------+
|2 |
+---------+
DELETE SUPPLIER'S NAME FOR SUPPLIER WHO DO NOT SUPPLY PART P2.
+-----------+
| supp_name |
+-----------+
| Hetanshi |
+-----------+
MariaDB [pearl]> Update part set color=’RED’ where city!='chennai' and weight>=10;
+--------+--------+
| color | city |
+--------+--------+
| red | pune |
| orange | mumbai |
+--------+--------+
+---------+-------+
| part_no | gmwt |
+---------+-------+
| 101 | 29510 |
| 201 | 22700 |
| 301 | 18160 |
+---------+-------+
+---+
|n|
+---+
|3|
+---+
+---------------+
| min(quantity) |
+---------------+
| 100 |
+---------------+
+---------------+
| max(quantity) |
+---------------+
| 100 |
+---------------+
+---------+
| part_no |
+---------+
| 12 |
| 15 |
+---------+
GET SUPPLIER NO. FROM SUPPLIER WITH STATUS GREATER THAN CURRENT
MAXIMUM STATUS IN THE SUPPLIER TABLE.
MariaDB [pearl]> select supp_no from supplier where status<(select max(status)from supplier);
+---------+
| supp_no |
+---------+
|1 |
|2 |
|3 |
|4 |
+---------+
+----------+------------+--------+---------+---------+-----------+
+----------+------------+--------+---------+---------+-----------+
| 1 | s1 | 15 | pune | 101 | p1 |
| 2 | s2 | 25 | chennai | 201 | p2 |
| 3 | s3 | 33 | mumbai | 301 | p3 |
+----------+------------+--------+---------+---------+-----------+
GET ALL PAIRS OF CITY NAMES SUCH THAT A SUPPLIER LOCATED IN FIRST
CITY SUPPLIES A PART STORED IN SECOND CITY.
MariaDB [pearl]> select distinct supplier.city as 'pune',part.city as chennai from supplier natural
join shipment natural join part;
+---------+---------+
| pune | chennai |
+---------+---------+
| pune | pune |
| chennai | chennai |
| mumbai | mumbai |
+---------+---------+
FOR EACH PART SUPPLIED GET PART NO. AND TOTAL SHIPMENT QUANTITY
+------------------------+
| sum(shipment.quantity) |
+------------------------+
| 100 |
| 500 |
| 900 |
+------------------------+
+------------------------+
| avg(quantity) |
+------------------------+
| 100 |
| 500 |
| 900 |
+------------------------+
EXPERIMENT 4
OBJECTIVE : To study Design and implementation of 10 SQL queries for suitable database
application using SQL DML statements: all types of Join, Sub-Query and View.
PROBLEM STATEMENT: Design at least 10 SQL queries for suitable database application
using SQL DML statements: all types of Join, Sub-Query and View.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : After completion of assignment student are able to implement 10 SQL queries for
suitable database application using SQL DML statements: all types of Join, Sub-Query and
View.
EXECUTION STEPS :
Perform inner join on supplier and parts on 'city'.
+----------+
| sup_name |
+----------+
| trupti |
| sneha |
| shreya |
+----------+
3 rows in set (0.00 sec)
+---------+-----------+------+---------+---------+----------+
+---------+-----------+------+---------+---------+----------+
+---------+-----------+------+---------+---------+----------+
+--------+---------+--------+---------+-------+
+--------+---------+--------+---------+-------+
|1 | p1 | 20 | p1 | Sneha |
|2 | p2 | 10 | p2 | Mansi |
|3 | p3 | 270 | NULL | NULL |
|4 | p4 | 27 | NULL | NULL |
+--------+---------+--------+---------+-------+
+----------+
| sup_name |
+----------+
| trupti |
| sneha |
| shreya |
+----------+
+--------+---------+--------+---------+-------+
+--------+---------+--------+---------+-------+
|1 | p1 | 20 | p1 | Sneha |
|2 | p2 | 10 | p2 | Mansi |
|3 | p3 | 270 | NULL | NULL |
|4 | p4 | 27 | NULL | NULL |
+--------+---------+--------+---------+-------+
EXPERIMENT 5
OBJECTIVE : To study Unnamed PL/SQL code block and use of Control structure and
Exception handling is mandatory. Write a PL/SQL block of code for Library fine calculation.
PROBLEM STATEMENT: Unnamed PL/SQL code block: Use of Control structure and
Exception handling is mandatory. Write a PL/SQL block of code for the following
requirements:-
Schema:
1. Borrower(Rollin, Name, DateofIssue, NameofBook, Status)
2. Fine(Roll_no,Date,Amt)
Accept roll_no & name of book from user.
Check the number of days (from date of issue), if days are between 15 to 30 then fine amount
will be Rs 5per day.
If no. of days>30, per day fine will be Rs 50 per day & for days less than 30, Rs. 5 per day.
After submitting the book, status will change from I to R.
If condition of fine is true, then details will be stored into fine table.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : After completion of assignment student are able to explain Unnamed PL/SQL
code block , use of Control structure and Exception handling is mandatory and write a PL/SQL
block of code for Library fine calculation.
THEORY :
Limitations of SQL
SQL is the most powerful and comprehensive database language. It is flexible and efficient. SQL is
designed for working with relational data. Even though it is powerful and efficient it has certain
limitations.
Some of the limitations are :
• SQL is a non-procedural language.
• SQL does not allow declaring and using the constants, variables.
• We cannot control the flow of execution using SQL.
• SQL processes a set of rows at a time and does not support row by row processing.
PL/SQL is the procedural language extension to the SQL, in which you can declare and use the
variables, constants, do exception handling and you can also write the program modules in the form
of PL/SQL subprograms. PL/SQL combines the features of a procedural Language with Structured
Query Language.
Advantages of PL/SQL
Some of the advantages of PL/SQL are as follows
Improved performance
In SQL, every statement individually goes to the ORACLE server, get processed there and
we get the response. In PL/SQL, an entire block of statements can be sent to ORACLE
server at one time, where as SQL statements are processed one at a time. Thus, PL/SQL
block statements drastically reduce communication between the application and ORACLE.
This helps in improving the performance.
SQL PROCESSING
Oracle Client Oracle Server
SQL Statement
SQL Statement
SQL
Higher productivity
Users use procedural features to build applications. PL/SQL code is written in the form of
PL/SQL block. PL/SQL blocks can also be used in other ORACLE tools like ORACLE Forms,
ORACLE Reports. This code reusability increases the programmers productivity.
Portability
Applications written in PL/SQL are portable. We can port them from one environment to any
computer hardware and operating system environment running ORACLE. Programs need
not be tailored for the new environment.
Features of PL/SQL
Some of the features of PL/SQL are as follows.
We can define and use variables and constants in PL/SQL.
PL/SQL provides control structures to control the flow of a program. The control structures
supported by PL/SQL are IF..THEN, LOOP, FOR..LOOP and Others.
We can do row by row processing of data in PL/SQL. PL/SQL supports row by row
processing using the mechanism called CURSOR (explained later).
We can handle pre-defined and user-defined error situations. Errors or warnings are called as
exceptions in PL/SQL. To handle these errors, you can write the code in the form of
Exception handlers in PL/SQL.
We can write modular application by using sub programs. The different types of sub-
programs are procedures, functions and packages.
The Structure of a PL/SQL Program
The basic unit of code in any PL/SQL program is a block. All PL/SQL programs are composed of
blocks. These blocks can be written sequentially (one after the other) or nested (one inside the other).
Typically, each block is written to perform a logical unit of work in a program.
DECLARE
Declarative section –
PL/SQL variables, types, cursors, and local subprograms are defined here.
This section is optional.
BEGIN
Executable section –
Procedural and SQL statements are written here. This is the main section of the block.
This section is required.
EXCEPTION
Exception handling section –
Error handling code is written here.
This section is optional.
END;
EXPERIMENT 6
OBJECTIVE : To study and implement database cursors for given problem statement.
PROBLEM STATEMENT: Cursors: (All types: Implicit, Explicit, Cursor FOR Loop,
Parameterized Cursor)
Write a PL/SQL block of code using parameterized Cursor, that will merge the data available in
the newly created table N_RollCall with the data available in the table O_RollCall. If the data in
the first table already exist in the second table then that data should be skipped.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : After completion of assignment student are able to implement database cursors
for merging two tables.
THEORY :
What is a Cursor?
For the processing of an SQL statement, the database needs to allocate memory. This memory is
known as the context area. The context area is a part of the PGA (Process Global Area) and is
allocated on the ORACLE Server. The memory structures SGA and PGA are explained in detail in
the chapter “ORACLE Architecture”.
A Cursor is associated with this work area (context area) used by ORACLE, for multi-row queries.
Here, ORACLE keeps track of row processing and related information.
A Cursor is a handle, or pointer to the context area. Using the cursor we can access the context
area. The cursor allows us to process the contents in the context area row by row and know some
information about it.
Types of Cursors
There are two types of cursors, explicit cursors and implicit cursors. Explicit cursors are defined
explicitly by the user in a PL/SQL block and implicit cursors are defined by ORACLE implicitly.
ORACLE defines implicit cursor for every SQL DML statement it processes.
Implicit Cursors
All the SQL DML statements or single row SELECT…INTO statements, are executed inside a
context area. During the processing, ORACLE implicitly defines a cursor that points to this
context area. It is known as a SQL cursor.
ORACLE implicitly
Opens this SQL cursor ( memory is allocated and a set rows brought into the PGA),
Processes the SQL statement in it ( processes the statement using rows), and
Closes the cursor afterwards( de-allocating memory and making resources free).
The implicit cursor cannot be used by the user for processing its contents. However, the user
can use the implicit cursor attributes to get the information about execution of the SQL
statement.
%FOUND
%NOTFOUND
%ISOPEN
%ROWCOUNT
Explicit Cursors
These are user-defined cursors. Explicit cursors are defined in the declaration section of the
PL/SQL block. Explicit cursor manipulation is done through OPEN, FETCH, CLOSE Statements.
Explicit cursor information can be accessed using its attributes. There are four steps in which the
explicit cursor is processed
Declaring a cursor
Opening a cursor
Fetching rows from an opened cursor
Closing a cursor
EXECUTION STEPS :
EXECUTION STEPS :
Enter password: ******
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Database changed
+---------+--------+
| roll_no | name |
+---------+--------+
| 2 | Aparna |
| 4 | maan |
| 5 | tips |
| 7 | Sneha |
| 8 | chotu |
+---------+--------+
mysql>delimiter $$;
-> BEGIN
-> DECLARE cur_2 CURSOR FOR SELECT roll_no FROM N_Rollcall where roll_no=inr
n;
-> DECLARE cur_1 CURSOR FOR SELECT roll_no,name FROM O_Rollcall where roll_n
o=inrn;
-> END; $$
Query OK, 0 rows affected (0.00 sec)
+--------+--------+------+
+--------+--------+------+
| 4 | maan | NULL |
+--------+--------+------+
+--------+-------+------+
+--------+-------+------+
| 5 | tips | NULL |
+--------+-------+------+
+--------+--------+------+
+--------+--------+------+
| 8 | chotu | NULL |
+--------+--------+------+
1 row in set (0.00 sec)
+---------+--------+
| roll_no | name |
+---------+--------+
| 2 | Aparna |
| 7 | Sneha |
| 4 | maan |
| 5 | tips |
| 8 | chotu |
+---------+--------+
+--------+--------+------+
+--------+--------+------+
| 7 | Sneha | NULL |
+--------+--------+------+
+---------+--------+
| roll_no | name |
+---------+--------+
| 2 | Aparna |
| 7 | Sneha |
+---------+--------+
CONCLUSION : Student successfully implemented database cursors for merging two tables.
GROUP A
EXPERIMENT 7
OBJECTIVE : To study and implement PL/SQL Stored Procedure and Stored Function
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
THEORY :
Subprogram Types
There are two types of subprogram:
• Procedures
• Functions
Procedures and functions both are PL/SQL programs addressed by name. They are stored on the
ORACLE Server in the form of compiled code, called as the p-code. Once a subprogram is created,
different ORACLE products and applications can reference it.
Procedures
A procedure is a subprogram that performs a specific action or task. A procedure has two parts
The procedure specification
The procedure body
The procedure specification specifies the procedure name and the parameters it accepts. It is not
necessary to create a procedure that accepts parameters.
The procedure body contains the declarative section without DECLARE keyword, the executable
section and an exception handling section.
Creating a procedure
The general syntax for procedure creation is
CREATE [ OR REPLACE ] PROCEDURE procedure_name
[ ( argument1 [ IN / OUT / IN OUT ] type ) ,
( argument2 [ IN / OUT / IN OUT ] type ) ,
...]
IS / AS
procedure_body
Where,
procedure_name - is the name of the procedure to be created
argument - is the name of the procedure parameter
type - is the data type of the associated parameter
procedure_body - is a PL/SQL block that makes up the code of the procedure.
Functions
A function is a subprogram, which is used to compute values and in many respects function is similar
to a procedure. Function also takes arguments and can be in different modes. Function also can be
stored in the database. It is a PL/SQL block consisting of declarative, executable, and exception
section.
The main difference in the procedure and a function is that the procedure call is a PL/SQL statement
by itself, while a function call is called as a part of an expression.Creating a Function
The general syntax for creation of function is.
CREATE OR REPLACE FUNCTION function_name
[ ( argument1 [ IN / OUT / IN OUT ] type ) ,
( argument2 [ IN / OUT / IN OUT ] type ) ,
...]
RETURN return_type IS / AS function_body
Where,
function_name - is the name of the function to be created
argument - is the name of the function parameter
type - is the data type of the associated parameter
return_type - is the type of the value that the function returns
function_body - is a PL/SQL block containing the code for the function.
Similar to procedures, the argument list is optional. The function return type is required, since the
function call is a part of an expression. The return type of the function is used to determine the
type of the expression containing the function call.
MariaDB [Result]> create procedure p (IN roll_no integer,IN name varchar(20),In total_marks
integer)
-> begin
-> end;
-> $$
-> $$
-> $$
+---------+-------+-------------+
+---------+-------+-------------+
| 1 | Trupti| DISTINCTION
|2 |Neha|FIRST CLASS |
| 3 |sneha |DISTINCTION
+---------+-------+-------------+
+-------+-------------+
| name | total_marks |
+-------+-------------+
| NULL | NULL |
| Trupti | 1450 |
|Neha | 978 |
|sneha | 1100 |
+-------+-------------+
OUTCOME : After completion of assignment student are able to implement PL/SQL Stored
Procedure to calculate student grade.
EXPERIMENT 8
OBJECTIVE : To study and implement Database Trigger (All Types: Row level and Statement
level triggers, Before and After Triggers).
PROBLEM STATEMENT: Database Trigger (All Types: Row level and Statement level
triggers, Before and After Triggers). Write a database trigger on Library table. The System
should keep track of the records that are being updated or deleted. The old value of updated or
deleted records should be added in Library_Audit table.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
OUTCOME : After completion of assignment student are able to implement Database Trigger
(All Types: Row level and Statement level triggers, Before and After Triggers) for maintaining
library logs.
THEORY :
What are Database Triggers?
A database trigger is a PL/SQL program unit that is associated with a specific table. Triggers
can be used for purposes like auditing, implementing additional security. Triggers are
associated with a specific table and are fired automatically whenever the table gets
manipulated in a predefined way. The act of executing a trigger is called as firing a trigger.
Triggers are similar to procedures, in that they are named PL/SQL blocks with declarative,
executable, and exception-handling sections. However there are some differences between a
trigger and a procedure.
A procedure is executed explicitly from another block via a procedure call but a trigger is
executed implicitly whenever the triggering event happens. A procedure can also pass
arguments, but a trigger doesn’t accept arguments.
A database trigger has got the following components
• A triggering Event
• A triggering Constraint
• A triggering Action
Uses of Triggers
A trigger is fired automatically whenever any user or application modifies the associated
table in a predefined way. Triggers behave uniformly with respect to all users and
applications.
A Trigger can be utilized for
• Enforcing complex business rules - Triggers can be used to implement complex
integrity constraints not possible through declarative constraints in table creation.
• Audit Operations - Auditing information in a table by recording the changes made and
who made them. Since, triggers are executed automatically you can use triggers to log
events transparently based on DML operations.
• Maintain replicate tables / signaling other tables - Triggers can be used for
automatically signaling other programs that action needs to take place when changes are
made to the table.
• Computing values - A trigger can be used to derive column values automatically during
a data manipulation operation.
• Security - Triggers can be used to implement complex security authorizations.
Trigger categories
Triggers are categorised in various ways. Trigger are categorised using
• Trigger Type
• Triggering Time
• Triggering Event
Trigger Types
There are two types of triggers
Statement Trigger
Row Trigger
Statement Trigger
A Statement Trigger is a trigger in which the trigger action is executed once for the
manipulation operation that fires the trigger. You can use a statement trigger when
the trigger action is independent of the data provided by the operation that fires the
trigger and/or the affected rows.
Example: a statement trigger can be used to maintain the log of operation on a
particular table.
Row Trigger
A Row Trigger is a trigger in which the trigger action is performed repeatedly for
each row of the table that is affected by the manipulation operation that fires the
trigger. You use a row trigger when the trigger action is dependent on the data
provided by the operation that fires the trigger and/or the accented rows.
For example, a row level trigger can be used for maintaining the consolidated balance
with each transaction.
Triggering Time
Triggers can specify the time of trigger action. Possible options for the time of a trigger
action are
BEFORE the triggering event
AFTER the triggering event
Before Trigger
The trigger action is performed before the operation that fires the trigger is executed.
This trigger is used when execution of operation depends on trigger action. For
example, in a bank account, before debiting an account, checking whether the current
balance is greater than the amount to be debited.
After Trigger
The trigger action is performed after the operation that fires the trigger is executed.
This trigger is used when triggering action depends on the execution of operation. For
example, in a bank account, updating balance after debiting or crediting an account.
Triggering Events
Triggering events are the DML operations. These operations are
Insert
Update
Delete
When these operations are performed on a table, the trigger, which is associated with the
operation, is fired. Triggering events divide triggers into these three types
DELETE TRIGGER
INSERT TRIGGER
UPDATE TRIGGER
EXECUTION STEPS :
Database changed
+------+-----------------+-----------+--------------+
+------+-----------------+-----------+--------------+
| 1 | Java | tips | 20 |
| 2 | C++ | appy | 33 |
| 3 | Basic C | maan | 23 |
| 4 | Android | sanedo | 45 |
+------+-----------------+-----------+--------------+
-> $$
+------------------+---------+------+-----+---------+-------+
+------------------+---------+------+-----+---------+-------+
+------------------+---------+------+-----+---------+-------+
MariaDB [library]> create trigger t1 before update on library for each row begin insert into
Lib_audit values(b_no,old.allowed_days,new.allowed_days); end;$$
Query OK, 0 rows affected (0.07 sec)
-> $$
-> $$
-> $$
+------+-----------------+-----------+--------------+
+------+-----------------+-----------+--------------+
| 1 | Java | tips | 20 |
| 2 | C++ | appy | 33 |
| 3 | Basic C | maan | 60 |
| 4 | Android | sanedo | 40 |
+------+-----------------+-----------+--------------+
-> $$
Query OK, 1 row affected (0.02 sec)
-> $$
+------+-----------------+-----------+--------------+
+------+-----------------+-----------+--------------+
| 1 | Java | tips | 20 |
| 2 | C++ | appy | 60 |
| 3 | Basic C | maan | 60 |
| 4 | Android | sanedo | 40 |
+------+-----------------+-----------+--------------+
-> $$
+------+------------------+-------------+
+------+------------------+-------------+
| NULL | 33 | 60 |
+------+------------------+-------------+
MariaDB [library]> create trigger t2 after delete on library for each row begin insert into
Lib_audit values(old.b_no,old.allowed_days,old.allowed_days); end;$$
-> $$
+------+-----------------+-----------+--------------+
+------+-----------------+-----------+--------------+
| 1 | Java | tips | 20 |
| 2 | C++ | appy | 60 |
| 3 | Basic C | maan | 60 |
| 4 | Android | sanedo | 40 |
+------+-----------------+-----------+--------------+
-> $$
-> $$
+------+-----------------+-----------+--------------+
+------+-----------------+-----------+--------------+
| 2 | C++ | appy | 60 |
| 3 | Basic C | maan | 60 |
| 4 | Android | sanedo | 40 |
+------+-----------------+-----------+--------------+
-> $$
+------+------------------+-------------+
+------+------------------+-------------+
| NULL | 33 | 60 |
| 1| 20 | 20 |
+------+------------------+-------------+
EXPERIMENT 9
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mongo DB
OUTCOME :After completion of assignment student are able to install Open Source NOSQL
Database: Mongo DB .
THEORY :
MongoDB is one of several database types to arise in the mid-2000s under the NoSQLbanner.
Instead of using tables and rows as in relational databases, MongoDB is built on an architecture
of collections and documents. Documents comprise sets of key-value pairs and are the basic unit
of data in MongoDB. Collections contain sets of documents and function as the equivalent of
relational database tables. Like other NoSQL databases, MongoDB supports
dynamic schema design, allowing the documents in a collection to have different fields and
structures. The database uses a document storage and data interchange format called BSON,
which provides a binary representation of JSON-like documents. Automatic shardingenables
data in a collection to be distributed across multiple systems for horizontal scalabilityas
data volumes increase.
Mongo DB was created by Dwight Merriman and Eliot Horowitz, who had encountered
development and scalability issues with traditional relational database approaches while
building Web applications at DoubleClick, an Internet advertising company that is now owned
by Google Inc. According to Merriman, the name of the database was derived from the
word humongous to represent the idea of supporting large amounts of data. Merriman and
Horowitz helped form 10Gen Inc. in 2007 to commercialize MongoDB and related software. The
company was renamed MongoDB Inc. in 2013.
The database was released to open source in 2009 and is available under the terms of the Free
Software Foundation's GNU AGPL Version 3.0 commercial license. At the time of this writing,
among other users, the insurance company MetLife is using MongoDB for customer service
applications, the website Craigslist is using it for archiving data, the CERN physics lab is using it
for data aggregation and discovery and the The New York Times newspaper is using MongoDB
to support a form-building application for photo submissions
EXECUTION STEPS :
https://www.mongodb.com/download-center#atlas
On First Terminal
On second terminal:
[student@localhost ~]$ cd /home/student/mongodb/mongodb-linux-x86_64-2.6.1
http://docs.mongodb.org/
http://groups.google.com/group/mongodb-user
>
EXPERIMENT 10
PROBLEM STATEMENT: Design and Develop MongoDB Queries using CRUD operations.
(Use CRUD operations, SAVE method, logical operators)
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mongo DB
OUTCOME :After completion of assignment student are able to Design and Develop Mongo
DB Queries using CRUD operations.
THEORY :
Basic Operations with the Shell: We can use the four basic operations, create, read, update and
delete (CRUD) to manipulate and view data in the shell.
2. Read:- Find and find One can be used to query a collection. If we just want to see one
document from a collection, we can use find One. Find and find One can also be passed criteria
in the form of a query document. This will restrict the documents matched by the query. The
shell will automatically display up to 20 documents matching a find, but more can be fetched.
3. Update:- If we would like to modify our post, we can use update. Update takes (at least) two
parameters: the first is the criteria to find which document to update, and the second is the new
document. Suppose we decide to enable comments on the blog post we created earlier. We’ll
need to add an array of comments as the value for a new key in our document.
4.Delete:- Remove permanently deletes documents from the database. Called with no
parameters, it removes all documents from a collection. It can also take a document specifying
criteria for removal.
5.fsync:- Mongo DBs fsync command allows us to copy the data directory of a running Mongo
DB server without risking any corruption. The fsync command will force the MongoDB server
to flush all pending writes to disk. It will also, optionally, hold a lock preventing any further
writes to the database until the server is unlocked.
6. Unlock:- After performing the backup, we need to unlock the database again: Simultaneously
if connection terminal is open you can see changes over their while running this command.
7. touch:-The touch command loads data from the data storage layer into memory. touch can
load the data (i.e. documents) indexes or both documents and indexes. Use this command to
ensure that a collection, and/or its indexes, are in memory before another operation. By loading
the collection or indexes into memory, mongod will ideally be able to perform subsequent
operations more efficiently.
EXECUTION STEPS :
[bvcoew@localhost bin]$ cd mongodb-linux-x86_64-2.6.1
bash: cd: mongodb-linux-x86_64-2.6.1: No such file or directory
[bvcoew@localhost bin]$ file:///home/bvcoew/mongodb-linux-x86_64-2.6.1.tgz
bash: file:///home/bvcoew/mongodb-linux-x86_64-2.6.1.tgz: No such file or directory
[bvcoew@localhost bin]$ cd file:///home/bvcoew/mongodb-linux-x86_64-2.6.1.tgz
bash: cd: file:///home/bvcoew/mongodb-linux-x86_64-2.6.1.tgz: No such file or directory
[bvcoew@localhost bin]$ cd file:///home/bvcoew/mongodb-linux-x86_64-2.6.1.tgz
bash: cd: file:///home/bvcoew/mongodb-linux-x86_64-2.6.1.tgz: No such file or directory
[bvcoew@localhost bin]$ ./mongo
MongoDB shell version: 2.6.1
connecting to: test
> show dbs
admin (empty)
college 0.078GB
engg 0.078GB
local 0.078GB
> use db try
2014-07-21T13:53:46.511+0530 Error: [db try] is not a valid database name at
src/mongo/shell/mongo.js:41
>db.std.find({'city':'pune'})
{ "_id" : ObjectId("53faef0e86280a0032e40ee6"), "name" : "siddhi", "id" : 1, "branch" : "comp",
"class" : "te", "city" : "pune", "street" : "abc", "pin" : 411047,"telephone" : [ 99999999, 1333955,
576878 ] }
{ "_id" : ObjectId("53faef3686280a0032e40ee8"), "name" : "shraddha", "id" : 3, "branch" :
"comp", "class" : "te", "city" : "pune", "street" : "abc", "pin" : 411047 ,"telephone" : [ 99999999,
1333955, 576878 ]}
{ "_id" : ObjectId("53faef4586280a0032e40ee9"), "name" : "neha", "id" : 4, "branch" : "comp",
"class" : "te", "city" : "pune", "street" : "abc", "pin" : 411047 ,"telephone" : [ 99999999,
1333955, 576878 ]}
9)add state:
10)remove state:
> db.std.remove({'name':'john'})
WriteResult({ "nRemoved" : 1 })
> db.std.find();
{ "_id" : ObjectId("53faef0e86280a0032e40ee6"), "name" : "siddhi", "id" : 1, "branch" : "comp",
"class" : "te", "city" : "pune", "street" : "abc", "pin" : 411047, "sub" : [ "dc", "osd", "fca" ], "dc" :
10 }
{ "_id" : ObjectId("53faef2586280a0032e40ee7"), "name" : "bhargavi", "id" : 2, "branch" :
"comp", "class" : "te", "city" : "mumbai", "street" : "abc", "pin" : 411047, "sub" : [ "dc", "osd",
"fca" ] }
{ "_id" : ObjectId("53faef3686280a0032e40ee8"), "name" : "shraddha", "id" : 3, "branch" :
"comp", "class" : "te", "city" : "pune", "street" : "abc", "pin" : 411047, "sub" : [ "dc", "osd",
"fca" ] }
{ "_id" : ObjectId("53faef4586280a0032e40ee9"), "name" : "neha", "id" : 4, "branch" : "comp",
"class" : "te", "city" : "pune", "street" : "abc", "pin" : 411047, "sub" : [ "dc", "osd", "fca" ] }
>
EXPERIMENT 11
OBJECTIVE : To study and implement aggregation and indexing with suitable example using
Mongo DB.
PROBLEM STATEMENT: Implement aggregation and indexing with suitable example using
Mongo DB.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mongo DB
OUTCOME : After completion of assignment student are able to indexing and aggregation in
mongo db.
THEORY :
AGGREGATION:
• It group value from multiple document together and perform a varitey of operation on grouped
data to return a single result.
Aggregate Methods:
Syntax:
db.Collection_Name.aggregate(AGGREGATE_CRITERIA)
• $sum
• $avg
• $min
• $max
• $push
• $addToSet
• $first
• $last
$avg:
calculate the average of all given values from all document in collection.
Example:
db.Teacher_Info.([{$group:{_id:”$by_user”;num_tutorial:{$avg:”$likes”}}}])
$push:
Example:
db.Teacher_Info.([{$group:{_id:”$by_user”;num_tutorial:{$push:”$num_tutorial”}}}])
$addToSet:
Insert the value to an array in the resulting document but dose not create duplicates.
Example:
db.Teacher_Info.([{$group:{_id:”$by_user”;url:{$addToSet:”$url”}}}])
modifiers:
• $set:
It set the value of a key.If the key dosent yet exist the it will be created
for example:
>db.user.update({”name”:”joe”},{”$unset”:{”favourite book”:”1”}})
INDEXING:
Indexes support the efficent resolution of queries.without indexes monodb must scan every
document of collection to select those document that match the query statment.This scan is
highly inefficent and requried 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
transverse form.The index stores the value of specific field or set of fields,orderded by value of
field specified in index.
Syntax:
>db.COLLECTION_NAME.ensureIndex({key:1})
here is the name of the field on which you want to create index and 1 is for ascending order.To
create in descending order you need to use -1.
>db.Teacher_Info.ensureIndex({”Teacher_ID”:1})
In ensureIndex() method we can pass multiple fields to create index on multiple fields.
>db.Teacher_Info.ensureIndex({”Title”:1,”description”:-1})
ensureIndex() method also accepts list of options which list is given below:
• Parameter-Background
Type:Boolean
Description-Buids the index in the background so that building of inex dose not block other
building.An index does not block other database activites.specify true to build in background as
the default value is false.
• Parameter-Unique
Type:Boolean
Description-Creates an unique index so that collection will not accept insertion of document
where the index key or keys match existing value in the index.specify true to create unique index
as default value is false.
• Parameter-Name
Type:String
• Parameter-Drop Dups
Type:Boolean
Description-creates a unique index on the field that may only have duplicates.MongoDB indexes
only the first occurence of a key and removes all document from the collection that contains
subsequent occurence of that key.specify true to craete unique index.The default value is false.
• Parameter-Sparse
Type:Boolean
Description-If true the index only refrences document with specified field.This indexes are less
sparse but behave diffrenty in same situation.
• Parameter-expire Aftersecond
Type:Integer
• Parameter-V
Type:Index Version
Description-The Index Version number.The default index Version of mongodb running when
creating a index.
• Parameter-Weights
Type:Document
Description-The weight is a number ranging from 1 to 99,999 and denotes the significance of the
field relative to other indexed fields in terms of score.
• Parameter-default_language
Type:String
Description-For a text index, the language that determines the list of stop words and the rules for
stemmer and tokenizer.The default value is english.
• Parameter-Language_override
Type:String
Description-for a text index specify the name of field in the documents that contains the
language to override the default language.The default value is language
EXECUTION STEPS :
> db.sinfo.insert({stud_name:'utkarsha',dept:'comp',addr:'chandigarh',class:'te'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.insert({stud_name:'surabhi',dept:'it',addr:'mumbai',class:'fe'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.insert({stud_name:'sanikaN',dept:'comp',addr:'pune',class:'se'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.insert({stud_name:'sanikaM',dept:'mech',addr:'delhi',class:'be'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.insert({stud_name:'sheenam',dept:'entc',addr:'mumbai',class:'fe'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.insert({stud_name:'ridhima',dept:'it',addr:'pune',class:'se'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.insert({stud_name:'rachna',dept:'mech',addr:'bangalore',class:'te'});
WriteResult({ "nInserted" : 1 })
> db.sinfo.find().pretty()
"_id" : ObjectId("540f0eb1e1cee50b9f1ee7bc"),
"stud_name" : "utkarsha",
"dept" : "comp",
"addr" : "chandigarh",
"class" : "te"
"_id" : ObjectId("540f0ee1e1cee50b9f1ee7bd"),
"stud_name" : "surabhi",
"dept" : "it",
"addr" : "mumbai",
"class" : "fe"
"_id" : ObjectId("540f0f0ce1cee50b9f1ee7be"),
"stud_name" : "sanikaN",
"dept" : "comp",
"addr" : "pune",
"class" : "se"
"_id" : ObjectId("540f0f26e1cee50b9f1ee7bf"),
"stud_name" : "sanikaM",
"dept" : "mech",
"addr" : "delhi",
"class" : "be"
"_id" : ObjectId("540f0f44e1cee50b9f1ee7c0"),
"stud_name" : "sheenam",
"dept" : "entc",
"addr" : "mumbai",
"class" : "fe"
}
{
"_id" : ObjectId("540f0fa1e1cee50b9f1ee7c1"),
"stud_name" : "ridhima",
"dept" : "it",
"addr" : "pune",
"class" : "se"
"_id" : ObjectId("540f0fd3e1cee50b9f1ee7c2"),
"stud_name" : "rachna",
"dept" : "mech",
"addr" : "bangalore",
"class" : "te"
> db.sinfo.update({stud_name:'utkarsha'},{"$set":{marks:'90'}})
> db.sinfo.update({stud_name:'surabhi'},{"$set":{marks:'95'}})
> db.sinfo.update({stud_name:'sanikaN'},{"$set":{marks:'80'}})
> db.sinfo.update({stud_name:'sanikaM'},{"$set":{marks:'85'}})
> db.sinfo.update({stud_name:'sheenam'},{"$set":{marks:'50'}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.sinfo.update({stud_name:'ridhima'},{"$set":{marks:'45'}})
> db.sinfo.update({stud_name:'rachna'},{"$set":{marks:'75'}})
> db.sinfo.find().pretty()
"_id" : ObjectId("540f0eb1e1cee50b9f1ee7bc"),
"stud_name" : "utkarsha",
"dept" : "comp",
"addr" : "chandigarh",
"class" : "te",
"marks" : "90"
"_id" : ObjectId("540f0ee1e1cee50b9f1ee7bd"),
"stud_name" : "surabhi",
"dept" : "it",
"addr" : "mumbai",
"class" : "fe",
"marks" : "95"
{"
_id" : ObjectId("540f0f0ce1cee50b9f1ee7be"),
"stud_name" : "sanikaN",
"dept" : "comp",
"addr" : "pune",
"class" : "se",
"marks" : "80"
"_id" : ObjectId("540f0f26e1cee50b9f1ee7bf"),
"stud_name" : "sanikaM",
"dept" : "mech",
"addr" : "delhi",
"class" : "be",
"marks" : "85"
"_id" : ObjectId("540f0f44e1cee50b9f1ee7c0"),
"stud_name" : "sheenam",
"dept" : "entc",
"addr" : "mumbai",
"class" : "fe",
"marks" : "50"
}
{
"_id" : ObjectId("540f0fa1e1cee50b9f1ee7c1"),
"stud_name" : "ridhima",
"dept" : "it",
"addr" : "pune",
"class" : "se",
"marks" : "45"
"_id" : ObjectId("540f0fd3e1cee50b9f1ee7c2"),
"stud_name" : "rachna",
"dept" : "mech",
"addr" : "bangalore",
"class" : "te",
"marks" : "75"
} ---------------------------------------------------------------------------------
1) > db.sinfo.find({stud_name:'sheenam'}).explain()
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 7,
"nscanned" : 7,
"nscannedObjectsAllPlans" : 7,
"nscannedAllPlans" : 7,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"server" : "localhost.localdomain:27017",
"filterSet" : false
} ````````````````````````````````````````````````````````````````
2) > db.sinfo.ensureIndex({stud_name:1})
{ "createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
} `````````````````````````````````````````````````````````````````
3) > db.sinfo.find({stud_name:'sheenam'}).explain()
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 1,
"nscannedAllPlans" : 1,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"server" : "localhost.localdomain:27017",
"filterSet" : false
} > ````````````````````````````````````````````````````````````````````
4) > db.sinfo.ensureIndex({dept:1})
{ "createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
} `````````````````````````````````````````````````````````````````````
sinfo system.indexes
> db.system.indexes.find()
{ "v" : 1,
"key" : { "stud_name" : 1 },
"name" : "stud_name_1",
> ``````````````````````````````````````````````````````````````````````````
6) > db.sinfo.dropIndex({dept:1})
> db.system.indexes.find()
} > ``````````````````````````````````````````````````````````````````````````
7) > db.sinfo.find({},{stud_name:1,marks:1})
{ "_id" : ObjectId("540f0eb1e1cee50b9f1ee7bc"),
"stud_name" : "utkarsha",
"marks" : "90"
"_id" : ObjectId("540f0ee1e1cee50b9f1ee7bd"),
"stud_name" : "surabhi",
"marks" : "95"
{
"_id" : ObjectId("540f0f0ce1cee50b9f1ee7be"),
"stud_name" : "sanikaN",
"marks" : "80"
"_id" : ObjectId("540f0f26e1cee50b9f1ee7bf"),
"stud_name" : "sanikaM",
"marks" : "85"
"_id" : ObjectId("540f0f44e1cee50b9f1ee7c0"),
"stud_name" : "sheenam",
"marks" : "50"
"_id" : ObjectId("540f0fa1e1cee50b9f1ee7c1"),
"stud_name" : "ridhima",
"marks" : "45"
"_id" : ObjectId("540f0fd3e1cee50b9f1ee7c2"),
"stud_name" : "rachna",
"marks" : "75"
} > ``````````````````````````````````````````````````````````````````````````
8) > db.sinfo.find().sort({stud_name:1})
{ "_id" : ObjectId("540f0fd3e1cee50b9f1ee7c2"),
"stud_name" : "rachna",
"dept" : "mech",
"addr" : "bangalore",
"class" : "te",
"marks" : "75"
"_id" : ObjectId("540f0fa1e1cee50b9f1ee7c1"),
"stud_name" : "ridhima",
"dept" : "it",
"addr" : "pune",
"class" : "se",
"marks" : "45"
"_id" : ObjectId("540f0f26e1cee50b9f1ee7bf"),
"stud_name" : "sanikaM",
"dept" : "mech",
"addr" : "delhi",
"class" : "be",
"marks" : "85"
"_id" : ObjectId("540f0f0ce1cee50b9f1ee7be"),
"stud_name" : "sanikaN",
"dept" : "comp",
"addr" : "pune",
"class" : "se",
"marks" : "80"
"_id" : ObjectId("540f0f44e1cee50b9f1ee7c0"),
"stud_name" : "sheenam",
"dept" : "entc",
"addr" : "mumbai",
"class" : "fe",
"marks" : "50"
"_id" : ObjectId("540f0ee1e1cee50b9f1ee7bd"),
"stud_name" : "surabhi",
"dept" : "it",
"addr" : "mumbai",
"class" : "fe",
"marks" : "95"
"_id" : ObjectId("540f0eb1e1cee50b9f1ee7bc"),
"stud_name" : "utkarsha",
"dept" : "comp",
"addr" : "chandigarh",
"class" : "te",
"marks" : "90"
} `````````````````````````````````````````````````````````````````````````
9) > db.sinfo.find().sort({class:1,stud_name:1})
{ "_id" : ObjectId("540f0f26e1cee50b9f1ee7bf"),
"stud_name" : "sanikaM",
"dept" : "mech",
"addr" : "delhi",
"class" : "be",
"marks" : "85"
"_id" : ObjectId("540f0f44e1cee50b9f1ee7c0"),
"stud_name" : "sheenam",
"dept" : "entc",
"addr" : "mumbai",
"class" : "fe",
"marks" : "50"
"_id" : ObjectId("540f0ee1e1cee50b9f1ee7bd"),
"stud_name" : "surabhi",
"dept" : "it",
"addr" : "mumbai",
"class" : "fe",
"marks" : "95"
"_id" : ObjectId("540f0fa1e1cee50b9f1ee7c1"),
"stud_name" : "ridhima",
"dept" : "it",
"addr" : "pune",
"class" : "se",
"marks" : "45"
"_id" : ObjectId("540f0f0ce1cee50b9f1ee7be"),
"stud_name" : "sanikaN",
"dept" : "comp",
"addr" : "pune",
"class" : "se",
"marks" : "80"
"_id" : ObjectId("540f0fd3e1cee50b9f1ee7c2"),
"stud_name" : "rachna",
"dept" : "mech",
"addr" : "bangalore",
"class" : "te",
"marks" : "75"
"_id" : ObjectId("540f0eb1e1cee50b9f1ee7bc"),
"stud_name" : "utkarsha",
"dept" : "comp",
"addr" : "chandigarh",
"class" : "te",
"marks" : "90"
} > ``````````````````````````````````````````````````````````````````````````````
{ "_id" : ObjectId("540f0f44e1cee50b9f1ee7c0"),
"stud_name" : "sheenam",
"dept" : "entc",
"addr" : "mumbai",
"class" : "fe",
"marks" : "50"
"_id" : ObjectId("540f0fa1e1cee50b9f1ee7c1"),
"stud_name" : "ridhima",
"dept" : "it",
"addr" : "pune",
"class" : "se",
"marks" : "45"
} > ````````````````````````````````````````````````````````````
WriteResult({ "nInserted" : 1 })
> db.sinfo.find({addr:'mumbai',class:'fe',dept:'comp'}).pretty()
"_id" : ObjectId("54101208b5f4773d09ee91af"),
"stud_name" : "bhargavi",
"dept" : "comp",
"addr" : "mumbai",
"class" : "fe",
"marks" : "70"
} > ```````````````````````````````````````````````````````````````````
EXPERIMENT 12
OBJECTIVE : To study and implement Map reduces operation with suitable example using
MongoDB.
PROBLEM STATEMENT: Implement Map reduces operation with suitable example using
MongoDB.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mongo DB
OUTCOME : After completion of assignment student are able to implement Map reduces
operation with suitable example using MongoDB.
THEORY :
Map-reduce :-
As per the Mongodb documentation. Map reduce is data processing paradigm for condensing
large volume of data into useful aggregated result Mongodb user Map-reduce is command for
map-reduce option. Map-reduce in generally used for processing large data sets.
Map-Reduce command:-
db.collection.mapreduce{
out:collection;
qyery:document;
sort:document;
limit:number;
the map-reduce function first queries the collection then map the result document to emit key-
value pair which is then reduced based on the keys that have multiple value.in above syntax
• map-reduce in javascript function , that maps a value with a key & limit a key value pair
• reduce is a javascript function that reduces or graphs all the document having same key.
USE Map-Reduce :-
Consider the following document structure sorting user postd the document stores user_name of
the user & status of post
”post_txt”:”tutorialsponit is an awsome
”user_name”:”mark”;
“status”:”active”;
new we will use mapreduce function on our post collection to select all the active post group
them an the basis of user_name & then count the number of post by each user using following
code
db.collection.mapreduce{
function(){exit(this user_id);}
function(key,values){return array.sun(values)};
out :”post_total”;
{”result”:”post_total”,
”time millis”:9,
”count”:{
”input”:4;
”emit”:4;
”reduce”:2;
”output”:2;
”ok” :1
The query map function emitted 4 documents with key value pair & finally reduce function
group mapped document having same key into2.
STEPS:
write on terminal1:
1. cd mongodb-linux-x86-64-2.6.1
2. cd bin
write on terminal 2:
1. cd mongodb-linux-x86-64-2.6.1
2. cd bin
3. ./mongo
EXECUTION STEPS:
> use bank
switched to db bank
> db.cust.insert({cust_id:1,amt:1000})
WriteResult({ "nInserted" : 1 })
> db.cust.insert({cust_id:2,amt:4000})
WriteResult({ "nInserted" : 1 })
> db.cust.insert({cust_id:3,amt:4000})
WriteResult({ "nInserted" : 1 })
> db.cust.insert({cust_id:4,amt:8000})
WriteResult({ "nInserted" : 1 })
> db.cust.insert({cust_id:2,amt:2000})
WriteResult({ "nInserted" : 1 })
> db.cust.insert({cust_id:6,amt:6000})
WriteResult({ "nInserted" : 1 })
> db.cust.mapReduce(mapfn,redfn,{'out':'result'})
{ "_id" : 2, "value" : 6000 } { "_id" : 3, "value" : 4000 } { "_id" : 4, "value" : 8000 } { "_id" : 6,
"value" : 6000 }
> ``````````````````````````````````````````````````````````````
switched to db custom
> db.order.insert({cust_id:1,item:'keyboard',quantity:20})
WriteResult({ "nInserted" : 1 })
> db.order.insert({cust_id:2,item:'cpu',quantity:10})
WriteResult({ "nInserted" : 1 })
> db.order.insert({cust_id:3,item:'monitor',quantity:50})
WriteResult({ "nInserted" : 1 })
> db.order.insert({cust_id:4,item:'keyboard',quantity:50})
WriteResult({ "nInserted" : 1 })
> db.order.insert({cust_id:5,item:'cpu',quantity:60})
WriteResult({ "nInserted" : 1 })
> db.order.insert({cust_id:6,item:'keyboard',quantity:70})
WriteResult({ "nInserted" : 1 })
> var mapfunction=function(){emit(this.item,this.quantity)};
> db.order.mapReduce(mapfunction,reducefunction,{'out':'result'})
EXPERIMENT 13
OBJECTIVE : To study and implement MYSQL database connectivity with Java Implement
Database navigation operations (add, delete, edit,) using JDBC.
HARDWARE REQUIREMENT :
SOFTWARE REQUIREMENT :
Operating System- Ubuntu 16.04
Database- Mysql
IDE : Eclipse
OUTCOME : After completing assignment student are able to implement MYSQL database
connectivity with JSP and database navigation operations (add, delete, edit,) using JDBC.
THEORY :
JDBC
JDBC ARCHITECTURE:
EXECUTION STEPS :
//package mg;
import java.io.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
static final String USER = "student"; //you can assign your user name who havin remote login
permissions
try
{
//STEP 2: Register JDBC driver Class.forName("com.mysql.jdbc.Driver");
do
System.out.println("5:Update table");
System.out.println("9:Close database");
ch=Integer.parseInt(bufr.readLine());
switch(ch)
case 1:
String sql = "CREATE TABLE employee " + "(id INTEGER primary key, " + "name
varchar(15),"+ " dept VARCHAR(255),"+ "sal int);";
stmt.executeUpdate(sql);
break;
// preparedStatements can use variables and are more efficient // "name, class from
jdbc.student");
id=Integer.parseInt(bufr.readLine());
name=bufr.readLine();
dept=bufr.readLine();
sal=Integer.parseInt(bufr.readLine());
preparedStatement.setInt(1, id);
preparedStatement.setString(2,name);
preparedStatement.setString(3, dept);
preparedStatement.setInt(4, sal);
preparedStatement.executeUpdate();
break;
case 3:
System.out.println("Creating statement...");
String sql1;
rs = stmt.executeQuery(sql1);
while (rs.next())
// which starts at 1
// e.g., resultSet.getSTring(2);
id = rs.getInt("id");
name = rs.getString("name");
dept = rs.getString("dept");
sal = rs.getInt("sal");
}
break;
case 4:
id=Integer.parseInt(bufr.readLine());
preparedStatement.setInt(1, id);
preparedStatement.executeUpdate();
break;
case 5:
id=Integer.parseInt(bufr.readLine());
sal=Integer.parseInt(bufr.readLine());
preparedStatement.setInt(2, id);
preparedStatement.setInt(1, sal);
preparedStatement.executeUpdate();
break;
case 6:
System.out.println("Creating statement...");
rs.last();
name = rs.getString("name");
dept = rs.getString("dept");
sal = rs.getInt("sal");
//Display values
rs.first();
name = rs.getString("name");
dept = rs.getString("dept");
sal = rs.getInt("sal");
//Display values
case 7:
System.out.println("Creating statement...");
rs.first();
temp=Integer.parseInt(bufr.readLine());
while (rs.next())
// which starts at 1
// e.g., resultSet.getString(2);
if(rs.getInt("id")==temp)
id = rs.getInt("id");
name = rs.getString("name");
dept = rs.getString("dept");
sal = rs.getInt("sal");
System.out.println("Id: " + id);
break;
case 8:
System.out.println("Creating statement...");
rs.first();
temp=Integer.parseInt(bufr.readLine());
while (rs.next())
// which starts at 1
// e.g., resultSet.getString(2);
if(rs.getInt("id")==temp)
id = rs.getInt("id");
name = rs.getString("name");
dept = rs.getString("dept");
job = rs.getString("job");
break;
case 9:
//Clean-up environment
rs.close();
stmt.close();
conn.close();
break;
ans=Integer.parseInt(bufr.readLine());
}while(ans==1);
} catch(Exception e)
//[can figure out which class, method and line caused the exception]
e.printStackTrace();
}//end JDBCExample
OUTPUT:
1:Create Table
2: Insert in table
3: Display Table
5:Update table
9:Close database
Ente choice : 2
Ente emp id : 5
Ente emp name : bnm
1:Create Table
2: Insert in table
3: Display Table
5:Update table
9:Close database
Ente choice : 3
Creating statement...
Id: 1
Name: abc
Class: comp
Marks: 20000
Id: 2
Name: xyz
Class: entc
Marks: 30000
Id: 5
Name: bnm
Class: mech
Marks: 50000
1:Create Table
2: Insert in table
3: Display Table
5:Update table
9:Close database
Ente choice : 5
1:Create Table
2: Insert in table
3: Display Table
5:Update table
6: Display first and last
9:Close database
Ente choice : 3
Creating statement...
Id: 1
Name: abc
Class: comp
Marks: 35000
Id: 2
Name: xyz
Class: entc
Marks: 30000
Id: 5
Name: bnm
Class: mech
Marks: 50000
1:Create Table
2: Insert in table
3: Display Table
9:Close database
Ente choice : 6
Creating statement...
Displaying record...
ID: 5,
Name: bnm,
dept: mech,
Salary: 50000
Displaying record...
ID: 1,
Name: abc,
dept: comp,
salary: 35000
Creating statement...
Id: 2
Name: xyz
Class: entc
Marks: 30000
1:Create Table
2: Insert in table
3: Display Table
5:Update table
9:Close database
Ente choice : 7
Creating statement...
Id: 5
Name: bnm
Class: mech
Marks: 50000
1:Create Table
2: Insert in table
3: Display Table
5:Update table
9:Close database
Ente choice : 8
Creating statement...
Id: 1
Name: abc
dept: comp
Job :prg
1:Create Table
2: Insert in table
3: Display Table
5:Update table
9:Close database
Ente choice : 9
Goodbye!
CONCLUSION :