5
Sushil Kulkarni 1 [email protected] P P R R A A C C T T I I C C A A L L S S I I N N A A D D V V A A N N C C E E D D D D A A T T A A B B A A S S E E S S 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

Advanced DBMS Concepts Practical

Embed Size (px)

Citation preview

Page 1: Advanced DBMS Concepts Practical

Sushil Kulkarni 1

[email protected]

PPPRRRAAACCCTTTIIICCCAAALLLSSS IIINNN AAADDDVVVAAANNNCCCEEEDDD DDDAAATTTAAABBBAAASSSEEESSS

1. Assume we have a global conceptual schema that contains the following table with thekey underlined: Employee(Eno,Ename,Title,Dno). Also assume that we horizontallyfragment 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 Employee1Site2 has Employee2

Site3 has Employee2 and Employee3Site4 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 evenlylocated in only those two states. In addition, the Part table is horizontally fragmentedusing 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 yourchoice. Implement at least 5 suitable queries using oracle 9i.

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

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

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

Page 2: Advanced DBMS Concepts Practical

Sushil Kulkarni 2

[email protected]

CarDealers. Give all create type and create table statements.

c. Give an insert statement that inserts a complete (complex-valued) tuple intoyour 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”. Datadictionary 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 refAuthorType;

/ create or replace type PublisherType as object( name varchar2(50),addr AddrType, branches BranchTableType);

/ create table Publishers of PublisherType NESTED TABLE branchesSTORE as branchtable;

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

Now,

Page 3: Advanced DBMS Concepts Practical

Sushil Kulkarni 3

[email protected]

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 thiscase 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: listof 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 (whichare managed in the table AUTHOR).

Queries:

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

select a.namefrom authors a, publishers pwhere 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 titlefrom books b, table(b.authors)group by titlehaving count(*)=(select max(count(*)) from books b, table(b.authors) group by title);

Page 4: Advanced DBMS Concepts Practical

Sushil Kulkarni 4

[email protected]

In the first query, the list of authors for each book is unnested and tuples aregrouped by title (e.g., if a book has 5 authors, then there will be five tuples thathave the same title). Only the book that has the most authors is select (using thehaving 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;

Page 5: Advanced DBMS Concepts Practical

Sushil Kulkarni 5

[email protected]

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 ofauthors (assuming that an integrity constraint requiring that the name of an authoris 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 10tuples 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 10tuples 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 tuplesin 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 issueat 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 includeSTARTBUST notation.