ADB Lab Manual
ADB Lab Manual
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;
Syntax:
SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column1 = table2.column2;
• 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.
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.
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.
- pads those rows with NULL values for all the attributes from left relation ,
and add them to the result of the Natural join.
Conclusion:
This practical covers topics:
- How to use joins to display data from multiple tables.
- How to perform pattern matching operation.
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)
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;
- 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.
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
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.
< 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.
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.:
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
Conclusion:
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
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).
as distribution & high performance access. OODB are queried using a standard Object
Query Language (OQL).
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.
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.
Example:
CREATE TYPE Apartment AS OBJECT (
BuildingName VARCHAR2 (25),
ApartmentNo CHAR (4),
NumberBedRooms NUMBER (10));
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 6: VARRAY:
- Firstly create object to a Varray:
CREATE TYPE Apt_unit AS object (
AprtNo CHAR (5),
Nobedrooms INT );
- Table:
CREATE TABLE build1 (
BuildID NUMBER,
Name VARCHAR2 (50),
Units Apt_list1);
Conclusion:
Thus we learned Object-oriented concept, in that how to create UDT and define
data.
QUESTIONS:
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
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:
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.
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.
- Horizontal Fragmentation
- Vertical Fragmentation
- Mixed Fragmentation.
Examples:
MODULE: USES:
TID MODULE
T1 Query Processing
T2 User Interface
TID USES
T1 SORT
T2 SORT
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.
Conclusion:
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.
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.
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”.
Proposition 1:
Creating XMLType Tables and Columns Based on XML Schema:
Syntax:
Table created.
FROM PURCHASEORDER;
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.
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.
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
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.
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.
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:
2. Connect boss/boss
- Create table exp as select * from emp;
- Grant all on emp to public;
- Also grant all on exp to public;
7. Connect client/client;
Conclusion:
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:
For eg:
1. Basic Information
4. Design (EER Model), Development (EER model convert into Relational model),
Testing and Debugging of Prototypes one by one.
3. Detail Specifications:
- Certificate
- Contents:
1. Introduction
1.1 Background
1.2 Need for Work
1.3 Brief Idea
2.1 Operation
2.2 Objects
2.3 Properties
2.4 Methods
2.5 Events
3. Module Design
6. Reference
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.