Você está na página 1de 45

Vidyalankar Institute of Technology

Information Technology Department


ACADEMIC YEAR 2015-2016

Name_______________________________________

Class _________

Semester _____

Subject:- Database Technologies

Final Grade:_______

Department of Information Technology

LAB MANUAL
DATABASE TECHNOLOGIES
TE IT Sem VI
Year: 2015- 2016

Subject In-charge: Vidya Chitre

Course Outcomes:
Upon completion of this course the students will be able to :
2

CO1: Apply the conceptual and relational models to design


database systems
CO2: Apply normalization steps in database design and removal of
data anomalies
CO3: Illustrate the concepts of Object Database systems and
explore the features of RDBMS and ODBMS
CO4: Examine the generic architecture of Parallel and Distributed
database systems, differentiate the properties for concurrent
execution of transactions.
CO5: Describe the differences between OLTP systems and data
warehouses, the need for data warehousing

Experiment no: - 1
TITLE:
3

Write the problem definition of any organization and draw the EER diagram for that

Problem Statement:

EER Diagram:

Remark:

Grade:

Signature with date:

Experiment no: - 2
5

TITLE:
Performing practical by using Basic SQL Statements & joining tables.

RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql

PRIOR CONCEPTS:
Database, concept of Database Management System.

NEW CONCEPTS:
Proposition 1: Basic SELECT Statements:
SELECT Retrieves data from the database.
Syntax:SELECT *| {[DISTINCT] column | expression [alias] }
FROM
table;
-

SELECT identifies what columns


FROM identifies which table

Example: 1) Selecting all columns of the table


SELECT *
FROM departments;
2) Displaying Table Structure:
DESCRIBE employees;
WHERE Clause: Limiting the Rows Selected:
Syntax:SELECT *| {[DISTINCT] column / expression [alias],.}
FROM table
[WHERE condition(s)];
-Restrict the rows returned by using the WHERE clause.
Comparison Conditions: (=,<,>,<=,>=)
SELECT last_name, salary
FROM employees
WHERE salary<= 3000;
Logical Conditions: (AND, OR & NOT)
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE (job_id = SA_REP
OR job_id = AD_PRES)
AND salary> 15000;
ORDER BY Clause: Sort rows.
6

SELECT employee_id, last_name, salary*12 annsal


FROM employees
ORDER BY annsal;
Proposition 2 :DISPLAYING DATA FROM MULTIPLE TABLES:
Syntax: Joining tables
SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column1= table2.column2;
- write the join condition in the WHERE clause.
1. Retrieving record with Equijoin/simple join/ inner join:
e.g.: SELECT employees.employee_id, employees.last_name,
employees.department_id, departments.department_id,
departments.location_id
FROM employees, departments
WHERE employees.department_id = departments.department_id;
2. Retrieving record with Non-Equijoins: contain something other than equality operator.
e.g.: SELECT e.last_name, e.salary, j.grade_level
FROM employees e, job_grades j
WHERE e.salary
BETWEEN j.lowest_sal AND j.highest_sal;
3. Outer join: the missing rows can be returned if an outer join operator (+) is used in
join condition.
Syntax: SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column (+) = table2.column;
e.g.: SELECT e.last-name, e.department_id, d.department_name
FROM employees e, departments d
WHERE e.department_id(+) = d.department_id;
4. Cross joins: produces the cross product of two tables.
e.g.: SELECT last_name, department_name
FROM employees
CROSS JOIN departments;

Proposition 3 : AGGREGATING DATA USING GROUP FUNCTIONS:


7

Group Functions: It operate on sets of rows to give one result per group.
Syntax: SELECT [column,] group_function (column),
FROM table
[WHERE condition]
[GROUP BY column]
[ORDER BY column];
- Types of Group Functions:
AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE , COUNT,
e.g.: SELECT AVG (salary), MAX (salary), MIN (salary), and SUM (salary),
COUNT (DISTINCT department_id)
FROM employees;

Creating groups of data using GROUP BY clause:


Syntax: SELECT column, group_function (column)
From table
[WHERE condition]
[GROUP BY
group_by_expression]
[ORDER BY column];
e.g.: SELECT AVG (salary)
FROM employees
GROUP BY department_id;

The HAVING Clause: to restrict groups


Syntax: SELECT column, group_function
From table
[WHERE condition]
[GROUP BY
group_by_expression]
[HAVING group_condition]
[ORDER BY column];
e.g.: SELECT department_id, MAX (salary)
FROM employees
GROUP BY department_id
HAVING MAX (salary)>10000;

Conclusion:
This practical covers topics:
- how to write & execute SELECT statements.
- Selecting, restricting, and sorting data.
how to use joins to display data from multiple tables and group functions.

QUESTIONS:
8

Write the following simple SQL Queries on the University Schema


1. Find the names of all the students whose total credits are greater than 100

2. Find the course id and grades of all courses taken by any student named 'Tanaka'

3. Find the ID and name of instructors who have taught a course in the Comp. Sci.
department, even if they are themselves not from the Comp. Sci. department. To
test this query, make sure you add appropriate data, and include the corresponding
insert statements along with your query.

4. Find the courses which are offered in both 'Fall' and 'Spring' semester (not
necessarily in the same year).

5. Find the names of all the instructors from Comp. Sci. department
9

6. Find the course id and titles of all courses taught by an instructor named
'Srinivasan'

7. Find names of instructors who have taught at least one course in Spring 2009

Remark:

Grade:

Signature with date:

Experiment no: - 3
10

TITLE:
Performing practical by using DDL, DML, DCL, Transaction, constraints, and set
operators concepts.

RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql

PRIOR CONCEPTS:
Basic SQL Statements.

NEW CONCEPTS:
Proposition 1: DDL & DML Operations:
CREATE TABLE Statement: create table
e.g.: CREATE TABLE dept
(deptno NUMBER (2),
dname VARCHAR2 (14),
loc VARCHAR2 (13));
ALTER TABLE Statement:
- use to add, modify, define values and drop a column.
Syntax:
1) ALTER TABLE table
ADD
(column datatype [DEFAULT expr]
[, column datatype] );
2) ALTER TABLE table
MODIFY (column datatype [DEFAULT expr]
[, column datatype] );
3) ALTER TABLE table
DROP
(column datatype [DEFAULT expr]
[, column datatype] );
e.g.: 1) Add a column:
ALTER TABLE dept80
ADD (job_id VARCHAR2 (9));
2) Drop a column:
ALTER TABLE dept80
MODIFY (last_name VARCHAR2 (30));
3) Drop a column:
ALTER TABLE dept80
DROP COLUMN job_id;
INSERT Statement: add new rows to a table
e.g.: INSERT INTO departments (department_id, department_name,
11

manager_id, location-id)
VALUES (70, Public Relations, 100, 1700);
UPDATE Statement: modify existing rows.
e.g.: UPDATE employees
SET department_id = 70
WHERE employee_id = 113;
DELETE Statement: remove existing rows from a table
e.g.: DELETE FROM departments
WHERE department_name = Finance;
Proposition 2: DATABASE TRANSACTIONS:
Committing Data:
- make the changes
e.g.: DELETE FROM employees
WHERE employee_id = 99999;
INSERT INTO departments
VALUES (290, Corporate Tax, NULL, 1700);
- Commit the changes
e.g.: COMMIT;
Commit complete.
Sate of data after ROLLBACK
- Discard all pending changes by using the ROLLBACK statement.
e.g.: DELETE FROM copy_emp;
22 rows deleted
ROLLBACK;
Rollback complete.
Proposition 3: CONSTRAINTS:
Defining Constraints:
Syntax: CREATE TABLE [schema.] table
(column datatype [DEFAULT expr]
[ column_constraint],

[table_constraint] [, ] );
Types of Constraint
1. NOT NULL: defining at the column level
2. UNIQUE Constraint: defined at either the table level or the column level.
3. PRIMARY Constraint: defined at either the table level or the column level
4. FOREIGN KEY Constraint: defined at either the table level or the column level
5. CHECK Constraint: define a condition that each row must be satisfy.
e.g.:
CREATE TABLE employees (
employee_id NUMBER (6),
12

first_name VARCHAR2 (20),


job_id VARCHAR2 (10) NOT NULL
CONSTRAINT emp_emp_id-pk
PRIMARY KEY (EMPLOYEE_ID),
email VARCHAR2 (25)
CONSTRIANT emp_email_uk UNIQUE (email),
department_id NUMBER (4)
CONSTRIANT dept_id_pk PRIMARY KEY (department_id),
CONSTRIANT emp-dept_fk FOREIGN KEY (department-id)
REFERANCES departments (department_id));
Proposition 4: VIEWS:
- Logically represents subsets of data from one or more tables.
Creating a View:
Syntax: CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
[(alias [, alias])]
AS subquery
[WITH CHECK OPTION [CONSTRAINT constraint]]
[WITH READ ONLY [CONSTRAINT constraint]];
e.g.:

CREATE VIEW empvu80


AS SELECT employee_id, last-name, salary
FROM employees
WHERE DEPARTMENT_ID=80;

Removing View:
Syntax: DROP VIEW view;
e.g.: DROP VIEW empvu80
Proposition 5: CONTROLLING USER ACCESS/ DCL STATEMENTS;
Creating Users:
Syntax: CREATE USER user
IDENTIFIED BY password;
e.g.: CREATE USER scott
IDENTIFIED BY tiger;
User System Privileges:
-Grant specific privileges to the user by administrator.
Syntax: GRANT privilege [, privilege...]
TO user [, user| role, PUBLIC...];
e.g.: GRANT create session, create table, create sequence, create view
TO
scott;
13

Changing Password:
e.g.: ALTER USER scott
IDENTIFIED BY lion;
Object Privileges: Its vary from object to object.
Syntax: GRANT object_priv [(columns)]
ON object
TO {user | role | PUBLIC}
[WITH GRANT OPTION];
e.g.: GRANT select
ON employees
TO sue, rich;
How to Revoke Object Privileges
Syntax: REVOKE {privilege [, privilege...]|ALL}
ON object
FROM {user [, user...]| role| PUBLIC}
[CASCADE CONSTRAINTS];
Database Links:
-Create database link:
e.g.: CREATE PUBLIC DATABASE LINK hq.acme.com
USING 'sales';
- use the database link:
e.g.: SELECT *
FROM emp@HQ.ACME.COM;
Proposition 6: SET OPERATORS:
1. UNION / UNION ALL:
- UNION: Returns result from both queries after eliminating duplications.
e.g.: SELECT employee_id, job_id
FROM employees
UNION
SELECT employee_id, job_id
FROM job_history;
- UNION ALL: returns results from both queries, including all duplications.
2. INTERSECT:
e.g.: SELECT employee_id, job_id
FROM employees
INTERSECT
SELECT employee_id, job_id
14

FROM job_history;
3. MINUS:
e.g.: SELECT employee_id, job_id
FROM employees
MINUS
SELECT employee_id, job_id
FROM job_history;

Conclusion:
This practical covers topics:
- how to use DML statements and control transactions.
- how to create and manage tables and adding constraints to existing tables.
- how to derive views.
- DCL statements that control access to the database and database objects.
- how to use SET operators.

QUESTIONS:
The following questions are all based on the university schema.
1. Find the number of instructors who have never taught any course. If the
result of your query is empty, add appropriate data (and include
corresponding insert statements) to ensure the result is not empty.

2. Find the total capacity of every building in the university

15

3. Find the maximum number of teachers for any single course section.
Your output should be a single number. For example if CS-101 section 1
in Spring 2012 had 3 instructors teaching the course, and no other
section had more instructors teaching the section.

4. Find all departments that have at least one instructor, and list the names
of the departments along with the number of instructors; order the
result in descending order of number of instructors.

5. As in the previous question, but this time you shouold include


departments even if they do not have any instructor, with the count as 0

6. For each student, compute the total credits they have successfully
completed, i.e. total credits of courses they have taken, for which they
16

have a non-null grade other than 'F'. Do NOT use the tot_creds attribute
of student.

7. Find the number of students who have been taught (at any time) by an
instructor named 'Srinivasan'. Make sure you count a student only once
even if the student has taken more than one course from Srinivasan.

8. Find the name of all instructors who get the highest salary in their
department.

9. Find all students who have taken all courses taken by instructor
'Srinivasan'. (This is the division operation of relational algebra.) You
can implement it by counting the number of courses taught by
Srinivasan, and for each student (i.e. group by student), find the number
of courses taken by that student, which were taught by Srinivasan. Make
sure to count each course ID only once.

17

10.Find the total money spent by each department for salaries of instructors
of that department.

11. Find the names of all students whose advisor has taught the maximum
number of courses (multiple offerings of a course count as only 1).
(Note: this is a complex query, break it into parts by using the with
clause.)

Remark:

Grade:

Signature with date:

18

Experiment no: - 4
Title: Schema creation and constraints

Resources required:
Oracle 9i - iSQLplus onwards or Postgesql

Theory:
drop
drop
drop
drop

table
table
table
table

trainhalts;
train;
track;
station;

--This table contains one row for every halt of a train.


-- id
: id of the train
-- seqno : the halt number. Assume that the starting station has seqno
as 0
-- stcode : station code of this halt
-- timein : time at which the train arrives at this station. (will be
null for the starting station of a train)
-- timeout: time at which the train departs this station. (will be null
for the terminating station of a train)
-- If a train passes through a station without stopping, then there will
be an entry with timein = timeout.
create table trainhalts
(id varchar(5) ,
seqno integer ,
stcode varchar(10),
timein varchar(5) ,
timeout varchar(5) ,
primary key (id,seqno) );
-- This table stores the distances between directly connected stations
stcode1 and stcode2.
-- Assume that this represents a directed track. i.e, for two stations A
and B, there will be
-- an entry corresponding to (A, B, distance) and another for (B,A,
distance).
create table track
(stcode1 varchar(5) ,
stcode2 varchar(5),
distance integer ,
primary key (stcode1,stcode2) );
create table station
(stcode varchar(5),
name varchar(20),
primary key (stcode));
create table train
(id varchar(5) ,
name varchar(20),

19

primary key (id) );


delete
delete
delete
delete
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert

from
from
from
from
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into
into

trainhalts;
station;
track;
train;
station values ('CST' ,'MUMBAI');
station values ('BYC' ,'BYCULLA');
station values ('DR' ,'DADAR');
station values ('KRL' ,'KURLA');
station values ('GPR' ,'GHATKOPAR');
station values ('TNA' ,'THANE');
station values ('DL' ,'DOMBIVALI');
station values ('AMR' , 'AMBARNATH');
station values ('KYN' ,'KALYAN');
station values ('KSR' ,'KASARA');
train values ('KP11' ,'CST-KYN');
train values ('KP11L' ,'CST-KYN_LOCAL');
train values ('T129' ,'CST-TNA_LOCAL');
train values ('A63' ,'CST-DL_LOCAL');
train values ('K101' ,'CST-KYN_LOCAL');
train values ('N27' ,'CST-TNA_LOCAL');
train values ('S33' ,'CST-KGR_LOCAL');
train values ('A65' ,'CST-AMR_LOCAL');
track values ('CST' ,'BYC', 5);
track values ('CST' ,'DR', 9);
track values ('CST' ,'KRL', 16);
track values ('CST' ,'GPR', 20);
track values ('CST' ,'TNA', 34);
track values ('CST' ,'DL', 49);
track values ('CST' ,'KYN', 54);
track values ('CST' ,'KSR', 77);
track values ('CST' ,'AMR', 65);
track values ('BYC' ,'DR', 4);
track values ('BYC' ,'KRL', 11);
track values ('GRP' ,'TNA', 14);
track values ('DR' ,'TNA', 25);
track values ('KRL' ,'KYN', 38);
track values ('TNA' ,'KYN', 20);
track values ('TNA' ,'KSR', 43);
trainhalts values ('KP11' , 0 , 'CST' , NULL, '20.23');
trainhalts values ('KP11' , 1 , 'BYC' , '20.31', '20.32');
trainhalts values ('KP11' , 2 , 'DR' , '20.41', '20.42');
trainhalts values ('KP11' , 3 , 'GPR' , '20.52', '20.53');
trainhalts values ('KP11' , 4 , 'GPR' , '20.52', '20.53');
trainhalts values ('KP11' , 5 , 'DR' , '20.41', '20.42');
trainhalts values ('KP11' , 6 , 'GPR' , '20.58', '20.59');
trainhalts values ('KP11' , 7 , 'TNA' , '21.21', '21.22');
trainhalts values ('KP11' , 8 , 'DL' , '21.45', '21.46');
trainhalts values ('KP11' , 9 , 'KYN' , '21.54', NULL);
trainhalts values ('A65' , 0 , 'CST' , NULL , '20.52');
trainhalts values ('A65' , 1 , 'BYC' , '21.00' , '21.01');
trainhalts values ('A65' , 2 , 'DR' , '21.10' , '21.11');
trainhalts values ('A65' , 3 , 'KRL' , '21.22' , '21.23');
trainhalts values ('A65' , 4 , 'GPR' , '21.28' , '21.29');
trainhalts values ('A65' , 5 , 'TNA' , '21.49' , '21.50');
trainhalts values ('A65' , 6 , 'DL' , '22.13' , '22.14');

20

insert into trainhalts values ('A65' , 7 , 'KYN' , '22.22' , '22.23');


insert into trainhalts values ('A65' , 8 , 'AMR' , '22.36' , NULL);

Questions:
Write the following Queries for Railway Schema
1. Find pairs of stations (station codes) that have a track (direct connection) with
distance less than 20Kms between them.

2. Find the IDs of all the trains which have a stop at THANE

3. Find the names of all trains that start at MUMBAI.

4. List all the stations in order of visit by the train 'CST-AMR_LOCAL'.

5. Find the name of the trains which have stop at Thane, before the 6th station in the
route of the train.

21

6. Modify the trains schema which we saw earlier to create constraints to check the
following:
1. The value of timein is always less than or equal to timeout

2. When a train is removed from service, all its halts should


be deleted.

7. Insert inconsistent data and verify the constraints.

8. Write SQL Create table statements to create the following schema. Include all
appropriate primary and foreign key declarations. Choose appropriate types for
each attribute.
1. remotecentre(centreId, college, town, state)

2. person(ID, name, email)

22

3. programme(progId, title, fromdate, todate)

4. coordinator(ID, progId, centreId)

5. participant(ID, progId, centreId)

Remark:

Grade:

Signature with date:

Experiment no: - 5
23

TITLE:
Performing practical by using Object-oriented database concepts.

RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql

PRIOR CONCEPTS:
Basic SQL Statements and Object-Oriented Programming Concepts.

NEW CONCEPTS:
Objects User defined complex data types
An object has structure or state (variables) and methods (behavior/operations).
Object Oriented Database Management Systems:

In an object database (also object oriented database), information is


represented in the form of objects as used in object-oriented programming. When
database capabilities are combined with object programming language capabilities, the
result is an object database management system (ODBMS). An ODBMS makes database
objects appear as programming language objects in one or more object programming
languages. An ODBMS extends the programming language with transparently persistent
data, concurrency control, data recovery, associative queries, and other capabilities.
An object is defined by specifying the attributes of the object & methods used to
manipulate the object. It does provide a set of valuable data management functions, such
24

as distribution & high performance access. OODB are queried using a standard Object
Query Language (OQL).
Object Query Language (OQL) is a query language standard for object-oriented
databases modelled after SQL. OQL was developed by the Object Data
Management Group (ODMG). Because of its overall complexity no vendor has
ever fully implemented the complete OQL. OQL has influenced the design of
some of the newer query languages like JDOQL and EJBQL, but they can't be
considered as different flavours of OQL.
Key Differences between OQL and SQL
OQL differs from SQL in that:

OQL supports object referencing within tables. Objects can be nested within
objects.
Not all SQL keywords are supported within OQL. Keywords that are not relevant
to Netcool/Precision IP have been removed from the syntax.
OQL can perform mathematical computations within OQL statements.

General Rules of OQL


The following rules apply to OQL statements:

All complete statements must be terminated by a semi-colon.


A list of entries in OQL is usually separated by commas but not terminated by a
comma.
Strings of text are enclosed by matching quotation marks.

Query returns:
OQL

SQL

Object
Collection of objects

Tuple
Table

Complex Object:
It can be composed of multiple base or user defined datatypes. They can represent
complex internal structure attributes & behavior. To create a complex object ,need to:
- Construct new user-defined datatypes (UDTs).
- Define new user-defined datatypes (UDFs).
To manipulate these types. Composite datatype consists of collection of values.

25

Proposition 1: CREATE OBJECT: UDT:


Example:
CREATE TYPE Apartment AS OBJECT (
BuildingName VARCHAR2 (25),
ApartmentNo CHAR (4),
NumberBedRooms NUMBER (10));
Proposition 2: CREATE TABLE:
Example:
CREATE TABLE person (
Name VARCHAR2 (50),
Location Apartment);
Proposition 3: INSERTION
Example:
INSERT INTO person VALUES (
Selma Whitebread,Apartment (Eastlake, 206, 2));
Proposition 4: UPDATION
Example:
UPDATE person
SET location = Apartment (Eastlake , 412, 3)
WHERE name = Selma Whitebread;
Proposition 5: SELECTION OF DATA
Example:
Selecting Column object:
SELECT * FROM person;
Proposition 6: VARRAY:
- Firstly create object to a Varray:
CREATE TYPE Apt_unit AS object (
AprtNo CHAR (5),
Nobedrooms INT

);

CREATE TYPE Apart_list1 AS VARRAY (50) of Apt_unit;


Here Apt_unit is a object-type.
-

Table:
CREATE TABLE build1 (
BuildID NUMBER,
Name VARCHAR2 (50),
Units Apt_list1);

26

INSERT INTO build1 VALUES (1, Eastlake,


Apart_list1 (Apt_unit (100, 1),
Apt_unit (200, 2),
Apt_unit (300, 3)));
- Select data from all rows:
SELECT * FROM Build1;

Conclusion:
Thus we learned Object-oriented concept, in that how to create UDT and define
data .

QUESTIONS:
Using Object Oriented databases create the following types:
a)AddrType1 (Pincode: number, Street :char, City : char,. state :char)

b) BranchType (address: AddrType1, phone1: integer,phone2: integer )

c) AuthorType (name:char,,addr AddrType1)

d) PublisherType (name: char, addr: AddrType1, branches: BranchTableType

27

e) AuthorListType as varray, which is a reference to AuthorType

Next create the following tables:


f) BranchTableType of BranchType

g) authors of AuthorType

h) books(title: varchar, year : date,


published_by ref PublisherType,authors AuthorListType)

i) Publishers of PublisherType

Insert 10 records into the above tables and fire the following queries:
28

1.List all of the authors that have the same pin code as their publisher:

2. List all books that have 2 or more authors:

3. List the name of the publisher that has the most branches

4. Name of authors who have not published a book

5. List all authors who have published more than one book:

6. Name of authors who have published books with at least two different publishers

29

7. List all books (title) where the same author appears more than once on the list of
authors (assuming that an integrity constraint requiring that the name of an author is
unique in a list of authors has not been specified).

Remark:

Grade:

Signature with date:

Experiment no: - 6
30

TITLE:
Performing practical by using using fragmentation concept.

RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql

PRIOR CONCEPTS:
Relational database and Basic SQL Statements.

NEW CONCEPTS:
Definition of Distributed Database:
A distributed database is a database that is under the control of a central database
management system (DBMS) in which storage devices are not all attached to a common
CPU. It may be stored in multiple computers located in the same physical location, or
may be dispersed over a network of interconnected computers. The computers in a DDB
system known as sites or nodes may vary in size and function.
The DDBMS synchronizes all the data periodically and, in cases where multiple
users must access the same data, ensures that updates and deletes performed on the data
at one location will be automatically reflected in the data stored elsewhere.
The general structure of a distributed system is:

Data Distribution:
31

Collections of data (eg. in a database) can be distributed across multiple physical


locations. A distributed database is distributed into separate partitions/fragments. Each
partition/fragment of a distributed database may be replicated.
Fig: A Fully Distributed Database Management System:

Data Fragmentation:
In this scheme, the relation is divided into fragments. The partitioning of relations
is known as fragmentation. It allows a subset of the relations attributes or relations tuple
to be defined at a given site to satisfy local applications.
There are various ways of data fragmentation:
-

Horizontal Fragmentation
Vertical Fragmentation

Mixed Fragmentation.

32

Examples:
Proposition 1: Vertical Fragmentation:
EMP (EMP#, Name, Dept, Degree, Phone, Sal, StartDate)
Fragment this relation vertically; into two different relations/nodes
EMP1 (EMP#, Name, Degree, Phone)
EMP2 (EMP#, Name, Sal, StartDate)
-

Here EMP# is a PK of original relation.

Original relation obtained by a joining of fragment on tuple identifiers.


Original relation: MODULE_USE
TID MODULE
USES
T1 Query Processing SORT
T2 User Interface
SORT
-

Horizontally fragment into two nodes

MODULE:

USES:
33

TID MODULE
T1 Query Processing
T2 User Interface
TID USES
T1 SORT
T2 SORT

Proposition

2:

Horizontal Fragmentation:

Example: ACCOUNT relation.


Branch_name
H
V
H
V
-

AcctNo.
A-1
A-2
A-3
A-4

Balance
500
300
400
600

Vertically fragment into two nodes depends on Banch_name.

ACCT1:
Branch_name AcctNo.
V
A-2
V
A-4

Balance
300
600

ACCT2:
Branch_name
H
H

AcctNo.
A-1
A-3

Balance
500
400

- Here, tuples of a relation are assigned to different fragments by using some


selection criterion.
-

Original relation obtains by union operation.

Conclusion:
Thus we learned horizontal & vertical fragmentation concept of distributed
database.

34

QUESTIONS:
1. Create a global conceptual schema Emp(Eno;Ename;Address;Email;Salary) and
insert 10 records. Divide Emp into vertical fragments Emp1 (Eno; Ename;
Address) and Emp2 (Eno; Email; Salary) on two different nodes.
(i)
Find the salary of an employee where employee number is
known.

(ii)

Find the Email where the employee name is known.

(iii)

) Find the employee name and Email where employee number


is known.

(iv)

Find the employee name whose salary is > 2000.

2. Create a global conceptual schema Emp (Eno;Ename;Address;Email;Salary) and


insert 10 records.Divide Emp into horizontal fragments using the condition that
Emp1 contains the tuples with salary = 10,000 and Emp2 with 10,000< salary =
20,000 on two different nodes.
a) Find the salary of all employees.

35

b) Find the Email of all employees where salary = 15,000

c) Find the employee name and Email where employee number is known.

d) Find the employee name and address where employee number is known.

Remark:

Grade:

Signature with date:

36

Experiment no: - 7
TITLE:
Performing practical by using replication concepts

RESOURCE REQUIRED:
Oracle 9i - iSQLplus onwards or Postgesql

PRIOR CONCEPTS:
Relational database and Distributed database concept.

NEW CONCEPTS:
Replication:
Replication is the process of creating and maintaining replica versions of database
objects (e.g. tables) in a distributed database system.
Replication can improve performance and increase availability of applications
because alternate data access options becomes available. For example, users can access a
local database rather than a remote server to minimize network traffic. Furthermore, the
application can continue to function if parts of the distributed database are down as
replicas of the data might still accessible.

Data Replication
- Storage of data copies at multiple sites served by a computer network
- Fragment copies can be stored at several sites to serve specific information
requirements
- Can enhance data availability and response time
- Can help to reduce communication and total query costs

37

Replication Objects:
A replication object is a database object existing on multiple servers in a
distributed database system. In a replication environment, any updates made to a
replication object at one site are applied to the copies at all other sites. Advanced
Replication enables you to replicate the following types of objects:
Tables
Indexes
Views and Object Views
Packages and Package Bodies
Procedures and Functions
User-Defined Types and Type Bodies
Triggers
Synonyms
Indextypes
User-Defined Operators
Regarding tables, replication supports advanced features such as partitioned tables, indexorganized tables, tables containing columns that are based on user-defined types, and
object tables.
Replication can be done by three ways:
1) Views
2) Synonym
3) Snapshot
Comparison :

38

1) View & Synonym doesnt store their own data but the derived the data from the
base table from where the view & synonym has been made whereas snapshot has
its own data
2) Again view & synonym requires continuously link but it can be refereshed at
periodic intervals.
3) View is basically used for in-house purpose whereas synonym & snapshot are
basically used in distributed database.
4) Snapshot is read only.
5) You must have to create a primary key before snapshot created.
Proposition 1: How does one implement basic snapshot replication?
Start by creating an optional snapshot log on the master database. If you do not
want to do fast refresh, you do not need to create a log. Also note that fast refreshes are
not supported for complex queries. Create a snapshot/materialized view on the snapshot
site. Look at this example:
SQL> create materialized view emp
refresh fast with primary key
start with sysdate
next sysdate + 1/(24*60)
as (select * from emp);

Proposition 2: Steps for creating replication:


1. create two users
e.g. Create user boss identified by password;
Create user client identified by password;
-

2. Connect boss/boss
Create table exp as select * from emp;
Grant all on emp to public;
Also grant all on exp to public;

3. Create View for emp table:


e.g. Create view sample as select * from emp;
Try to insert few records in view & check view & emp table.
39

4. Create synonym for emp:


Syntax: create synonym syn_name for table_name;
Insert few records in synonym & check synonym & emp table.
5. Alter table & add pk for that.
e.g. Alter table exp add primary key(EMPNO);
6. Create snapshot snapshot_name as select * from exp;
Try to insert record in snapshot. Then check exp table & snapshot.
Execute DBMS_Snapshot.Refresh(snapshot_name);
Select * from exp;
Select * from snapshot_name;
7.

Connect client/client;

8. Create view v1 as select * from boss.emp;


Insert some record in this view & check view & emp table in boss user.
9. Create synonym synonym_name for boss.emp;
Insert record in synonym & check it & check emp table from boss user.
Both user data will be reflected.
10. Create snapshot snap1 as select * from boss.exp;
Insert some record in exp table in boss user & check in exp table & snapshot
(sanp_name).
Execute DBMS_SNAPSHOT.REFRESH (snap_name);
11. Again connect boss/boss;
12. Drop table emp;
Drop table exp;
Select * from sample;
Select * from Syn_name;
Select * from snapshot_name;
13. Connect client/client;
Select * from v1;
Select * from syn_name;
Select * from snap1;

-------which is from boss user

Conclusion:
Thus we learned how to implement replication concept by using
two users.

40

QUESTIONS:
Create a global conceptual schema EMP (Eno; Ename; Address; Email; Salary) and insert
10 records. Store the replication of EMP into two different nodes and fire the following
queries:
(i) Find the salary of all employees.

(ii) Find the Email of all employees where salary = 15,000

(iii) Find the employee name and Email where employee number is known.

(iv) Find the employee name and address where employee number is known.

Remark:

Grade:

Signature with date:


41

Experiment no: - 8
Title: Study of data warehousing tool.
Resources required:

Remark:

Grade:

Signature with date:

42

Experiment no: - 9
Mini Projects:
Resources required:

Problem Statement:

Remark:

Grade:

Signature with date:

43

Experiment no: - 10
Mini Projects:
Resources required:
Problem Statement:

Remark:

Grade:

Signature with date:

44

Assignments

45

Você também pode gostar