You are on page 1of 4

KRCT-M.E.

CSE 2013-2015 BATCH

CP7211 ADVANCED DATABASE LABORATORY AIM: To learn to work on distributed data bases.

DISTRIBUTED DATABASE: 1. Consider a distributed database for a bookstore with 4 sites called S1, S2, S3 and S4. Consider the following relations: Books ( ISBN, primary Author, topic, total Stock, price ) Book Store (store No, city, state, zip, inventoryValue ) Stock (store No, ISBN, Qty ) Total Stock is the total number of books in stock and inventory Value is the total inventory value for the store in dollars. Consider that Books are fragmented by price amounts into: F1: Books: price up to $20 F2: Books: price from $20.01 to $50 F3: Books: price from $50.01 to $100 F4: Books: price $100.01 and above Similarly, Book Stores are divided by ZIP codes into: S1: Bookstore: Zip up to 25000 S2: Bookstore: Zip 25001 to 50000 S3: Bookstore: Zip 50001 to 75000 S4: Bookstore: Zip 75001 to 99999 Task: Write SQL query for the following ALGORITHM: 1. Start the program. 2. Create a table Book with fields ISBN, primary Author, topic, total Stock, price. 3. Create a table Bookstore with store No, city, state, zip, inventory Value. 4. Create a table Stock store No, ISBN, Qty. 5. Find Total stock and inventory value. 6. Books are fragmented into F1, F2, F3 and F4 based on price amount. 7. Bookstores are divided into S1,S2,S3 and S4. 8. Insert value into each table 9. Find the total number of books in stock where price is between $15 and $55. 10. Update the book price of book No=1234 from $45 to $55 at site S3. 11. Find total number of book at site S2. 12. Display query output. 13. Stop the program

KRCT-M.E. CSE 2013-2015 BATCH

1. INSERT AND DISPLAY DETAILS IN EACH TABLE. create table books (isbn varchar(15),primaryauthor varchar(20),topic varchar(20),totalstock numeric(5),price numeric(6,2),primary key(isbn)); create table bookstore(store_no varchar(15),city varchar(20),state numeric(10,2),inventory_value numeric(6,2),primary key(store_no)); create table stock(store_no key(store_no,isbn)); varchar(15),isbn varchar(15),qty varchar(20),zip

numeric(20),primary

insert into books values('1231','william','network security','5','40'); insert into books values('1232','robert','programming language','8','100'); insert into books values('1233','richard','operating systems','7','50'); insert into books values('1234','jeffrey','databases','4','45'); select * from books;

insert into bookstore values('1','trichy','tamilnadu','40000','450'); insert into bookstore values('2','chennai','tamilnadu','50000','500'); insert into bookstore values('3','trivandrum','kerala','65000','850'); insert into bookstore values('4','mumbai','madhya pradesh','70000','600'); select * from bookstore;

KRCT-M.E. CSE 2013-2015 BATCH

insert into stock values('1','1231','45'); insert into stock values('2','1232','55'); insert into stock values('3','1233','65'); insert into stock values('4','1234','95'); select * from stock;

2. Find the total number of books in stock where price is between $15 and $55. select sum(totalstock) from books where price between 15 and 55;

KRCT-M.E. CSE 2013-2015 BATCH

3. Update the book price of book No=1234 from $45 to $55 at site S3. update books set price='55' where ISBN='1234';

4. Find total number of book at site S2. select sum(Qty) from stock,bookstore where stock.store_no=Bookstore.store_no and zip between '25001' and '50000';

Result: Thus the distributed data bases concepts using SQL Queries executed and verified successfully.

You might also like