You are on page 1of 48

DATABASE MANAGEMENT &

INTERNET APPLICATION
(03110257)

Laboratory Manual

KUNTAL SHUKLA

Bachelor of Technology
(AGRICULTURAL)
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

DATABASE MANAGEMENT &


INTERNET APPLICATION
(03110257)
JAN-2017
REV 1.0

Asst. Prof. KUNTAL SHUKLA


M.E., EC department
PIT

Agricultural Engineering Department


Parul Institute of Technology
Faculty of Engineering & Technology
Parul University, Limda,
Ph:02668-260345, www.parul.ac.in

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 2
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 3
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

PREFACE
It gives us immense pleasure to present the first edition of
Database Management & Internet Application Laboratory
Practical Book for the B.Tech.-2 nd year students of PARUL
UNIVERSITY.

The Database Management & Internet Application theory and


laboratory courses at PARUL UNIVERSITY, WAGHODIA,
VADODARA are designed in such a way that students develop
the basic understanding of the subject in the theory classes and
then try their hands on using software, the experiments to
realize the various Database Management & Internet
Application concept of the theoretical sessions. The main
objective of the Database Management & Internet Application
laboratory course is: Learning Database queries & HTML coding
through experimentations.

The objective of this Database Management & Internet


Application Laboratory Practical Book is to provide a
comprehensive source for all the experiments included in the
laboratory course. It explains all the aspects related to queries
and programming such as: Understanding of different types of
SQL queries & HTML programming concept. It also gives
sufficient information on creation of webpages.

We acknowledge the authors and publishers of all the books


which we have consulted while developing this laboratory
Practical book. Hopefully this Database Management & Internet
Application Laboratory Practical Book will serve the purpose for
which it has been developed.

KUNTAL SHUKLA
DATABASE MANAGEMENT & INTERNET APPLICATION
Page 4
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 5
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Table of Contents
EXPERIMENT NO. 1.........................................................................................................7
AIM: Basic Database Concepts.................................................................7
EXPERIMENT NO. 2.......................................................................................................14
AIM: Introduction to RDBMS...................................................................14
EXPERIMENT NO. 3.......................................................................................................20
AIM: S Q L C o m m a n d s D D L , D M L .....................................................20
EXPERIMENT NO. 4.......................................................................................................26
AIM: Select Command, Joins and functions. .
..26
EXPERIMENT NO. 5.......................................................................................................31
AIM: Group functions, set functions........................................................31
EXPERIMENT NO. 6.......................................................................................................35
AIM: Working with Forms........................................................................35
EXPERIMENT NO. 7.......................................................................................................37
AIM: Basic of HTML ................................................................................37
EXPERIMENT NO. 8.......................................................................................................39
AIM: Development of Web pages using Mata tags.................................39
EXPERIMENT NO. 9.......................................................................................................41
AIM: Dynamic pages using Java Scripts..................................................41
EXPERIMENT NO. 10....................................................................................................42
AIM: Connectivity of Web pages with databases....................................42

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 6
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT NO. 1
AIM: To study Basic Database Concepts.
DATABASE--- An organized collection of related information.)

DEFINATION

DATABASE MANAGMENT SYSTEM is a collection of interrelated data


and a set of programs to access those data.

PRIMARY GOAL OF DBMS

Is to provide way to store and retrieve database information that is


both convenient and efficient.

DBMS designed to manage large bodies of information.

The database system must ensure the safety of the information stored .

DATABASE SYTEM APPLICATION

Banking: all transactions


Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Online retailers: order tracking, customized recommendations
Manufacturing: production, inventory, orders, supply chain
Human resources: employee records, salaries, tax deductions

BASIC CONCEPT AND DEFINATION DATA

DATA is a raw fact, anything can be data.


It is not be meaningful.
It is used analysis and reasoning.
It is input processing unit.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 7
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Data is basic row material which taken by certain observation,


certain experiment and storing in paper, stored memory, human
mind.
Ex:- marks of student ,account information.

INFORMATION
This is a processed from of data.
It is always meaningful.
Meaningful data is called information.
It is output processing units.
When ever we organize the data and process is done on it then we
get proper information.
Example :-
NO. BRANCH STUDENT
1 CE 60
2 EC 50

Here their data of student branch and no of student study in


student.

METADATA

The data structure of database is specifying by database schema


and it called metadata.

Data that describe the properties or characteristics of other data

Properties include data definitions, data structures, and rules or


constraints.

Metadata describe data but not include that data

DATA ITEMS ( FIELDS, ATTRIBUTES, COLUMNS )

The characteristics of an entity are called fields or attributes or


columns.

Entity can have a number of characteristics like name, address,


phone no. etc.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 8
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Entity is a group of similar information or data.

RECORD (ROW, TUPLE)

Multiple fields placed in a horizontal plane are called a record or


row or TUPLE.

An organization will deal with many clients and the same


information must be recorded for each client multiple fields placed
in a horizontal plane is called a record or row or TUPLE.

Files

Which store the database itself?

DATA DICTIONARY (DATA DIRECTORY)

Data dictionary, which stores metadata about the structure of


database, in particular the schema of the database.
The data dictionary is a file that contains metadata that is data
about data.
The data structure of database is specifying by database schema
and it called metadata.
The file which contains that metadata is called DATA DICTIONARY
(DIRECTORY).
This file is consulted before actual data are read or modified in the
database system.
Example: - In ORACLE special tables tab is contain the information
about all tables, called table of table. It gives all the name of table
in the database so tab contains data about data. And it may refer
as data dictionary.
We have considered only the representation of the relations
themselves

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 9
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

A DBMS needs to maintain data about the relations such as the


schema of the relations. This information is called the data-
dictionary or system catalog.
The types of information that the system must store are these
Name of the relations
Name of the attributes of each relation
Domain and lengths of attributes
Integrity constraints (for ex :- key constraints)
Data dictionaries can also classified as Active or Passive
Active data dictionary is automatically updated by the DBMS with
every database access, thereby keeping its access information up to
date.
Passive data dictionary is not updated automatically and usually
requires running a batch process
Data dictionary access information is normally used by the DBMS for
query optimization purposes.

Database
A database is a collection of persistent data that is used by application
systems of some given enterprise.
Persistent means the data is not transient in nature like input and
output data.
In short database is collection of data.
Database can be define by meaningful data
An organized collection of logically related data.

Database system
Database system is basically computerized record keeping system,
whose overall purpose is to maintain information and to make that
information available on demand Four components of database system.
Data
Hardware
Software

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 10
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

User

Data
Database system is available on small systems as well as large
systems. Small systems are single user system on which at most
one user can access the data at any given time. Large systems
are usually multi-user systems on which multiple users can
access the data concurrently. Data in the database of multi-user
system must be integrated and shared.
Integrated - The data files available in the database system must
have redundancy among them wholly or partially removed so
that they are same at all the location.
Shared - The individual piece of data in the database can be
shared among several different users.

Hardware
The hardware system consist of : Secondary storage volumes -
typically moving - head magnetic disks - that are used to hold
data, together with the associated I/O devices.
Processor and main memory they support the execution of
database system software.

Software
Software is a collection of a program.
It is the layer between the physical database itself and the users
called database manager or more usually database management
system. It shields the users of database from hardware level
details.

Users

There are the four different types of database-system users,


different by the way that they expect to interact with the system.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 11
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Application programmers
Sophisticated users
Specialized users
Nave users

Application programmers : responsible for writing database application


programs in some programming language such as COBOL,PL/I,C++,JAVA
OR some higher-level fourth generation language. The resulting program
is then run through the host language compiler, which generates
appropriate object code.

Sophisticated users: they interact with the system without writing


programs. They form their request in the database query processor whose
function is to break down DML statement into instruction that the storage
manager understands.

Specialized users: They are sophisticated users who write specialize


database application that do not fit into the traditional data-processing
framework.

Nave users: They are unsophisticated users who interact with the
system by invoking one of the permanent application programs that have
been written previously.
Operations performed on database systems.

Create Add new data to the database.


Read Read current database data (often presented in a useful
format on a Computer screen or a printed report).
Update Update (or modify) current database data.
Delete Delete current data from the database.

Database administrator

One of the main reasons for using DBMS is to have central control of
both of data and programs that access those data.
DATABASE MANAGEMENT & INTERNET APPLICATION
Page 12
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

A person who has such central control over the system is called
database administrator.
The functions of DBA include:
Schema definition: The DBA creates the original database
schema by executing a set of data definition statements in DDL
(data-definition language).

Storage structure and access-method definition.

Schema and physical-organization modification: The DBA


carries out changes to the schema and physical organization to
reflect the changing needs of the organization, or physical
organization improve performance.

Granting of authorization for data access: Granting different


types of authorization, the database administrator can regulate
which parts of the database various users can access. The
authorization information is kept in a special system structure
that the database system consults whenever someone attempts
to access the data in the system.

Routine maintenance : example of the database


administrators routine maintenance activities are:
Periodically backing up the database, either onto tapes or not
remote servers, to prevent loss of data in case of disasters as
flooding.
Ensuring that enough free disk space is available for normal
operations, and upgrading disk space required.
Monitoring jobs running on the database and ensuring that
performance is not degraded by very expensive tasks
submitted by some users.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 13
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

REVIEW QUESTION
1) EXPLAIN DATA, INFORMATION, METADATA, SYSTEM CATLOG.
2) DIFFERENCES BETWEEN DATA VS INFORMATION.
3) DIFFERENCES BETWEEN FILE ORIENTED SYSTEM VS DATABASE
SYSTEM.
4) EXPLAIN DATA ADMINISTRATOR.
5) EXPLAIN DATABASE ADMINISTRATOR.
6) EXPLAIN DATA DICTIONARY.
7) ADVANTAGE AND DISADVANTAGE OF DBMS.
8) ADVANTAGE AND DISADVANTAGE OF FILE-ORIENTED SYSTEM.
9) EXPLAIN DATA APPROACH.
10) EXPLAIN DATA BASE.
11) EXPLAIN DATA BASE SYSTEM

EXPERIMENT NO. 2
AIM: Introduction to RDBMS.

Introduction

Relational databases are the most widely used databases in


commercial applications like as banking system, railway-
reservation system, etc.
Relational databases are based on the relational model.

Structure of Relational Databases

Domain:

A domain of an attribute is a set of permitted values for that


attribute

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 14
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

For example, if the bank is organized in three branches,


named 'vvn', 'ksad' and 'anand', then, the domain of
attribute bname is {'vvn', 'ksad', 'anand'}.
A value for a branch name must be one of these three
values in any relation.

Similarly, a domain for column an in Account table is a set


of strings starting from 'A followed by unique numerical
value, such as {A01, A02, A03, A04, A05}.
A domain is atomic if elements of domain are considered to be
indivisible units.
For example, a domain for bname is an atomic domain.
A domain for some attribute, say address may not be atomic,
as address can be divided into sub-parts such as society, city,
and pin code.
A domain of an attribute should be atomic
An atomic domain is preferable rather than a non-atomic
domain.

Keys of Relations

Tuples in a relational model represents individual entities or


relationships.
Tuples are distinguished based on data values stored
No any two tuples in a relation should have exactly the same
values for all attributes.
There cannot be two identical tuples in a relation.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 15
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Several keys have been defined, as illustrated below.


Super Key
Relation Key
Candidate Key
Primary Key
Alternate Key
Foreign Key

Super Key
"A super key is a set of one or more attributes that allows to
identify each tuple
uniquely in a relation."
For example, consider a relation Customer with attributes
cid, cname, address,
and contact_no.
In this relation, each tuple represents an individual customer.
Here, the cid attribute can distinguish each tuple from
another. So, cid is a super key for Customer relation.
Relation Key
"A super key for which no subset is a super key is
called a relation key."

In other words, relation key is a minimal super key.

A relation key is also referred as 'key' only.

A relation key is sufficient to identify each and every


tuple uniquely within a
relation.

A relation key cannot have null or duplicate values, as


well as it does not contain any redundant attribute.

There can be more than one relation keys for the same
relation. For example, for Customer relation, {cid} as
well as {cname, address} are relation keys.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 16
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Candidate Key
"If a relation contains more than one relation keys, then,
they each are called candidate key."

For example, for Customer relation, {cid} as well as


{cname, address} are relation keys. And so, they each are
called candidate keys.

Primary Key
"A primary key is a candidate key that is chosen by the
database designer to identify tuples uniquely in a
relation."

For example, if database designers choose candidate


key cid to identify all customers uniquely, then, cid is a
primary key of the relation Customer.

Alternate Key
"An alternate key is a candidate key that is not chosen by
the database designer to identify tuples uniquely in a
relation."

For example, if database designers choose candidate key cid


to identify all customers uniquely, then, another candidate
key {cname, address} is an alternate key.

Foreign Key

"A foreign key is a set of one or more attributes whose


values are derived from the key attribute of another
relation."

RELATIONAL ALGEBRA

Relational algebra is a collection of formal operations acting on


relations and producing relations as results.
DATABASE MANAGEMENT & INTERNET APPLICATION
Page 17
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Six basic operators

select:

project:

union:

set difference:

Cartesian product: x

Rename:

The operators take one or two relations as inputs and produce a


new relation as a result.

Relational algebra is a Procedural language.

The Select Operation:

Operation : Selects tuples from a relation that satisfy a


given condition

Symbol: (Sigma)

Notation: p(r)

p is called the selection predicate

Operators: The following operators can be used to form a


condition.

=, ?, <, =, >, =, A (AND), V (OR) Find out all

Example: Find out all accounts which belong to branch


named "vvn".

The following query returns all tuples which contains "vvn" as a


branch name
(Account)
bname = vvn '

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 18
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

The resultant relation is given in following figure


3.6.

The Project Operation

Operation : Selects specified attributes of a relation.

Symbol : (pi)

Notation : (attribute list) <Relation>

Duplicate rows removed from result, since relations are sets

The projection of R, denoted by R is the set of specified


A, B,...

attributes A, B, ... of the relation R, i.e. a vertical subset of R.

EXAMPLE STUDENT#,EXAM ASSESSMENTS is


OUTPUT:-

STUDEN EX
T# A
M
A101 60
A101 50
J326 70

Example-3 : List out all account numbers having balance less


than 7000.

(an) (balance < 7000 (Account))

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 19
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Figure: All account numbers having balance < 7000.

EXPERIMENT NO. 3
AIM: SQL Commands DDL, DML

a. Create
b. Insert.
DATABASE MANAGEMENT & INTERNET APPLICATION
Page 20
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

c. Select
d. Delete
e. Update
f. Drop
g. Truncate

a. Create
mysql> create database my_database;

Query OK, 1 row affected (0.05 sec)

mysql> use my_database;

Database changed

mysql> create table BE_academic(sem_no int


auto_increment,spi int not null,cpi i

nt not null,primary key(sem_no));

Query OK, 0 rows affected (0.20 sec)

mysql> select * from BE_academic;

Empty set (0.00 sec)

mysql> insert into BE_academic values(1,6.30,0);

Query OK, 1 row affected (0.05 sec)

my sql> select * from BE_academic;

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

| sem_no | spi | cpi |

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

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 21
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

| 1| 6| 0|

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

1 row in set (0.00 sec)

mysql> alter table BE_academic modify spi real not null;

Query OK, 1 row affected (0.27 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> update BE_academic set spi = 6.3;

Query OK, 1 row affected (0.02 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from BE_academic;

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

| sem_no | spi | cpi |

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

| 1 | 6.3 | 0|

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

1 row in set (0.00 sec)

mysql> alter table BE_academic drop column cpi;

Query OK, 0 rows affected (0.25 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from BE_academic;

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

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 22
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

| sem_no | spi |

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

| 1 | 6.3 |

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

1 row in set (0.00 sec)

INSERT
mysql> insert into BE_academic values(2,6.30);

Query OK, 1 row affected (0.00 sec)

mysql> insert into BE_academic values(3,7.2);

Query OK, 1 row affected (0.00 sec)

mysql> insert into BE_academic values(4,8.5);

Query OK, 1 row affected (0.00 sec)

mysql> insert into BE_academic values(5,8.9);

Query OK, 1 row affected (0.00 sec)

mysql> insert into BE_academic values(6,9.0);

Query OK, 1 row affected (0.02 sec)

mysql> insert into BE_academic values(7,9.3);

Query OK, 1 row affected (0.02 sec)

mysql> insert into BE_academic values(8,9.9);

Query OK, 1 row affected (0.00 sec)

mysql> select * from BE_academic;

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 23
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

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

| sem_no | spi |

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

| 1 | 6.3 |

| 2 | 6.3 |

| 3 | 7.2 |

| 4 | 8.5 |

| 5 | 8.9 |

| 6| 9|

| 7 | 9.3 |

| 8 | 9.9 |

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

8 rows in set (0.00 sec)

DELETE
mysql> delete from BE_academic where spi = 9;

Query OK, 1 row affected (0.06 sec)

mysql> select * from BE_academic;

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

| sem_no | spi |

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

| 1 | 6.3 |

| 2 | 6.3 |

| 3 | 7.2 |

| 4 | 8.5 |

| 5 | 8.9 |

| 7 | 9.3 |

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 24
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

| 8 | 9.9 |

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

7 rows in set (0.00 sec)

mysql> insert into BE_academic values(6,9.1);

Query OK, 1 row affected (0.01 sec)

mysql> select * from BE_academic;

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

| sem_no | spi |

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

| 1 | 6.3 |

| 2 | 6.3 |

| 3 | 7.2 |

| 4 | 8.5 |

| 5 | 8.9 |

| 6 | 9.1 |

| 7 | 9.3 |

| 8 | 9.9 |

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

8 rows in set (0.00 sec)

TRUNCATE
mysql> truncate BE_academic;

Query OK, 0 rows affected (0.14 sec)

mysql> select * from BE_academic;

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 25
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Empty set (0.00 sec)

mysql> drop table BE_academic;

Query OK, 0 rows affected (0.08 sec)

mysql> select * from BE_academic;

ERROR 1146 (42S02): Table 'my_database.be_academic'


doesn't exist

mysql> show tables;

Empty set (0.00 sec)

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 26
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT - 4

AIM: Select Command, Joins and functions.

PROGRAM:
Equi Join :
A join based on an exact match between two columns is called an
Equi Join
The comparison operator in the join condition is =
Example:

Table Name: emp

Ename Eid Sal Deptno


Rahul E01 1000 10
Vishal E02 1500 15
Ajit E03 2000 20

Table Name: dept

Deptno Deptname Location


10 Sales Mumbai
15 Accounts Chennai
20 Purchase Mumbai

SQL> select ename,eid,location from emp,dept


where emp.deptno=dept.deptno;

The above join query will retrieve the name, id and location of all
employees
Output:
Ename Eid Location
Rahul E01 Mumbai
Vishal E02 Chennai
Ajit E03 Mumbai

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 27
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Non-Equi Join :
Joins which use comparison operators other than = are called
Non-Equi joins.
Example:

Table Name: emp

Ename Eid Sal Deptno


Rahul E01 1000 10
Vishal E02 1500 15
Ajit E03 2000 20

Table Name: dept

Deptno Deptname Location


10 Sales Mumbai
15 Accounts Chennai
20 Purchase Mumbai

Select ename, location from emp, dept


Where sal BETWEEN(operator other than =) 1000
AND 2000;
The above join query will retrieve the name, and location of
employees having salary between 1000 and 2000
Output:
Ename Location
Vishal Chennai

Self Join :
A join that joins one row in table with another row in the same
table is called Self Join.
Using the table alias names these two identical tables can be
joined.
From <TableName> [<alias1>], <TableName> [<alias2>]
Example:
Table Name: employee

Eid Ename Manager_


no
E00001 Rahul E00002
E00002 Vishal E00005
E00003 Ajit E00004
E00004 Prem
E00005 Ronak

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 28
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

select e1.ename,e2.enamemanager_no from


employee e1,employee e2
where e1.manager_no = e2.eid;

The above query will retrieve the names of the employees and
the names of their respective manager from the employee table
Output:
Ename Manager_
no
Rahul Vishal
Vishal Ronak
Ajit Prem

Outer Join :
Outer join in three types
Left outer join
Right outer join
Full outer join

We have two table (client and salesman) with structure is show


below;
Table name: Client

Column Datatype Size


name
Name Varchar2 10
Id Varchar2 6

Table name: Salesman

Column Datatype Size


name
Id Varchar2 6
City Varchar2 8

SQL> select * from client

Name Id
------------- -----------
Rahul 10
Vishal 20

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 29
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

SQL> select * from salesman

Id City
------------- -----------
30 bombay
20 madras
40 bombay

Left outer join

SQL> select * from client


LEFT outer join salesman
on client.ID = salesman.ID ;

OUTPUT:-
NAME ID ID CITY
---------- ------ ------ --------
vishal 20 20 madras
rahul 10

Using (+) sign left join

SQL> select * from client, salesman


where
on client.ID = salesman.ID(+) ;

Right outer join

SQL> select * from client


RIGHT outer join salesman
on client.ID = salesman.ID ;

OUTPUT:-
NAME ID ID CITY
---------- ------ ------ --------
vishal 20 20 madras
30 bombay
40 bombay

Using (+) sign Right join

SQL> select * from client, salesman


Where
on client.ID (+) = salesman.ID ;

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 30
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

full outer join

SQL> select * from client


FULL outer join salesman
on client.ID = salesman.ID ;

OUTPUT:-
NAME ID ID CITY
---------- ------ ------ --------
vishal 20 20 madras
rahul 10
30 bombay
40 bombay

Using (+) sign Full join

SQL> select * from client, salesman


where
on client.ID = salesman.ID(+)
union
select * from client, salesman
Where
on client.ID (+) = salesman.ID ;

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 31
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT - 5

AIM: Group functions, Set functions

PROGRAM:
SET OPERATIONS
UNION, INTERSECT, MINUS

UNION Clause
The UNION clause merges or combines the output of two or more
queries into a single set of rows and columns
Multiple queries can be put together and their output combined
using the UNION clause.

The output of both queries will be displayed as above.


Output : Record only in query one + records only in query two +
a single set of records which is common in both queries

Example:
Table Name: client_master

Client_no Name City


C00001 Ivan bay Bombay
Ross
C00002 Vandana Madras
C00003 Pramala Bombay

Table Name: salesman_master

Salesman_ Name City


no
S00001 Kiran Bomba
DATABASE MANAGEMENT & INTERNET APPLICATION
Page 32
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

y
S00002 Manish Delhi
S00003 Ravi Bomba
y

Select salesman_no ID, name from salesman_master


Where city=bombay
UNION
Select client_no ID, name from client_master
Where city=bombay;

OUTPUT:
ID Name
C00001 Ivan bayross
C00003 Pramala
S00001 Kiran
S00003 Ravi

Restriction on UNION clause :


The number of column in all the queries should be same.
The data type of columns in each query should be same
Unions cannot be used in Sub queries
Union cannot be used with aggregate functions

INTERSECT Clause
The INTERSECT clause outputs only those rows produced by both
queries intersected.
The output of INTERSECT clause will include only those rows that
are retrieved by both the queries.

The output of both queries will be displayed as above


The final output of INTERSECT clause will be:
Output: A single set of Records which is common in both queries.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 33
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Example: Retrieve the salesman name in Bombay whose efforts


have resulted into at least one sales transaction

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 34
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Table Name: salesman_master

Sman_no name City


S00001 Kiran Bombay
S00002 Manish Delhi
S00003 Ravi Bombay

Table Name: sales_order

Order_no Order_date Sman_no


O19001 12-Apr-08 S00001
O19002 25-Dec-08 S00003
O19003 19-Oct-08 S00001
O19004 02-May-08 S00002

SQL> select sman_no, name from salesman_master where


city='bombay'
INTERSECT
select salesman_master.sman_no , name from salesman_master,
sales_order where salesman_master.sman_no=sales_order.sman_no;

Output:
Sman_no name
S00001 Kiran
S00003 Ravi

MINUS Clause
The MINUS clause outputs the rows produced by the first query,
after filtering the rows retrieved by the second query.

The output of both queries will be displayed as above


The final output of MINUS clause will be:
Output: Records only in query one

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 35
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Example: Retrieve all the product number of non-moving items


from the product_master table.

Table Name: sales_order_details

Order_no product_no
O19001 P00001
O19001 P00004
O19001 P00006
O19002 P00002
O19002 P00005
O19003 P00003
O19004 P00001
O19005 P00006
O19005 P00004
O19006 P00006

Table Name: product_master

Product_no Description
P00001 1.44 floppies
P00002 Monitors
P00003 Mouse
P00004 1.22 floppies
P00005 Keyboards
P00006 CD drive
P00007 HDD
P00008 1.44 drive
P00009 1.22 drive

Select product_no from product_master

MINUS
Select product_no from sales_order_details;

Output:
Product_no
P00007
P00008
P00009

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 36
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT NO. 6
AIM: WORKING WITH FORMS

PROGRAM:

Text Input
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>

Radio Button Input:

<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>

The Submit Button


<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>

Last name:<br>

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 37
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

<input type="text" name="lastname" value="Mouse"><br><br>


<input type="submit" value="Submit">
</form>

The Action Attribute

The action attribute defines the action to be performed when the form is
submitted.

Normally, the form data is sent to a web page on the server when the user
clicks on the submit button.

In the example above, the form data is sent to a page on the server called
"action_page.php". This page contains a server-side script that handles
the form data:

<form action="action_page.php">

If the action attribute is omitted, the action is set to the current page.

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 38
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT NO. 7
AIM: Basics of HTML

PROGRAM:
HTML Document:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

HTML Headings:

<!DOCTYPE html>
<html>
<body>

<h1>This is heading 1</h1>


<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>

</body>
</html>

HTML Paragraphs:

<!DOCTYPE html>
<html>
<body>

<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 39
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

<p>This is a paragraph.</p>

</body>
</html>

HTML Links:

<!DOCTYPE html>
<html>
<body>

<a href="http://www.w3schools.com">This is a link</a>

</body>
</html>

HTML Images

<!DOCTYPE html>
<html>
<body>

<img src="w3schools.jpg" alt="W3Schools.com" width="104"


height="142">

</body>
</html>

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 40
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT NO. 8

AIM: Development of Web pages using mata tags.

THEORY:
HTML lets you specify metadata - additional important information about a
document in a variety of ways. The META elements can be used to include
name/value pairs describing properties of the HTML document, such as
author, expiry date, a list of keywords, document author etc.

The <meta> tag is used to provide such additional information. This tag
is an empty element and so does not have a closing tag but it carries
information within its attributes.

PROGRAM:
Adding HTML meta tag, metadata as an important keyword

<!DOCTYPE htm l>


<htm l>
<head>
<title>Meta Tags Exam ple</title>
<m eta nam e="keywords" content="HTML, Meta Tags, Metadata" />
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>

Use of <meta> tag to give a short description about the


document

<!DOCTYPE htm l>


<htm l>
<head>
<title>Meta Tags Exam ple</title>
<m eta nam e="keywords" content="HTML, Meta Tags, Metadata" />
<m eta nam e="description" content="Learning about Meta Tags." />
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 41
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Use of <meta> tag to give information about when last time the
document was updated

<!DOCTYPE htm l>


<htm l>
<head>
<title>Meta Tags Exam ple</title>
<m eta nam e="keywords" content="HTML, Meta Tags, Metadata" />
<m eta nam e="description" content="Learning about Meta Tags." />
<m eta nam e="revised" content="Tutorialspoint, 3/7/2014" />
</head>
<body>
<p>Hello HTML5!</p>
</body>
</html>

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 42
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

EXPERIMENT NO. 9
AIM: Dynamic pages using Java Scripts

PROGRAM:

Create a Web page that customized itself by asking the user their name and then
incorporating that name within the text of the page.

<html>
<!-- Dave Reed greet.html 1/20/02 -->
<!-- -->
<!-- Web page that displays a personalized greeting. -->
<!------------------------------------------------------>

<head>
<title> Greetings </title>
</head>

<body>
<script language="JavaScript">
firstName = prompt("Please enter your name", "");

document.write("Hello " + firstName + ", welcome to my Web page.");


</script>

<p>
Whatever else you want to appear in your Web page...
</body>
</html>

OUTPUT:

EXPERIMENT: 10
DATABASE MANAGEMENT & INTERNET APPLICATION
Page 43
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

AIM: Connectivity of Web pages with databases

PROGRAM:
Displaying Data from Database

In a web page, you can easily display data from a database.

You can connect to an existing database, or you can create a


new database.

Create a New Database

In this chapter we will demonstrate how to create a new database using


WebMatrix:

Create a database
Add data to the database

Creating a Database

WebMatrix includes an SQL Database design tool.

Follow the instructions below to create an SQL database called


"SmallBakery".

Open the Databases workspace and click New Database or Add


a database.

WebMatrix will create a database with the same name as your site:
"Demo.sdf":

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 44
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Rename the database to "SmallBakery.sdf".

Click New Table.

Name the new table "Product".

In the new table, create 4 columns named "Id", "Name", "Description",


and "Price".

For all columns, set Allows Null to "No".

For the "Id" column, Set Data Type to "bigint", Is Primary Key to "Yes",
and Is Identity to "Yes".

For the "Name" and "Description" columns, set Data Type to


"nvarchar(50)".

For the "Price" column, set Data Type to "money".

When you are finished, your table design will look like this

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 45
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Allow Nulls=No, specifies that the column cannot be blank (empty).

Is Primary Key?, tells the database that this will be the table's primary
key.

Is Identity?, tells the database to automatically assign a new Id number


for every new record (starting at 1).

Data Type=nvarchar(50), specifies a variable length (max 50) character


string data type.

(The n in nvarchar indicates that the character variable can hold


international Unicode characters

Adding Data to the Database

Follow the instructions below to add some data to your database:

Open the Products table (In the left pane, double-click SmallBakery.sdf,
double-click Tables, and double-click Products).

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 46
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

Enter the following records:

Name Description

Bread Baked fresh every day

Strawberry Cake Made with organic strawberries

Apple Pie Second only to your mom's pie

Pecan Pie If you like pecans, this is for you

Lemon Pie Made with the best lemons in the world

Cupcakes Your kids will love these

After you have finished your input, your screen should look much like this:

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 47
FACULTY OF ENGINEERING AND TECHNOLOGY
AGRICULTURAL

DATABASE MANAGEMENT & INTERNET APPLICATION


Page 48