Sei sulla pagina 1di 33

Advanced Database Management Systems Experiment

Experiment no: - 1

Title:
Performing practical by using Basic SQL Statements, joining tables and pattern
matching.

Resource Required:
Oracle 9i - iSQLplus

Prior Concepts:
Database, concept of Database Management System.

Theory:
1.0 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

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: (=, <,>, <=,>=)
Logical Conditions: (AND, OR & NOT)

1.1 Displaying Data From Multiple Tables:


Joining is the method that used to displaying data from multiple tables.
Joining types are:
1. Equijoin /Equal join
2. Natural join
3. Outer join

Syntax:
SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column1 = table2.column2;

• Write the join condition in the WHERE clause.

Terna Engineering College, Nerul. 1


Advanced Database Management Systems Experiment

• Prefix the column name with the table name when the same column name appears
in more than one table.
1. Retrieving record with Equijoin/simple join/ inner join/ equal join:
- A join, which is based on equalities.
- Equijoins are also called simple joins or inner joins.
- Here, Comparison Operator equal (=) is used to perform join.
- It retrieves the row from tables having common column.

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. Natural Join:
- The NATURAL JOIN clause is based on all columns in the two tables that have the
same name.
- It selects rows from the two tables that have equal values in all matched columns.
- If the columns having the same names have different data types, an error is returned.

e.g.: SELECT department_id, department_name, location_id, city


FROM departments
NATURAL JOIN locations;

3. Outer join:
- Returning Records with No Direct Match. If a row does not satisfy a join
condition, the row will not appear in the query result.
- The missing rows can be returned if an outer join operator is used in the join
condition.

>> Left Outer Join:


- takes all rows in left relation that did not match with any row in the right
relation
- pads those rows with NULL values for all other attributes from right
relation and add them to the result of the Natural join.

e.g.: SELECT e.last_name, e.department-id, and d.department_name


FROM employees e
LEFT OUTER JOIN departments d
ON (e. department_id = d.department_id);

>> Right Outer Join:


- takes all rows in the right relation that did not match with any row in the
left relation

Terna Engineering College, Nerul. 2


Advanced Database Management Systems Experiment

- pads those rows with NULL values for all the attributes from left relation ,
and add them to the result of the Natural join.

e.g.: SELCET e.last_name, e.department_id, d.department_name


FROM employees e
RIGHT OUTER JOIN departments d
ON (e.department_id = d.department_id);

>> Full Outer Join:


- Combination of both right outer join and left outer join.

e.g.: SELECT e.last_name, e.department-id, and d.department_name


FROM employees e
FULL OUTER JOIN departments d
ON (e. department_id = d.department_id);

1.2 Pattern Matching:

- The character pattern-matching operation is referred to as a wildcard


search.
- This operation performed by using LIKE operator: When you may not
always know the exact value to search.
- Used in WHERE clause.
Two symbols can be used to construct the search string:
_ (Underscore) it matches any single character
% (Percentage) it matches any sequence of string

e.g.: SELECT last_name


FROM employees
WHERE last_name LIKE '_o%';
Find last_name of employee which has second character ‘o’ in their last_name.

Conclusion:
This practical covers topics:
- How to use joins to display data from multiple tables.
- How to perform pattern matching operation.

Terna Engineering College, Nerul. 3


Advanced Database Management Systems Experiment

QUESTIONS:
1. Write a query to display the last name, department number, and department name for
all employees.

2. Write a query to display the employee last name, department name, location ID, and
city of all employees who earn a commission.

3. Display the employee last name and department name for all employees who have a
(lowercase) in their last names.

4. Write a query to display the last name, job, department number, and department name
for all employees who work in Toronto.

5. Display the employee last name and employee number along with their manager’s last
name and manager number. Label the columns Employee, Emp#, Manager, and Mgr#,
respectively. Display all employees including King, who has no manager and Order the
results by the employee number. (left outer join)

Terna Engineering College, Nerul. 4


Advanced Database Management Systems Experiment

Experiment no: - 2

Title:
Performing practical by using Aggregate functions and subqueries consists ANY,
ALL, EXIST and NOT EXIS operators.

Resource Required:
Oracle 9i - iSQLplus

Prior Concepts:
Database, Basic SQL statements.

Theory:
2.0 Aggregate Functions:
Aggregate functions 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];

e.g.: SELECT AVG (salary), MAX (salary), MIN (salary), and SUM (salary),
COUNT (DISTINCT department_id)
FROM employees;

- You can use AVG, SUM for numeric data.


- You can use MIN and MAX for any data type.
- COUNT returns the number of rows in a table

Terna Engineering College, Nerul. 5


Advanced Database Management Systems Experiment

 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;

2.1 Group Functions and Null Values:


NULL means totally unknown, inapplicable,
All group functions ignore null values in the column.

e.g.: SELECT AVG (commission_pct)


FROM employees;

- Null values are used mostly in Group Function by using NVL function.
- The NVL function forces group functions to include null values.
NVL Function: returns actual value of expression
Nvl (expr1, expr2): here if expr1 is NULL result is expr2, if expr1 is NOT NULL then
result is expr1.

e.g.: SELECT AVG (NVL (commission_pct, 0))


FROM employees;

2.2 Nested Query / Subquery:


A subquery is a SELECT statement that is embedded in a clause of another SELECT
statement.
They can be very useful when you need to select rows from a table with a
condition that depends on the data in the table itself.

Terna Engineering College, Nerul. 6


Advanced Database Management Systems Experiment

You can place the subquery in a number of SQL clauses, including:


• The WHERE clause
• The HAVING clause
• The FROM clause
Execute the subquery (inner query) on its own first to show the value that the subquery
returns. Then execute the outer query using the result returned by the inner query. Finally,
execute the entire query (containing the subquery), and show that the result is the same

Syntax:
SELECT select_list
FROM table
WHERE expr operator
(SELECT select_list
FROM table);
- The subquery (inner query) executes once before the main query.
- The result of the subquery is used by the main query (outer query).

Types of Subqueries:
1. Single-row subquery
2. Multiple-row subquery

 Single- row Subqueries:


- Return only one row and uses single-row comparison operators (=, >, <,
>=, <=, < >).

 Multiple-row Subqueries:
- Return more than one row and uses multiple-row comparison
operators :
IN : Equal to any member in the list.
ANY : Compare value to each value returned by the subquery.
ALL : Compare value to every value returned by the subquery.

ANY: The ANY operator (and its synonym, the SOME operator) compares a value to
each value returned by a subquery.

Terna Engineering College, Nerul. 7


Advanced Database Management Systems Experiment

< ANY means less than the maximum. >ANY means more than the minimum. =ANY is
equivalent to IN.

ALL: The ALL operator compares a value to every value returned by a subquery.

>ALL means more than the maximum, and <ALL means less than the minimum.

2.3 Advanced Subqueries:


Here, learn how to write multiple-column subqueries and subqueries in the FROM
clause of a SELECT statement.

Correlated Subqueries
Correlated subqueries are used for row-by-row processing. Each subquery is
executed once for every row of the outer query.

A correlated subquery is evaluated once for each row processed by the parent statement.
The parent statement can be a SELECT, UPDATE, or DELETE statement.

Syntax:
SELECT column1, column2, ...
FROM table1 outer
WHERE column1 operator
(SELECT colum1, column2
FROM table2
WHERE expr1 =
outer .expr2);

e.g.:

Terna Engineering College, Nerul. 8


Advanced Database Management Systems Experiment

SELECT last_name, salary, department_id


FROM employees outer
WHERE salary >
(SELECT AVG (salary)
FROM employees
WHERE department_id =
outer.department_id);
Each time a row from the outer query is processed, the inner query is evaluated.

Using the EXISTS Operator


- The EXISTS operator tests for existence of rows in the results set of the subquery.
- If a subquery row value is found:
– The search does not continue in the inner query
– The condition is flagged TRUE
- If a subquery row value is not found:
– The condition is flagged FALSE
– The search continues in the inner query

e.g.: SELECT employee_id, last_name, job_id, department_id
FROM employees outer
WHERE EXISTS (SELECT 'X'
FROM employees
WHERE manager_id =
outer.employee_id);

The EXISTS operator ensures that the search in the inner query does not continue when
at least one match is found for the manager and employee number by the condition:
WHERE manager_id = outer.employee_id.
Note: Having EMPLOYEE_ID in the SELECT clause of the inner query causes a table
scan for that column. Replacing it with the literal X, or any constant, improves
performance

Using the NOT EXISTS Operator


It evaluates to FALSE if any member of the set is a NULL value
e.g.: SELECT department_id, department_name
FROM departments d
WHERE NOT EXISTS (SELECT 'X'
FROM employees
WHERE department_id
= d.department_id);
This statement help to find all departments that do not have any employees.

Conclusion:

Terna Engineering College, Nerul. 9


Advanced Database Management Systems Experiment

This practical covers topics:


- How to use aggregate function and null values.
- Creating subqueries by using any, all, exit and not exit operator.

Questions:
1. Create a query to display the employee numbers and last names of all employees who
earn more than the average salary. Sort the results in ascending order of salary.

2. Display the highest, lowest, sum, and average salary of all employees for each job
type. Label the columns Maximum, Minimum, Sum, and Average, respectively.

3. Displays employees who are not IT programmers and whose salary is less than that of
any IT programmer.

4. Displays employees whose salary is less than the salary of all employees with a job ID
of IT_PROG and whose job is not IT_PROG.

5. Find all employees who are not supervisors. (Using the NOT EXISTS operator.)

Experiment no: - 3

Terna Engineering College, Nerul. 10


Advanced Database Management Systems Experiment

Title:
Performing practical by using Object -Relational Database concept.

Resource Required:
Oracle 9i - iSQLplus

Prior Concepts:
Relational Database, Basic SQL statements, Object oriented programming.

Theory:
3.0 Basic 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 function’s, such

Terna Engineering College, Nerul. 11


Advanced Database Management Systems Experiment

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 Tuple
Collection of objects 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.

Proposition 1: CREATE OBJECT: UDT:

Terna Engineering College, Nerul. 12


Advanced Database Management Systems Experiment

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);

INSERT INTO build1 VALUES (1, ‘Eastlake’,

Terna Engineering College, Nerul. 13


Advanced Database Management Systems Experiment

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:

Terna Engineering College, Nerul. 14


Advanced Database Management Systems Experiment

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
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 5 records into the above tables and fire the following queries:

a) List all of the authors that have the same pin code as their publisher:
b) List all books that have authors:
c) List the name of the publisher that has the most branches

Experiment no: - 4

Terna Engineering College, Nerul. 15


Advanced Database Management Systems Experiment

Title:
Performing practical by using Fragmentation concept.

Resource Required:
Oracle 9i - iSQLplus

Prior Concepts:
Relational database and Basic SQL Statements.

Theory:
4.0 Basic 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:

Terna Engineering College, Nerul. 16


Advanced Database Management Systems Experiment

5.0 Data Distribution:

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:

6.0 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 relation’s 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.

Terna Engineering College, Nerul. 17


Advanced Database Management Systems Experiment

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

Terna Engineering College, Nerul. 18


Advanced Database Management Systems Experiment

- Horizontally fragment into two nodes

MODULE: USES:

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

Proposition 2: Horizontal Fragmentation:

Example: ACCOUNT relation.


Branch_name AcctNo. Balance
H A-1 500
V A-2 300
H A-3 400
V A-4 600

- Vertically fragment into two nodes depends on Banch_name.

ACCT1:
Branch_name AcctNo. Balance
V A-2 300
V A-4 600
ACCT2:
Branch_name AcctNo. Balance
H A-1 500
H A-3 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.

Terna Engineering College, Nerul. 19


Advanced Database Management Systems Experiment

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.
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.

Terna Engineering College, Nerul. 20


Advanced Database Management Systems Experiment

Experiment no: - 5

Title:
Performing practical by using XML Database concept.

Resource Required:
Oracle 9i - iSQLplus

Prior Concepts:
Relational database and Basic SQL Statements.

Theory:
5.0 Basic Concepts:
 Introducing Oracle XML DB:
XML is also language-independent and platform-independent. As XML
support has become standard in browsers, application servers, and databases, enterprises
have wished to tie legacy applications to the Web using XML to transform various
proprietary file- and document-exchange templates into XML.
Oracle XML DB is a set of built-in high-performance storage and
retrieval technologies geared to XML. The advantages of relational database technology
and XML technology at the same time. Oracle XML DB can be used to store, query,
update, transform, or otherwise process XML, while at the same time providing SQL
access to the same XML data.

 Oracle XML DB Architecture:-

The Oracle XML DB architecture. The two main features in Oracle XML DB architecture
are:

 The XMLType tables and views storage, which includes storage of XMLType
tables and views
 The Oracle XML DB Repository also referred to in this manual as "XML
Repository" or "Repository”.

Terna Engineering College, Nerul. 21


Advanced Database Management Systems Experiment

Figure 1-1 Oracle XML DB Architecture: XMLType Storage and


Repository

 Using Oracle XML DB:

Proposition 1:
Creating XMLType Tables and Columns Based on XML Schema:
Syntax:

CREATE TABLE [schema.] table OF XMLTYPE

[XMLTYPE XMLType_storage] [XMLSchema_spec];

Terna Engineering College, Nerul. 22


Advanced Database Management Systems Experiment

Figure : Creating an XMLType Table

E.g.: CREATE TABLE testxml (id NUMBER (3), dt SYS.XMLTYPE);


Table created.

Creating a Table with an XMLType Column


CREATE TABLE Example1
(
KEYVALUE varchar2(10) primary key,
XMLCOLUMN xmltype
);

Creating a Table of XMLType


CREATE TABLE example2 of XMLType;

Proposition 2: Inserting XML Content into an XMLType Table

SQL> INSERT INTO testxml VALUES(111,


sys.xmltype.createxml(
'<?xml version="1.0"?>
<customer>
<name>Joe Smith</name>
<title>Mathematician</title>
</customer>'))
1 row created.

Proposition 3: Creating an XMLType Table that Conforms to an XML Schema


CREATE TABLE PurchaseOrder of XMLType
XMLSCHEMA
"http://localhost:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd"
ELEMENT "PurchaseOrder"
varray "XMLDATA"."ACTIONS"."ACTION"
STORE AS table ACTION_TABLE
(
(primary key (NESTED_TABLE_ID, ARRAY_INDEX))
)
varray "XMLDATA"."LINEITEMS"."LINEITEM"

Terna Engineering College, Nerul. 23


Advanced Database Management Systems Experiment

store as table LINEITEM_TABLE


(
(primary key (NESTED_TABLE_ID, ARRAY_INDEX))
organization index overflow
);

Table created.

Proposition 4: Using DESCRIBE for an XML Schema-Based XMLType Table


desc PURCHASEORDER
Name Null? Type
----------------------------- -------------------------------------------------
TABLE of SYS.XMLTYPE(XMLSchema
"http://localhost:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element
"PurchaseOrder") STORAGE Object-relational TYPE "PURCHASEORDER_T"

Using object_value to Retrieve an Entire XML Document


set long 10000
set pagesize 100
set linesize 132
--
SELECT object_value

FROM PURCHASEORDER;

Proposition 5: Accessing XML Fragments Using extract()

statement returns an XMLType containing the first LineItem element in the LineItems
collection:

SELECT extract(object_value,'/PurchaseOrder/LineItems/LineItem[1]')
FROM PURCHASEORDER;

Conclusion:
Thus we learned , how to implement XML database creation & XMLType
concept.

Terna Engineering College, Nerul. 24


Advanced Database Management Systems Experiment

QUESTIONS:
Create a table employee having dept_id as number datatype and employee_spec as XML
datatype (XMLType).
The employee_spec is a schema with attributes emp id, name, email, acc_no,
managerEmail, dateOf Joning.
Insert 8 tuples into employee table. Fire the following queries on XML database.

a) Retrieve the names of employee.


b) Retrieve the acc_no of employees.
c) Retrieve the names, acc_no, and email of employees.
d) Update the 3rd record from the table and display the name of an employee.
e) Delete 4 th record from the table.

Terna Engineering College, Nerul. 25


Advanced Database Management Systems Experiment

Experiment no: - 6

Title:
Performing practical by using Replication concept.

Resource Required:
Oracle 9i - iSQLplus

Prior Concepts:
Relational database, Basic SQL Statements, Distributed database basic.

Theory:
6.0 Basic 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

Terna Engineering College, Nerul. 26


Advanced Database Management Systems Experiment

 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
 Index types
 User-Defined Operators

Regarding tables, replication supports advanced features such as partitioned tables, index-
organized 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 :

1) View & Synonym doesn’t store their own data but the derived the data from the
base table from where the view & synonym has been made whereas snapshot has
it’s 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.

Terna Engineering College, Nerul. 27


Advanced Database Management Systems Experiment

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.

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;

Terna Engineering College, Nerul. 28


Advanced Database Management Systems Experiment

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; -------which is from boss user
Select * from snap1;

Conclusion:

Thus we learned how to implement replication concept by using


two users.

Terna Engineering College, Nerul. 29


Advanced Database Management Systems Experiment

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.

Terna Engineering College, Nerul. 30


Advanced Database Management Systems Experiment

One mini project using any Front End and any


Backend:

For eg:

1. Library Management System


2. income Tax Calculation System
3. Payroll System
4. Inventory Management System
5. Railway Reservation
6. Merit List Management System.
7. Check-List Controller.

Perform project work as per following steps by Project


group:-

1. Basic Information

2. Project Activities: performs by project group


1. Selection of Project.

2. Preparation of Project Execution plan: Time & Resource allocation.

3. Preperation of Software Requirements Specifiation.


For e.g. (1) User Inputs (2) Outputs for User (3) Environmental constraints (4)
Other important processes.

4. Design (EER Model), Development (EER model convert into Relational model),
Testing and Debugging of Prototypes one by one.

5. Preparation of Project Report and all technical documentation like Schematic


Drawings, Flow Charts, E-R Diagrams, Data-Flow Diagrams, Source Code
Listing, User Instructions, and List of Problems encountered etc.

6. Final submission of Project-Report.

Terna Engineering College, Nerul. 31


Advanced Database Management Systems Experiment

3. Detail Specifications:

- The original design requirements are not essential, it is most important


that, students must put his independent study efforts on the project. Thus, student
should gain practical project execution knowledge about making some useful
product, after he goes through all projects completion steps listed above.

- Assigned maximum 3 students in each group.

4. Project Report Format:

- Certificate

- Contents:

1. Introduction

1.1 Background
1.2 Need for Work
1.3 Brief Idea

2. System Overview and Design

2.1 Operation
2.2 Objects
2.3 Properties
2.4 Methods
2.5 Events

3. Module Design

3.1 Module 1 (EER model)


3.2 Module 2 (Relational Model)

4. Debugging and Testing

4.1 Debugging Report


4.2 Testing Report

5. Result and Conclusion

6. Reference

Terna Engineering College, Nerul. 32


Advanced Database Management Systems Experiment

5. Suggested Scheme of Chapters in Project Report:

1. Chapter 1: Introduction: Background of the project, Need for the project, Brief idea
of the project

2. Chapter 2: System Overview and Design: Present the overview of the complete
system. Use Block Diagrams. Specify design parameters for the system. Discuss each
object and its associated properties, methods and events along with relationship with
other objects.

3. Chapter 3: Module Design: Present each module with its associated EE-R Diagram,
Full Source Code Listing and validation rules and convert EER Diagram into Relational
Model for implementation.

4. Chapter 4: Debugging and Testing: Present debugging and testing report for each
module and overall system.

5. Chapter 5: Results and Conclusions: Analyze the observations about results of the
project. Discuss why the specifications were not met or the reasons for the failure, if any.
Discussed the problems and difficulties encountered and how they were / can be
eliminated. Discuss any extension work or modifications, which you want to suggest.

6. Chapter 6: References: List the books, magazines and data manuals used.

6. Submission Process:
Student should prepare 1 copy of the Project Report. At the beginning, the
respective Project Guide must approve copy positively before the end examination.

Terna Engineering College, Nerul. 33

Potrebbero piacerti anche