You are on page 1of 5

Sushil Kulkarni 1

PPR
RAAC
CTTIIC
CAALLSS IIN
NAAD
DVVA
ANNC
CEED
DDDA
ATTA
ABBA
ASSEESS

1. Assume we have a global conceptual schema that contains the following table with the
key underlined: Employee(Eno,Ename,Title,Dno). Also assume that we horizontally
fragment the table as follows:

Employee1(Eno;Ename; Title;Dno), where 1 £ Dno £ 10


Employee2(Eno;Ename; Title;Dno), where 11 £ Dno £ 20
Employee3(Eno;Ename; Title;Dno), where 21 £ Dno £ 30

In addition, assume we have 4 sites that contain the following fragments:

Site1 has Employee1


Site2 has Employee2
Site3 has Employee2 and Employee3
Site4 has Employee1

Implement at least 5 suitable queries using oracle 9i on Employee fragments.

2. We are given the following three relations with their keys underlined:

Supplier( Sno,Sname,City,State)
Part( Pno,Pname,Color)
Supplier-Part( Sno,Pno,Qty).

We know that Suppliers can supply many Parts and many Suppliers can supply a Part.
Assume the Supplier table is horizontally fragmented using the predicates: State =
Maharashtra and State = Karnataka. We can also assume that Suppliers are evenly
located in only those two states. In addition, the Part table is horizontally fragmented
using the predicates: 1 £ Pno £ 100,101 £ Pno £ 200, 201 £ Pno £ 300, 301 £ Pno £
400, 401 £ Pno £ 500. Part numbers are continuous from 1 to 500, inclusive.

Now we are to horizontally fragment the Supplier- Part relation according to your
choice. Implement at least 5 suitable queries using oracle 9i.

3. The Oracle user Amar owns a database table named CarDealers. The table
contains some user-defined (complex) data types as attributes.

a. Identify the structure of the table CarDealers as well as the structure of all
its subcomponents (attributes). In order to identify the components
(attribute names and data types), use only queries against views of the
Oracle Data Dictionary. Give all SQL queries you state against the data
dictionary in order to obtain the information. Give also the result of each
query.

b. Create exactly the same table in your schema using Oracle9i-SQL. That
create the appropriate user-defined types first, and finally the table

Sushiltry@yahoo.co.in
Sushil Kulkarni 2

CarDealers. Give all create type and create table statements.

c. Give an insert statement that inserts a complete (complex-valued) tuple into


your table CarDealers.

d. Formulate a query against the table CarDealers owned by the user Amar.
The query has to list the names of car dealers who offer silver “ icon”. Data
dictionary views specific to object-relational features in Oracle9i.

4. Type the following code and answer the queries:

Drop table book;


Drop table author;
Drop table publisher;
Create or replace type AddrType as object(
Pincode number(5),
Street char(20),
City varchar2(50),
state varchar2(40),
no number(4) );

/ create or replace type BranchType as object(


address AddrType,
phone1 integer,
phone2 integer );
/
create or replace type BranchTableType as table of BranchType;
/
create or replace type AuthorType as object(
name varchar2(50),
addr AddrType );
/ create table authors of AuthorType;

create or replace type AuthorListType as varray(10) of ref


AuthorType;

/ create or replace type PublisherType as object(


name varchar2(50),
addr AddrType, branches BranchTableType);

/ create table Publishers of PublisherType NESTED TABLE branches


STORE as branchtable;

create table books(


title varchar2(50),
year date,
published_by ref PublisherType,
authors AuthorListType);

Now,

Sushiltry@yahoo.co.in
Sushil Kulkarni 3

AUTHOR(name, addr:<pincode,street,city,state,no>)

That is, address is the name of an object-valued attribute, which has five components.

PUBLISHERS(name, addr:<pincode,street,city,state,no>, branches:


set of <address:<pincode,street,city,state,no>,phone1,phone2> )

Addr again is an object-valued attribute. Branches is a complex-valued attribute, in this


case a nested table where each element in the table has three parts

(i) an address (which again is an object-valued attribute),


(ii) two phones.

BOOKS(title, year, published_by: ref<PUBLISHERS>, authors: list


of ref AUTHOR )

Published_by is a reference to elements of the table PUBLISHER; authors is a complex-


valued attribute, in this case a list of references to objects of the type author (which
are managed in the table AUTHOR).

Queries:

a) List all of the authors that have the same address as their publisher:

select a.name
from authors a, publishers p
where a.addr = p.addr;

b) List all of the authors that have the same pincode as their publisher:

select a.name
from authors a, publishers p
where a.addr.zipcode = p.addr.pincode;

c) List all books that have 2 or more authors:

select * from books b where 1 < (


select count(*)
from table(b.authors));

d) List the title of the book that has the most authors:

Select title
from books b, table(b.authors)
group by title
having count(*)
=
(select max(count(*))
from books b, table(b.authors)
group by title);

Sushiltry@yahoo.co.in
Sushil Kulkarni 4

In the first query, the list of authors for each book is unnested and tuples are
grouped by title (e.g., if a book has 5 authors, then there will be five tuples that
have the same title). Only the book that has the most authors is select (using the
having clause).

e) List the name of the publisher that has the most branches:

Select p.name
from publishers p, table(p.branches)
group by p.name having count(*)> =
all (select count(*)
from publishers p, table(p.branches)
group by name);

g) Name of authors who have not published a book:

select a.name
from authors a
where not exists(
select b.title
from books b, table(select authors
from books b1
where b.title = b1.title) a2
where a.name = name);

or
select a.name
from authors a
where not exists( select b.title
from books b, table(b.authors)
where a.name = name);

h) Move all the branches that belong to the publisher 'LittleHouse' to the publisher
‘‘PubHouse'

insert into table(


select branches
from publishers
where name = 'PubHouse')
select b.* from publishers p, table(p.branches) b
where name = 'LittleHouse';

i) List all authors who have published more than one book:

select a.name
from authors a, books b, table(b.authors) v
where v.column_value = ref(a)
group by a.name having count(*) > 1;

Sushiltry@yahoo.co.in
Sushil Kulkarni 5

j) Name of authors who have published books with at least two different publishers?

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

5. a. Create a table that contains at least one attribute of an image. Add at least 10
tuples in the table and write query to invoke a particular image.
b. Create a table that contains at least one attribute of an audio. Add at least 10
tuples in the table and write query to invoke a particular audio.
c. Create a table that contains at least one attribute of a video. Add at least 10 tuples
in the table and write query to invoke a particular video.

6. Create a table using Time DB to store data along with valid, transaction time and issue
at least 3 queries on it.

7. Create a table that store the special data and issue at least 3 queries

8. Formulate a database using active rules using row and statement level that include
STARTBUST notation.

Sushiltry@yahoo.co.in

You might also like