• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Create mca dbms

  • 303 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • can plz anybody upload the list of top colleges for MCA course in INDIA....
    desperately awaiting ....
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
303
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
1
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. DBMS _ LAB V semester SIR MVGSC CREATE TABLE CUSTOMER(CUST_NO NUMBER(5) PRIMARY KEY, CNAME VARCHAR2(10), CITY VARCHAR2(12)); INSERT INTO CUSTOMER VALUES(&CUST_NO,'&CNAME','&CITY'); CUST_NO CNAME CITY --------- ---------- ------------ 111 SHILPA MYSORE 222 SHANKAR DHARWAD 333 SHIVU MANDYA 444 ANJALI BANGALORE 555 BHAVYA MANGALORE 666 CHANDRU NAGPUR 777 BANU MUMBAI 888 GARIMA DELHI 999 MANU CHENNAI 1010 KANNA KASHMIR ------------------------------------------------------------------- CREATE TABLE OORDER(ORDER_NO NUMBER(5) PRIMARY KEY, ODATE DATE, CUST_NO REFERENCES CUSTOMER, ORD_AMT NUMBER(6)); INSERT INTO OORDER VALUES(&ORDER_NO,'&ODATE',&CUST_NO,&ORD_AMT); ORDER_NO ODATE CUST_NO ORD_AMT --------- --------- --------- --------- 100 23-FEB-02 111 10000 200 16-APR-01 111 25000 300 22-FEB-01 222 12000 400 23-FEB-00 333 5000 500 16-APR-03 333 9000 600 22-FEB-03 444 15000 700 23-FEB-02 555 20000 800 16-APR-04 666 8000 900 23-FEB-01 777 18000 1000 16-JAN-04 888 22000 ------------------------------------------------------------------------ CREATE TABLE ORDER_ITEM(ORDER_NO REFERENCES OORDER, ITEM_NO REFERENCES ITEM ON DELETE CASCADE, QTY NUMBER(5)); INSERT INTO ORDER_ITEM VALUES(&ORDER_NO,&ITEM_NO,&QTY); ORDER_NO ITEM_NO QTY --------- --------- --------- 100 2121 500 200 2121 400 300 2222 250 400 2323 200 1
  • 2. DBMS _ LAB V semester SIR MVGSC 500 2323 150 600 2424 100 700 2525 150 1000 2828 350 ------------------------------------------------------------------- CREATE TABLE ITEM(ITEM_NO NUMBER(5) PRIMARY KEY, WAREHOUSE_NO REFERENCES WAREHOUSE, SHIP_DATE DATE); INSERT INTO ITEM VALUES(&ITEM_NO,&WAREHOUSE_NO,'&SHIP_DATE'); ITEM_NO WAREHOUSE_NO SHIP_DATE --------- ------------ --------- 2121 1111 12-JAN-02 2222 1111 01-DEC-03 2323 1111 06-SEP-01 2424 1212 03-AUG-02 2525 1212 05-OCT-01 2626 1212 15-JAN-01 2727 1313 22-FEB-00 2828 1414 30-NOV-03 2929 1515 10-JUN-03 ------------------------------------------------------------------- CREATE TABLE WAREHOUSE(WAREHOUSE_NO NUMBER(5) PRIMARY KEY, CITY VARCHAR2(12)); INSERT INTO WAREHOUSE VALUES(&WAREHOUSE_NO,'&CITY'); WAREHOUSE_NO CITY ------------ ------------ 1111 MYSORE 1212 BANGALORE 1313 MYSORE 1414 BANGALORE 1515 MANGALORE 1616 MANGALORE 1717 MYSORE 1818 BANGALORE 1919 MANGALORE 2020 MYSORE -------------------------------------------------------------------- CUSTOMER: ORDER: ORDER_ITEM: --------- ------ ----------- CUST_NO CNAME CITY | ORDER_NO ODATE CUST_NO ORD_AMT | ORDER_NO ITEM_NO QTY --------- ------ ---------- | --------- ----- -------- ------ | -------- ------- --- 111 SHILPA MYSORE |100 23-FEB-02 111 10000 |100 2121 500 222 SHANKAR DHARWAD |200 16-APR-01 111 25000 |200 2121 400 333 SHIVU MANDYA | 300 22-FEB-01 222 12000 |300 2
  • 3. DBMS _ LAB V semester SIR MVGSC 2222 250 444 ANJALI BANGALORE |400 23-FEB-00 333 5000 |400 2323 200 555 BHAVYA MANGALORE |500 16-APR-03 333 9000 |500 2323 150 666 CHANDRU NAGPUR |600 22-FEB-03 444 15000 |600 2424 100 777 BANU MUMBAI |700 23-FEB-02 555 20000 |700 2525 150 888 GARIMA DELHI |800 16-APR-04 666 8000 |1000 2828 350 999 MANU CHENNAI |900 23-FEB-01 777 1800 | 1010 KANNA KASHMIR |1000 16-JAN-04 888 22000 | ---------------------------------------------------------------------- ITEM WAREHOUSE ----- --------- ITEM_NO WAREHOUSE_NO SHIP_DATE| WAREHOUSE_NO CITY ------- ------------ ---------| ------------ ---- 2121 1111 12-JAN-02 | 1111 MYSORE 2222 1111 01-DEC-03 | 1212 BANGALORE 2323 1111 06-SEP-01 | 1313 MYSORE 2424 1212 03-AUG-02 | 1414 BANGALORE 2525 1212 05-OCT-01 | 1515 MANGALORE 2626 1212 15-JAN-01 | 1616 MANGALORE 2727 1313 22-FEB-00 | 1717 MYSORE 2828 1414 30-NOV-03 | 1818 BANGALORE 2929 1515 10-JUN-03 | 1919 MANGALORE | 2020 MYSORE ------------------------------------------------------------------------ QUERIES: -------- (iii) SELECT CNAME,COUNT(ORDER_NO) CNT,AVG(ORD_AMT) AVG FROM CUSTOMER,OORDER WHERE CUSTOMER.CUST_NO=OORDER.CUST_NO GROUP BY CNAME; (iv) SELECT COUNT(*) FROM WAREHOUSE WHERE WAREHOUSE_NO IN (SELECT WAREHOUSE_NO FROM ITEM WHERE ITEM_NO IN (SELECT ITEM_NO FROM ORDER_ITEM WHERE ORDER_NO IN (SELECT ORDER_NO FROM OORDER WHERE CUST_NO IN (SELECT CUST_NO FROM CUSTOMER WHERE CITY IN (SELECT CITY FROM CUSTOMER GROUP BY CITY))))); (v) DELETE FROM ITEM WHERE ITEM_NO=3030; CREATE TABLE PERSON(DRIVER_ID VARCHAR2(5) PRIMARY KEY, NAME VARCHAR2(10), ADDRESS VARCHAR2(15)); INSERT INTO PERSON VALUES('&DRIVER_ID','&NAME','&ADDRESS'); DRIVE NAME ADDRESS 3
  • 4. DBMS _ LAB V semester SIR MVGSC ----- ---------- --------------- D111 SHILPA MYSORE D222 SHANKAR MYSORE D333 SHIVU MYSORE D444 ANJALI MYSORE D555 BHAVYA MYSORE D666 BANU MYSORE D777 GARIMA MYSORE D888 MANU MYSORE D999 CHANDRU MYSORE D1111 VIVEK MYSORE ---------------------------------------------------------------------- CREATE TABLE CAR(REGNO VARCHAR2(10) PRIMARY KEY, MODEL VARCHAR2(10), YEAR NUMBER(4)); INSERT INTO CAR VALUES('&REGNO','&MODEL',&YEAR); REGNO MODEL YEAR ---------- ---------- --------- KA09-S-383 SONATA 2004 KA09-S-735 MERCEDES 2000 KA09-S-200 MARUTI 2002 KA09-A-782 ESTEEM 2003 KA09-V-642 SANTRO 2003 KA09-R-710 SONATA 2002 KA09-G-421 MARUTI 2002 KA09-X-111 SANTRO 2004 KA09-D-478 ESTEEM 2001 KA09-G-564 SONATA 2003 ----------------------------------------------------------------------- CREATE TABLE ACCIDENT(REPORT_NO NUMBER(5) PRIMARY KEY, ODATE DATE, LOCATION VARCHAR2(12)); INSERT INTO ACCIDENT VALUES(&REPORT_NO,'&ODATE','&LOCATION'); REPORT_NO ODATE LOCATION --------- --------- ------------ 10 23-FEB-02 MYSORE 11 16-APR-02 DHARWAD 12 22-FEB-02 MANDYA 13 22-FEB-01 BANGALORE 14 22-FEB-03 MANGALORE 15 16-APR-01 MYSORE 16 22-FEB-00 NAGPUR 17 22-FEB-02 MUMBAI 18 16-APR-03 DELHI 19 22-FEB-04 CHENNAI 20 02-JAN-00 KASHMIR ------------------------------------------------------------------- CREATE TABLE OWNS(DRIVER_ID REFERENCES PERSON, 4
  • 5. DBMS _ LAB V semester SIR MVGSC REGNO REFERENCES CAR); INSERT INTO OWNS VALUES('&DRIVER_ID','&REGNO'); DRIVE REGNO ----- ---------- D111 KA09-S-383 D111 KA09-S-735 D222 KA09-S-200 D222 KA09-A-782 D333 KA09-V-642 D444 KA09-R-710 D555 KA09-G-421 D888 KA09-X-111 D999 KA09-D-478 D1111 KA09-G-564 --------------------------------------------------------------------- CREATE TABLE PARTICIPATED(DRIVER_ID REFERENCES PERSON, REGNO REFERENCES CAR, REPORT_NO REFERENCES ACCIDENT, DAMAGE_AMT NUMBER(6)); INSERT INTO PARTICIPATED VALUES('&DRIVER_ID','&REGNO',&REPORT_NO,&DAMAGE_AMT); DRIVE REGNO REPORT_NO DAMAGE_AMT ----- ---------- --------- ---------- D111 KA09-S-383 10 0 D111 KA09-S-735 11 0 D222 KA09-S-200 12 0 D222 KA09-A-782 13 0 D333 KA09-V-642 14 0 D444 KA09-R-710 15 0 D555 KA09-G-421 16 0 D888 KA09-X-111 17 0 D999 KA09-D-478 18 0 D1111 KA09-G-564 19 0 ---------------------------------------------------------------------- PERSON CAR ACCIDENT ------ --- -------- DRIVE NAME ADDRESS | REGNO MODEL YEAR |REPORT_NO ODATE LOCATION ----- ------- ------- | ----- ----- ---- |--------- ----- -------- D111 SHILPA MYSORE |KA09-S-383 SONATA 2004 | 10 23-FEB-02 MYSORE D222 SHANKAR MYSORE |KA09-S-735 MERCEDES 2000 | 11 16-APR-02 DHARWAD D333 SHIVU MYSORE |KA09-S-200 MARUTI 2002 | 12 22-FEB-02 MANDYA D444 ANJALI MYSORE |KA09-A-782 ESTEEM 2003 | 13 22-FEB-01 BANGALORE D555 BHAVYA MYSORE |KA09-V-642 SANTRO 2003 | 14 22-FEB-03 MANGALORE 5
  • 6. DBMS _ LAB V semester SIR MVGSC D666 BANU MYSORE |KA09-R-710 SONATA 2002 | 15 16-APR-01 MYSORE D777 GARIMA MYSORE |KA09-G-421 MARUTI 2002 | 16 22-FEB-00 NAGPUR D888 MANU MYSORE |KA09-X-111 SANTRO 2004 | 17 22-FEB-02 MUMBAI D999 CHANDRU MYSORE |KA09-D-478 ESTEEM 2001 | 18 16-APR-03 DELHI D1111 VIVEK MYSORE |KA09-G-564 SONATA 2003 | 19 22-FEB-04 CHENNAI | | 20 02-JAN-00 KASHMIR -------------------------------------------------------------------------- OWNS PARTICIPATED ---- ------------ DRIVE REGNO |DRIVE REGNO REPORT_NO DAMAGE_AMT ----- ---------- |----- ----- --------- ----------- D111 KA09-S-383 |D111 KA09-S-383 10 0 D111 KA09-S-735 |D111 KA09-S-735 11 0 D222 KA09-S-200 |D222 KA09-S-200 12 0 D222 KA09-A-782 |D222 KA09-A-782 13 0 D333 KA09-V-642 |D333 KA09-V-642 14 0 D444 KA09-R-710 |D444 KA09-R-710 15 0 D555 KA09-G-421 |D555 KA09-G-421 16 0 D888 KA09-X-111 |D888 KA09-X-111 17 0 D999 KA09-D-478 |D999 KA09-D-478 18 0 D1111 KA09-G-564 |D1111 KA09-G-564 19 0 -------------------------------------------------------------------------- QUERIES: ------- (iii a) UPDATE PARTICIPATED SET DAMAGE_AMT=25000 WHERE REGNO='KA09-S-200' AND REPORT_NO=12; (iii b) INSERT INTO ACCIDENT VALUES(&REPORT_NO,'&ODATE','&LOCATION'); (iv) SELECT COUNT(*) FROM PERSON WHERE DRIVER_ID IN (SELECT DRIVER_ID FROM OWNS WHERE REGNO IN (SELECT REGNO FROM PARTICIPATED WHERE REPORT_NO IN (SELECT REPORT_NO FROM ACCIDENT WHERE ODATE IN (SELECT ODATE FROM ACCIDENT WHERE ODATE > '31-DEC-2001' AND ODATE < '1-JAN-2003')))); (v) SELECT COUNT(*) FROM ACCIDENT WHERE REPORT_NO IN (SELECT REPORT_NO FROM PARTICIPATED WHERE REGNO IN (SELECT REGNO FROM CAR WHERE MODEL='ESTEEM')); CREATE TABLE STUDENT(REGNO VARCHAR2(10) PRIMARY KEY, NAME VARCHAR2(10), MAJOR VARCHAR2(8), BDATE DATE); INSERT INTO STUDENT VALUES('&REGNO','&NAME','&MAJOR','&BDATE'); 6
  • 7. DBMS _ LAB V semester SIR MVGSC REGNO NAME MAJOR BDATE ---------- ---------- ------------------------- --------- MCA20 SHILPA OPERATING SYSTEM 23-FEB-02 MCA21 SHANKAR GRAPHICS 16-APR-04 MCA22 SHIVU SYSTEM PROGRAMMING 22-FEB-02 MCA1 ANJALI COMP TECH 01-JAN-00 MCA5 BHAVYA PROG LANG 05-DEC-00 ACC1 BANU ACCOUNTANCY 13-AUG-01 ACC2 GARIMA FINANCIAL MGT 27-NOV-03 ACC3 CHANDRU PERSONAL MGT 24-JUN-99 ENG4 MANU MECH ENG 06-NOV-86 MTECH6 KANNA ELECTRICAL ENG 21-JUL-94 --------------------------------------------------------------------------- CREATE TABLE COURSE(COURSE_NO NUMBER(5) PRIMARY KEY, CNAME VARCHAR2(10), DEPT VARCHAR2(10)); INSERT INTO COURSE VALUES(&COURSE_NO,'&CNAME','&DEPT'); COURSE_NO CNAME DEPT --------- ---------- ---------- 10 MCA CS-DEPT 11 MBA ACC-DEPT 12 ENG ENG-DEPT 14 BSC BSC-DEPT 13 MTECH CS-DEPT --------------------------------------------------------------------------- CREATE TABLE ENROLL(REGNO REFERENCES STUDENT, COURSE_NO REFERENCES COURSE, SEM NUMBER(2) NOT NULL, MARKS NUMBER(4)); INSERT INTO ENROLL VALUES('&REGNO',&COURSE_NO,&SEM,&MARKS); REGNO COURSE_NO SEM MARKS ---------- --------- --------- --------- MCA20 10 1 500 MCA21 10 1 500 MCA22 10 1 600 ACC1 11 3 400 ACC2 11 1 450 ENG4 12 5 600 MTECH6 13 4 450 --------------------------------------------------------------------------- CREATE TABLE TEXT(BOOK_ISBN NUMBER(5) PRIMARY KEY, BOOK_TITLE VARCHAR2(15), PUBLISHER VARCHAR2(25), AUTHOR VARCHAR2(10)); INSERT INTO TEXT VALUES(&BOOK_ISBN,'&BOOK_TITLE','&PUBLISHER','&AUTHOR'); 7
  • 8. DBMS _ LAB V semester SIR MVGSC BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR --------- --------------- ------------------------- ---------- 100 C SSS SHILPA 200 C++ AAA SHANKAR 300 JAVA BBB SHIVU 400 ORACLE SSS ANJALI 500 VB AAA BHAVYA 600 MIS SSS BANU 700 TALLY BBB GARIMA 800 ADA AAA KANNA 900 DBMS BBB KANNA ----------------------------------------------------------------------------- CREATE TABLE BOOK_ADOPTION(COURSE_NO REFERENCES COURSE, SEM NUMBER(2) NOT NULL, BOOK_ISBN REFERENCES TEXT); INSERT INTO BOOK_ADOPTION VALUES(&COURSE_NO,&SEM,&BOOK_ISBN); COURSE_NO SEM BOOK_ISBN --------- --------- --------- 10 1 100 10 1 200 10 1 500 11 3 600 11 4 900 12 1 200 13 4 700 --------------------------------------------------------------------------- STUDENT COURSE ENROLL ------- ------- ------- REGNO NAME MAJOR BDATE |COURSE_NO CNAME DEPT |REGNO COURSE_NO SEM MARKS ------ ------- ------------------ ---------|--------- ----- ---- |----- --------- --- ----- MCA20 SHILPA OPERATING SYSTEM 23-FEB-02| 10 MCA CS-DEPT |MCA20 10 1 500 MCA21 SHANKAR GRAPHICS 16-APR-04| 11 MBA ACC-DEPT|MCA21 10 1 500 MCA22 SHIVU SYSTEM PROGRAMMING 22-FEB-02| 12 ENG ENG-DEPT|MCA22 10 1 600 MCA1 ANJALI COMP TECH 01-JAN-00| 14 BSC BSC-DEPT|ACC1 11 3 400 MCA5 BHAVYA PROG LANG 05-DEC-00| 13 MTECH CS-DEPT |ACC2 11 1 450 ACC1 BANU ACCOUNTANCY 13-AUG-01| |ENG4 12 5 600 ACC2 GARIMA FINANCIAL MGT 27-NOV-03| |MTECH6 13 4 450 ACC3 CHANDRU PERSONAL MGT 24-JUN-99| | ENG4 MANU MECH ENG 06-NOV-86| | MTECH6 KANNA ELECTRICAL ENG 21-JUL-94| | 8
  • 9. DBMS _ LAB V semester SIR MVGSC ---------------------------------------------------------------------------- TEXT BOOK_ADOPTION ---- ------------- BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR |COURSE_NO SEM BOOK_ISBN --------- ---------- --------- ------- |--------- --- ---------- 100 C SSS SHILPA | 10 1 100 200 C++ AAA SHANKAR | 10 1 200 300 JAVA BBB SHIVU | 10 1 500 400 ORACLE SSS ANJALI | 11 3 600 500 VB AAA BHAVYA | 11 4 900 600 MIS SSS BANU | 12 1 200 700 TALLY BBB GARIMA | 13 4 700 800 ADA AAA KANNA | 900 DBMS BBB KANNA | ---------------------------------------------------------------------------- QUERIES: -------- SELECT DEPT FROM COURSE WHERE COURSE_NO IN (SELECT COURSE_NO FROM COURSE WHERE COURSE_NO IN (SELECT COURSE_NO FROM BOOK_ADOPTION WHERE BOOK_ISBN IN (SELECT BOOK_ISBN FROM TEXT WHERE PUBLISHER IN (SELECT PUBLISHER FROM TEXT GROUP BY PUBLISHER)))); CREATE VIEW S AS SELECT DISTINCT COURSE_NO,COUNT(TEXT.BOOK_ISBN)BOOK_NO,BOOK_TITLE FROM BOOK_ADOPTION,TEXT WHERE BOOK_ADOPTION.BOOK_ISBN=TEXT.BOOK_ISBN AND COURSE_NO IN (SELECT COURSE_NO FROM COURSE WHERE DEPT='CS-DEPT') GROUP BY TEXT.BOOK_TITLE,COURSE_NO; SELECT COURSE_NO FROM S GROUP BY COURSE_NO HAVING COUNT(COURSE_NO)>2; CREATE TABLE BRANCH(BRANCH_NAME VARCHAR2(20) PRIMARY KEY,BRANCH_CITY VARCHAR2(20),ASSETS REAL); CREATE TABLE ACCOUNT(ACCNO INT PRIMARY KEY,BRANCH_NAME REFERENCES BRANCH ON DELETE CASCADE,BALA NCE REAL); CREATE TABLE DEPOSITOR(NAME VARCHAR2(20) NOT NULL,ACCNO REFERENCES ACCOUNT ON DELETE CASCADE); CREATE TABLE CUSTOMER(NAME VARCHAR2(20) NOT NULL,STREET VARCHAR2(20),CITY VARCHAR2(20)); CREATE TABLE LOAN(LOAN_NO INT PRIMARY KEY,BRANCH_NAME REFERENCES BRANCH ON DELETE CASCADE,AMOUNT REAL); CREATE TABLE BORROWER(NAME VARCHAR2(20),LOAN_NO REFERENCES LOAN ON DELETE CASCADE); 9
  • 10. DBMS _ LAB V semester SIR MVGSC 1: INSERT INTO BRANCH VALUES('&N','&C','&A') 1: INSERT INTO BRANCH VALUES('SNAGAR','TUMKUR','35000000') SELECT * FROM BRANCH; BRANCH_NAME BRANCH_CITY ASSETS -------------------- -------------------- --------- SSPURAM MYSORE 1000000 JLPURAM MYSORE 2000000 JNAGAR MYSORE 300000 JPNAGAR MYSORE 400000 RNAGAR BANGALORE 500000 GNAGAR BANGALORE 6000000 ANAGAR TUMKUR 7.655E+09 SNAGAR TUMKUR 35000000 8 rows selected. 1: INSERT INTO ACCOUNT VALUES(&N,'&B','&A') 1: INSERT INTO ACCOUNT VALUES(802,'SNAGAR','600000') SELECT * FROM ACCOUNT; ACCNO BRANCH_NAME BALANCE --------- -------------------- --------- 100 SSPURAM 25000 101 SSPURAM 20000 103 SSPURAM 30000 102 SSPURAM 5000 104 SSPURAM 45000 105 SSPURAM 3000 106 SSPURAM 2000 200 JLPURAM 3000 201 JLPURAM 3000 202 JLPURAM 4000 203 JLPURAM 5000 204 JLPURAM 6000 205 JLPURAM 6000 300 JNAGAR 1000 301 JNAGAR 2000 302 JNAGAR 3000 303 JNAGAR 4000 304 JNAGAR 5000 305 JNAGAR 8000 400 JPNAGAR 1000 401 JPNAGAR 2000 ACCNO BRANCH_NAME BALANCE --------- -------------------- --------- 402 JPNAGAR 4000 403 JPNAGAR 4000 404 JPNAGAR 5000 500 RNAGAR 500000 10
  • 11. DBMS _ LAB V semester SIR MVGSC 501 RNAGAR 30000 502 RNAGAR 400000 600 GNAGAR 30000 601 GNAGAR 60000 602 GNAGAR 6000 603 GNAGAR 50000 700 ANAGAR 5000 701 ANAGAR 50000 702 ANAGAR 5888 800 SNAGAR 500 801 SNAGAR 90000 802 SNAGAR 600000 37 rows selected. 1: INSERT INTO DEPOSITOR VALUES('&N',&A) 1: INSERT INTO DEPOSITOR VALUES('RAJU',501) SELECT * FROM DEPOSITOR; NAME ACCNO -------------------- --------- SHILPA 100 SHILPA 200 SHILPA 300 SHILPA 400 SHILPA 104 SHILPA 105 SHILPA 204 SHIVU 101 SHIVU 201 SHIVU 301 SHIVU 401 SHIVU 106 SHIVU 205 SHANKAR 102 SHANKAR 202 ANJALI 302 ANJALI 402 BHAVYA 103 BHAVYA 203 BHAVYA 303 BHAVYA 403 NAME ACCNO -------------------- --------- BHAVYA 404 BHAVYA 304 AISH 600 AISH 601 AISH 603 AISH 502 DIVYA 500 DIVYA 603 DIVYA 801 RAJU 700 RAJU 800 11
  • 12. DBMS _ LAB V semester SIR MVGSC RAJU 501 33 rows selected. SELECT * FROM LOAN; LOAN_NO BRANCH_NAME AMOUNT --------- -------------------- --------- 1000 SSPURAM 2000 1001 SSPURAM 20000 1003 SSPURAM 3000 2000 JLPURAM 5000 2001 JLPURAM 4000 3000 JNAGAR 5000 6000 GNAGAR 500000 60001 GNAGAR 6000 8000 SNAGAR 50000 1: INSERT INTO BORROWER VALUES('&N',&N) 1: INSERT INTO BORROWER VALUES('RAJU',8000) SELECT * FROM BORROWER; NAME LOAN_NO -------------------- --------- SHILPA 1000 SHIVU 1001 SHANKAR 1003 SHILPA 2000 BHAVYA 2001 AISH 6000 AISH 60001 RAJU 8000 8 rows selected. 3)Query SELECT DISTINCT * FROM(SELECT CUSTOMER_NAME,BRANCH_NAME,COUNT(CUSTOMER_NAME)CNT FROM ACCOUNT,DEPOSITOR WHERE ACCOUNT.ACCNO=DEPOSITOR.ACCNO GROUP BY CUSTOMER_NAME, BRANCH_NAME)WHERE CNT>=2; NAME BRANCH_NAME CNT -------------------- -------------------- --------- AISH GNAGAR 3 BHAVYA JNAGAR 2 BHAVYA JPNAGAR 2 SHILPA JLPURAM 2 SHILPA SSPURAM 3 SHIVU JLPURAM 2 SHIVU SSPURAM 2 7 rows selected. SELECT * FROM(SELECT 12
  • 13. DBMS _ LAB V semester SIR MVGSC C.NAME,A.BRANCH_NAME,B.BRANCH_CITY,COUNT(C.NAME) CNT FROM ACCOUNT A,BRANCH B,DEPOSITOR C WHERE A.ACCNO=C.ACCNO AND B.BRANCH_NAME=A.BRANCH_NAME GROUP BY C.NAME,A.BRANCH_NAME,B.BRANCH_CITY)WHERE CNT>=2; NAME BRANCH_NAME BRANCH_CITY CNT -------------------- -------------------- -------------------- --------- AISH GNAGAR BANGALORE 3 BHAVYA JNAGAR MYSORE 2 BHAVYA JPNAGAR MYSORE 2 SHILPA JLPURAM MYSORE 2 SHILPA SSPURAM MYSORE 3 SHIVU JLPURAM MYSORE 2 SHIVU SSPURAM MYSORE 2 4)Query SELECT C.NAME,B.BRANCH_NAME,COUNT(*)NAM FROM ACCOUNT A,CUSTOMER C,DEPOSITOR D,BRANCH B WHERE A.ACCNO=D.ACCNO AND B.BRANCH_NAME=A.BRANCH_NAME AND C.NAME=D.NAME AND BRANCH_CITY='MYSORE'GROUP BY C.NAME,B.BRANCH_NAME; NAME BRANCH_NAME NAM -------------------- -------------------- --------- ANJALI JNAGAR 1 ANJALI JPNAGAR 1 BHAVYA JLPURAM 1 BHAVYA JNAGAR 2 BHAVYA JPNAGAR 2 BHAVYA SSPURAM 1 SHANKAR JLPURAM 1 SHANKAR SSPURAM 1 SHILPA JLPURAM 2 SHILPA JNAGAR 1 SHILPA JPNAGAR 1 SHILPA SSPURAM 3 SHIVU JLPURAM 2 SHIVU JNAGAR 1 SHIVU JPNAGAR CREATE TABLE AUTHOR(AUTHOR_ID NUMBER(6) PRIMARY KEY, NAME VARCHAR2(10), CITY VARCHAR2(14), COUNTRY VARCHAR2(10)); INSERT INTO AUTHOR VALUES(&AUTHOR_ID,'&NAME','&CITY','&COUNTRY'); 13
  • 14. DBMS _ LAB V semester SIR MVGSC AUTHOR_ID NAME CITY COUNTRY --------- ---------- -------------- ---------- 1 SHILPA MYSORE INDIA 2 SHANKAR MYSORE INDIA 3 SHIVU MYSORE INDIA 4 ANJALI BANGALORE INDIA 5 BHAVYA BANGALORE INDIA 6 BANU DELHI INDIA 7 GARIMA DELHI INDIA 8 CHANDRU MUMBAI INDIA 9 MANU MUMBAI INDIA 10 KANNA DELHI INDIA ------------------------------------------------------------------------------------------------ CREATE TABLE PUBLISHER(PUBLISHER_ID NUMBER(6) PRIMARY KEY, NAME VARCHAR2(10), CITY VARCHAR2(14), COUNTRY VARCHAR2(10)); INSERT INTO PUBLISHER VALUES(&PUBLISHER_ID,'&NAME','&CITY','&COUNTRY'); PUBLISHER_ID NAME CITY COUNTRY ------------ ---------- -------------- ---------- 11 SSS MYSORE INDIA 22 SSS BANGALORE INDIA 33 SSS MYSORE INDIA 44 AAA MYSORE INDIA 55 BBB DELHI INDIA 66 AAA MUMBAI INDIA 77 BBB CHENNAI INDIA 88 SSS DELHI INDIA 99 SSS MUMBAI INDIA ------------------------------------------------------------------------------------------------ CREATE TABLE CATALOG(BOOK_ID NUMBER(6) PRIMARY KEY, TITLE VARCHAR2(20), AUTHOR_ID REFERENCES AUTHOR, PUBLISHER_ID REFERENCES PUBLISHER, CATEGORY_ID REFERENCES CATEGORY, YEAR NUMBER(4), PRICE NUMBER(6)); INSERT INTO CATALOG VALUES(&BOOK_ID,'&TITLE',&AUTHOR_ID,&PUBLISHER_ID,&CATEGORY_ID, &YEAR,&PRICE); BOOK_ID TITLE AUTHOR_ID PUBLISHER_ID CATEGORY_ID YEAR PRICE --------- -------------------- --------- ------------ ----------- --------- --------- 10 IWP 1 11 111 14
  • 15. DBMS _ LAB V semester SIR MVGSC 2000 500 20 MIS 3 44 555 2000 300 30 TD 4 55 888 2001 400 40 SOM 7 88 666 2003 250 50 GRAPHICS 9 88 222 2002 300 60 LD 5 77 333 2001 400 70 IM 4 55 444 1999 300 80 DRAWING 2 77 777 2000 250 90 ENV_ENG 8 11 999 2001 300 100 CT 1 22 111 2000 350 110 CN 1 33 222 2000 400 120 MP 5 66 444 2000 600 ------------------------------------------------------------------------------------------------ CREATE TABLE CATEGORY(CATEGORY_ID NUMBER(5) PRIMARY KEY, DESCRIPTION VARCHAR2(20)); INSERT INTO CATEGORY VALUES(&CATEGORY_ID,'&DESCRIPTION'); CATEGORY_ID DESCRIPTION ----------- -------------------- 111 CS 222 MECH 333 ELECTRONICS 444 IP 555 IS 666 CIVIL 777 IT 888 ELECTRICAL 999 ENV ------------------------------------------------------------------------------------------------ CREATE TABLE ORDER_DETAILS(ORDER_NO NUMBER(5) PRIMARY KEY, BOOK_ID REFERENCES CATALOG, QUANTITY NUMBER(6)); INSERT INTO ORDER_DETAILS VALUES(&ORDER_NO,&BOOK_ID,&QUANTITY); ORDER_NO BOOK_ID QUANTITY --------- --------- --------- 51 10 50 52 20 60 15
  • 16. DBMS _ LAB V semester SIR MVGSC 53 30 40 54 40 100 55 50 170 56 60 200 57 70 150 58 80 230 59 90 210 ------------------------------------------------------------------------------------------------ AUTHOR PUBLISHER CATREGORY ------- ---------- ---------- A_ID NAME CITY COUNTRY |P_ID NAME CITY COUNTRY|CATEGORY_ID DESCRIPTION ---- ------- --------- ------- |---- ---- ---- -------|----------- ----------- 1 SHILPA MYSORE INDIA | 11 SSS MYSORE INDIA| 111 CS 2 SHANKAR MYSORE INDIA | 22 SSS BANGALORE INDIA| 222 MECH 3 SHIVU MYSORE INDIA | 33 SSS MYSORE INDIA| 333 ELECTRONICS 4 ANJALI BANGALORE INDIA | 44 AAA MYSORE INDIA| 444 IP 5 BHAVYA BANGALORE INDIA | 55 BBB DELHI INDIA| 555 IS 6 BANU DELHI INDIA | 66 AAA MUMBAI INDIA| 666 CIVIL 7 GARIMA DELHI INDIA | 77 BBB CHENNAI INDIA| 777 IT 8 CHANDRU MUMBAI INDIA | 88 SSS DELHI INDIA| 888 ELECTRICAL 9 MANU MUMBAI INDIA | 99 SSS MUMBAI INDIA| 999 ENV 10 KANNA DELHI INDIA | | ------------------------------------------------------------------------------------------------ CATALOG ORDER_DETAILS ------- ------------- BOOK_ID TITLE A_ID P_ID C_ID YEAR PRICE|ORDER_NO BOOK_ID QUANTITY ------- --------- ---- ----- ---- ----- -----|-------- ------- --------- 10 IWP 1 11 111 2000 500 | 51 10 50 20 MIS 3 44 555 2000 300 | 52 20 60 30 TD 4 55 888 2001 400 | 53 30 40 40 SOM 7 88 666 2003 250 | 54 40 100 50 GRAPHICS 9 88 222 2002 300 | 55 50 170 60 LD 5 77 333 2001 400 | 56 60 200 70 IM 4 55 444 1999 300 | 57 70 150 80 DRAWING 2 77 777 2000 250 | 58 80 230 90 ENV_ENG 8 11 999 2001 300 | 59 90 210 16
  • 17. DBMS _ LAB V semester SIR MVGSC 100 CT 1 22 111 2000 350 | 110 CN 1 33 222 2000 400 | 120 MP 5 66 444 2000 600 | ------------------------------------------------------------------------------------------------ QUERIES: -------- (iii) SELECT NAME FROM AUTHOR WHERE AUTHOR_ID IN (SELECT AUTHOR_ID FROM CATALOG WHERE BOOK_ID IN (SELECT BOOK_ID FROM ORDER_DETAILS WHERE QUANTITY IN (SELECT MAX(QUANTITY) FROM ORDER_DETAILS))); (ii) SELECT * FROM AUTHOR WHERE AUTHOR_ID IN (SELECT AUTHOR_ID FROM CATALOG WHERE PRICE IN (SELECT PRICE FROM CATALOG WHERE PRICE > (SELECT AVG(PRICE) FROM CATALOG) AND YEAR=2000) GROUP BY AUTHOR_ID HAVING COUNT(AUTHOR_ID) >=2); (v) SELECT PRICE,PRICE*0.1 INC,PRICE+PRICE*0.1 TOTAL FROM CATALOG WHERE PUBLISHER_ID IN (SELECT PUBLISHER_ID FROM PUBLISHER WHERE NAME='SSS'); CREATE TABLE PERSON(DRIVER_ID VARCHAR2(5) PRIMARY KEY, NAME VARCHAR2(10), ADDRESS VARCHAR2(15)); INSERT INTO PERSON VALUES('&DRIVER_ID','&NAME','&ADDRESS'); DRIVE NAME ADDRESS ----- ---------- --------------- D111 SHILPA MYSORE D222 SHANKAR MYSORE D333 SHIVU MYSORE D444 ANJALI MYSORE D555 BHAVYA MYSORE D666 BANU MYSORE D777 GARIMA MYSORE D888 MANU MYSORE D999 CHANDRU MYSORE D1111 VIVEK MYSORE ------------------------------------------------------------------------------------------------ CREATE TABLE CAR(REGNO VARCHAR2(10) PRIMARY KEY, MODEL VARCHAR2(10), YEAR NUMBER(4)); INSERT INTO CAR VALUES('&REGNO','&MODEL',&YEAR); REGNO MODEL YEAR ---------- ---------- --------- KA09-S-383 SONATA 2004 KA09-S-735 MERCEDES 2000 KA09-S-200 MARUTI 2002 KA09-A-782 ESTEEM 2003 17
  • 18. DBMS _ LAB V semester SIR MVGSC KA09-V-642 SANTRO 2003 KA09-R-710 SONATA 2002 KA09-G-421 MARUTI 2002 KA09-X-111 SANTRO 2004 KA09-D-478 ESTEEM 2001 KA09-G-564 SONATA 2003 ------------------------------------------------------------------------------------------------ CREATE TABLE ACCIDENT(REPORT_NO NUMBER(5) PRIMARY KEY, ODATE DATE, LOCATION VARCHAR2(12)); INSERT INTO ACCIDENT VALUES(&REPORT_NO,'&ODATE','&LOCATION'); REPORT_NO ODATE LOCATION --------- --------- ------------ 10 23-FEB-02 MYSORE 11 16-APR-02 DHARWAD 12 22-FEB-02 MANDYA 13 22-FEB-01 BANGALORE 14 22-FEB-03 MANGALORE 15 16-APR-01 MYSORE 16 22-FEB-00 NAGPUR 17 22-FEB-02 MUMBAI 18 16-APR-03 DELHI 19 22-FEB-04 CHENNAI 20 02-JAN-00 KASHMIR ------------------------------------------------------------------------------------------------ CREATE TABLE OWNS(DRIVER_ID REFERENCES PERSON, REGNO REFERENCES CAR); INSERT INTO OWNS VALUES('&DRIVER_ID','&REGNO'); DRIVE REGNO ----- ---------- D111 KA09-S-383 D111 KA09-S-735 D222 KA09-S-200 D222 KA09-A-782 D333 KA09-V-642 D444 KA09-R-710 D555 KA09-G-421 D888 KA09-X-111 D999 KA09-D-478 D1111 KA09-G-564 ------------------------------------------------------------------------------------------------ CREATE TABLE PARTICIPATED(DRIVER_ID REFERENCES PERSON, REGNO REFERENCES CAR, REPORT_NO REFERENCES ACCIDENT, DAMAGE_AMT NUMBER(6)); 18
  • 19. DBMS _ LAB V semester SIR MVGSC INSERT INTO PARTICIPATED VALUES('&DRIVER_ID','&REGNO',&REPORT_NO,&DAMAGE_AMT); DRIVE REGNO REPORT_NO DAMAGE_AMT ----- ---------- --------- ---------- D111 KA09-S-383 10 0 D111 KA09-S-735 11 0 D222 KA09-S-200 12 0 D222 KA09-A-782 13 0 D333 KA09-V-642 14 0 D444 KA09-R-710 15 0 D555 KA09-G-421 16 0 D888 KA09-X-111 17 0 D999 KA09-D-478 18 0 D1111 KA09-G-564 19 0 ------------------------------------------------------------------------------------------------ PERSON CAR ACCIDENT ------ --- -------- DRIVE NAME ADDRESS | REGNO MODEL YEAR |REPORT_NO ODATE LOCATION ----- ------- ------- | ----- ----- ---- |--------- ----- -------- D111 SHILPA MYSORE |KA09-S-383 SONATA 2004 | 10 23-FEB-02 MYSORE D222 SHANKAR MYSORE |KA09-S-735 MERCEDES 2000 | 11 16-APR-02 DHARWAD D333 SHIVU MYSORE |KA09-S-200 MARUTI 2002 | 12 22-FEB-02 MANDYA D444 ANJALI MYSORE |KA09-A-782 ESTEEM 2003 | 13 22-FEB-01 BANGALORE D555 BHAVYA MYSORE |KA09-V-642 SANTRO 2003 | 14 22-FEB-03 MANGALORE D666 BANU MYSORE |KA09-R-710 SONATA 2002 | 15 16-APR-01 MYSORE D777 GARIMA MYSORE |KA09-G-421 MARUTI 2002 | 16 22-FEB-00 NAGPUR D888 MANU MYSORE |KA09-X-111 SANTRO 2004 | 17 22-FEB-02 MUMBAI D999 CHANDRU MYSORE |KA09-D-478 ESTEEM 2001 | 18 16-APR-03 DELHI D1111 VIVEK MYSORE |KA09-G-564 SONATA 2003 | 19 22-FEB-04 CHENNAI | | 20 02-JAN-00 KASHMIR ------------------------------------------------------------------------------------------------ OWNS PARTICIPATED ---- ------------ DRIVE REGNO |DRIVE REGNO REPORT_NO DAMAGE_AMT ----- ---------- |----- ----- --------- ----------- D111 KA09-S-383 |D111 KA09-S-383 10 0 D111 KA09-S-735 |D111 KA09-S-735 11 0 D222 KA09-S-200 |D222 KA09-S-200 12 0 D222 KA09-A-782 |D222 KA09-A-782 13 0 D333 KA09-V-642 |D333 KA09-V-642 14 0 D444 KA09-R-710 |D444 KA09-R-710 15 0 D555 KA09-G-421 |D555 KA09-G-421 16 0 D888 KA09-X-111 |D888 KA09-X-111 17 0 D999 KA09-D-478 |D999 KA09-D-478 18 0 D1111 KA09-G-564 |D1111 KA09-G-564 19 0 19
  • 20. DBMS _ LAB V semester SIR MVGSC ------------------------------------------------------------------------------------------------ QUERIES: ------- (iii a) UPDATE PARTICIPATED SET DAMAGE_AMT=25000 WHERE REGNO='KA09-S-200' AND REPORT_NO=12; (iii b) INSERT INTO ACCIDENT VALUES(&REPORT_NO,'&ODATE','&LOCATION'); (iv) SELECT COUNT(*) FROM PERSON WHERE DRIVER_ID IN (SELECT DRIVER_ID FROM OWNS WHERE REGNO IN (SELECT REGNO FROM PARTICIPATED WHERE REPORT_NO IN (SELECT REPORT_NO FROM ACCIDENT WHERE ODATE IN (SELECT ODATE FROM ACCIDENT WHERE ODATE > '31-DEC-2001' AND ODATE < '1-JAN-2003')))); (v) SELECT COUNT(*) FROM ACCIDENT WHERE REPORT_NO IN (SELECT REPORT_NO FROM PARTICIPATED WHERE REGNO IN (SELECT REGNO FROM CAR WHERE MODEL='ESTEEM')); CREATE TABLE BRANCH(BRANCH_NAME VARCHAR2(20) PRIMARY KEY,BRANCH_CITY VARCHAR2(20),ASSETS REAL); CREATE TABLE ACCOUNT(ACCNO INT PRIMARY KEY,BRANCH_NAME REFERENCES BRANCH ON DELETE CASCADE,BALA NCE REAL); CREATE TABLE DEPOSITOR(NAME VARCHAR2(20) NOT NULL,ACCNO REFERENCES ACCOUNT ON DELETE CASCADE); CREATE TABLE CUSTOMER(NAME VARCHAR2(20) NOT NULL,STREET VARCHAR2(20),CITY VARCHAR2(20)); CREATE TABLE LOAN(LOAN_NO INT PRIMARY KEY,BRANCH_NAME REFERENCES BRANCH ON DELETE CASCADE,AMOUNT REAL); CREATE TABLE BORROWER(NAME VARCHAR2(20),LOAN_NO REFERENCES LOAN ON DELETE CASCADE); 1: INSERT INTO BRANCH VALUES('&N','&C','&A') 1: INSERT INTO BRANCH VALUES('SNAGAR','TUMKUR','35000000') SELECT * FROM BRANCH; BRANCH_NAME BRANCH_CITY ASSETS -------------------- -------------------- --------- 20
  • 21. DBMS _ LAB V semester SIR MVGSC SSPURAM MYSORE 1000000 JLPURAM MYSORE 2000000 JNAGAR MYSORE 300000 JPNAGAR MYSORE 400000 RNAGAR BANGALORE 500000 GNAGAR BANGALORE 6000000 ANAGAR TUMKUR 7.655E+09 SNAGAR TUMKUR 35000000 8 rows selected. 1: INSERT INTO ACCOUNT VALUES(&N,'&B','&A') 1: INSERT INTO ACCOUNT VALUES(802,'SNAGAR','600000') SELECT * FROM ACCOUNT; ACCNO BRANCH_NAME BALANCE --------- -------------------- --------- 100 SSPURAM 25000 101 SSPURAM 20000 103 SSPURAM 30000 102 SSPURAM 5000 104 SSPURAM 45000 105 SSPURAM 3000 106 SSPURAM 2000 200 JLPURAM 3000 201 JLPURAM 3000 202 JLPURAM 4000 203 JLPURAM 5000 204 JLPURAM 6000 205 JLPURAM 6000 300 JNAGAR 1000 301 JNAGAR 2000 302 JNAGAR 3000 303 JNAGAR 4000 304 JNAGAR 5000 305 JNAGAR 8000 400 JPNAGAR 1000 401 JPNAGAR 2000 ACCNO BRANCH_NAME BALANCE --------- -------------------- --------- 402 JPNAGAR 4000 403 JPNAGAR 4000 404 JPNAGAR 5000 500 RNAGAR 500000 501 RNAGAR 30000 502 RNAGAR 400000 600 GNAGAR 30000 601 GNAGAR 60000 602 GNAGAR 6000 603 GNAGAR 50000 700 ANAGAR 5000 701 ANAGAR 50000 702 ANAGAR 5888 800 SNAGAR 500 801 SNAGAR 90000 802 SNAGAR 600000 21
  • 22. DBMS _ LAB V semester SIR MVGSC 37 rows selected. 1: INSERT INTO DEPOSITOR VALUES('&N',&A) 1: INSERT INTO DEPOSITOR VALUES('RAJU',501) SELECT * FROM DEPOSITOR; NAME ACCNO -------------------- --------- SHILPA 100 SHILPA 200 SHILPA 300 SHILPA 400 SHILPA 104 SHILPA 105 SHILPA 204 SHIVU 101 SHIVU 201 SHIVU 301 SHIVU 401 SHIVU 106 SHIVU 205 SHANKAR 102 SHANKAR 202 ANJALI 302 ANJALI 402 BHAVYA 103 BHAVYA 203 BHAVYA 303 BHAVYA 403 NAME ACCNO -------------------- --------- BHAVYA 404 BHAVYA 304 AISH 600 AISH 601 AISH 603 AISH 502 DIVYA 500 DIVYA 603 DIVYA 801 RAJU 700 RAJU 800 RAJU 501 33 rows selected. SELECT * FROM LOAN; LOAN_NO BRANCH_NAME AMOUNT --------- -------------------- --------- 1000 SSPURAM 2000 1001 SSPURAM 20000 1003 SSPURAM 3000 2000 JLPURAM 5000 22
  • 23. DBMS _ LAB V semester SIR MVGSC 2001 JLPURAM 4000 3000 JNAGAR 5000 6000 GNAGAR 500000 60001 GNAGAR 6000 8000 SNAGAR 50000 1: INSERT INTO BORROWER VALUES('&N',&N) 1: INSERT INTO BORROWER VALUES('RAJU',8000) SELECT * FROM BORROWER; NAME LOAN_NO -------------------- --------- SHILPA 1000 SHIVU 1001 SHANKAR 1003 SHILPA 2000 BHAVYA 2001 AISH 6000 AISH 60001 RAJU 8000 8 rows selected. 3)Query SELECT DISTINCT * FROM(SELECT CUSTOMER_NAME,BRANCH_NAME,COUNT(CUSTOMER_NAME)CNT FROM ACCOUNT,DEPOSITOR WHERE ACCOUNT.ACCNO=DEPOSITOR.ACCNO GROUP BY CUSTOMER_NAME, BRANCH_NAME)WHERE CNT>=2; NAME BRANCH_NAME CNT -------------------- -------------------- --------- AISH GNAGAR 3 BHAVYA JNAGAR 2 BHAVYA JPNAGAR 2 SHILPA JLPURAM 2 SHILPA SSPURAM 3 SHIVU JLPURAM 2 SHIVU SSPURAM 2 7 rows selected. SELECT * FROM(SELECT C.NAME,A.BRANCH_NAME,B.BRANCH_CITY,COUNT(C.NAME) CNT FROM ACCOUNT A,BRANCH B,DEPOSITOR C WHERE A.ACCNO=C.ACCNO AND B.BRANCH_NAME=A.BRANCH_NAME GROUP BY C.NAME,A.BRANCH_NAME,B.BRANCH_CITY)WHERE CNT>=2; NAME BRANCH_NAME BRANCH_CITY CNT -------------------- -------------------- -------------------- --------- AISH GNAGAR BANGALORE 3 BHAVYA JNAGAR MYSORE 23
  • 24. DBMS _ LAB V semester SIR MVGSC 2 BHAVYA JPNAGAR MYSORE 2 SHILPA JLPURAM MYSORE 2 SHILPA SSPURAM MYSORE 3 SHIVU JLPURAM MYSORE 2 SHIVU SSPURAM MYSORE 2 4)Query SELECT C.NAME,B.BRANCH_NAME,COUNT(*)NAM FROM ACCOUNT A,CUSTOMER C,DEPOSITOR D,BRANCH B WHERE A.ACCNO=D.ACCNO AND B.BRANCH_NAME=A.BRANCH_NAME AND C.NAME=D.NAME AND BRANCH_CITY='MYSORE'GROUP BY C.NAME,B.BRANCH_NAME; NAME BRANCH_NAME NAM -------------------- -------------------- --------- ANJALI JNAGAR 1 ANJALI JPNAGAR 1 BHAVYA JLPURAM 1 BHAVYA JNAGAR 2 BHAVYA JPNAGAR 2 BHAVYA SSPURAM 1 SHANKAR JLPURAM 1 SHANKAR SSPURAM 1 SHILPA JLPURAM 2 SHILPA JNAGAR 1 SHILPA JPNAGAR 1 SHILPA SSPURAM 3 SHIVU JLPURAM 2 SHIVU JNAGAR 1 SHIVU JPNAGAR CREATE TABLE AUTHOR(AUTHOR_ID NUMBER(6) PRIMARY KEY, NAME VARCHAR2(10), CITY VARCHAR2(14), COUNTRY VARCHAR2(10)); INSERT INTO AUTHOR VALUES(&AUTHOR_ID,'&NAME','&CITY','&COUNTRY'); AUTHOR_ID NAME CITY COUNTRY --------- ---------- -------------- ---------- 1 SHILPA MYSORE INDIA 2 SHANKAR MYSORE INDIA 3 SHIVU MYSORE INDIA 4 ANJALI BANGALORE INDIA 5 BHAVYA BANGALORE INDIA 6 BANU DELHI INDIA 7 GARIMA DELHI INDIA 8 CHANDRU MUMBAI INDIA 24
  • 25. DBMS _ LAB V semester SIR MVGSC 9 MANU MUMBAI INDIA 10 KANNA DELHI INDIA ------------------------------------------------------------------------------------------------ CREATE TABLE PUBLISHER(PUBLISHER_ID NUMBER(6) PRIMARY KEY, NAME VARCHAR2(10), CITY VARCHAR2(14), COUNTRY VARCHAR2(10)); INSERT INTO PUBLISHER VALUES(&PUBLISHER_ID,'&NAME','&CITY','&COUNTRY'); PUBLISHER_ID NAME CITY COUNTRY ------------ ---------- -------------- ---------- 11 SSS MYSORE INDIA 22 SSS BANGALORE INDIA 33 SSS MYSORE INDIA 44 AAA MYSORE INDIA 55 BBB DELHI INDIA 66 AAA MUMBAI INDIA 77 BBB CHENNAI INDIA 88 SSS DELHI INDIA 99 SSS MUMBAI INDIA ------------------------------------------------------------------------------------------------ CREATE TABLE CATALOG(BOOK_ID NUMBER(6) PRIMARY KEY, TITLE VARCHAR2(20), AUTHOR_ID REFERENCES AUTHOR, PUBLISHER_ID REFERENCES PUBLISHER, CATEGORY_ID REFERENCES CATEGORY, YEAR NUMBER(4), PRICE NUMBER(6)); INSERT INTO CATALOG VALUES(&BOOK_ID,'&TITLE',&AUTHOR_ID,&PUBLISHER_ID,&CATEGORY_ID, &YEAR,&PRICE); BOOK_ID TITLE AUTHOR_ID PUBLISHER_ID CATEGORY_ID YEAR PRICE --------- -------------------- --------- ------------ ----------- --------- --------- 10 IWP 1 11 111 2000 500 20 MIS 3 44 555 2000 300 30 TD 4 55 888 2001 400 40 SOM 7 88 666 2003 250 50 GRAPHICS 9 88 222 2002 300 60 LD 5 77 333 25
  • 26. DBMS _ LAB V semester SIR MVGSC 2001 400 70 IM 4 55 444 1999 300 80 DRAWING 2 77 777 2000 250 90 ENV_ENG 8 11 999 2001 300 100 CT 1 22 111 2000 350 110 CN 1 33 222 2000 400 120 MP 5 66 444 2000 600 ------------------------------------------------------------------------------------------------ CREATE TABLE CATEGORY(CATEGORY_ID NUMBER(5) PRIMARY KEY, DESCRIPTION VARCHAR2(20)); INSERT INTO CATEGORY VALUES(&CATEGORY_ID,'&DESCRIPTION'); CATEGORY_ID DESCRIPTION ----------- -------------------- 111 CS 222 MECH 333 ELECTRONICS 444 IP 555 IS 666 CIVIL 777 IT 888 ELECTRICAL 999 ENV ------------------------------------------------------------------------------------------------ CREATE TABLE ORDER_DETAILS(ORDER_NO NUMBER(5) PRIMARY KEY, BOOK_ID REFERENCES CATALOG, QUANTITY NUMBER(6)); INSERT INTO ORDER_DETAILS VALUES(&ORDER_NO,&BOOK_ID,&QUANTITY); ORDER_NO BOOK_ID QUANTITY --------- --------- --------- 51 10 50 52 20 60 53 30 40 54 40 100 55 50 170 56 60 200 57 70 150 58 80 230 59 90 210 ------------------------------------------------------------------------------------------------ AUTHOR PUBLISHER CATREGORY 26
  • 27. DBMS _ LAB V semester SIR MVGSC ------- ---------- ---------- A_ID NAME CITY COUNTRY |P_ID NAME CITY COUNTRY|CATEGORY_ID DESCRIPTION ---- ------- --------- ------- |---- ---- ---- -------|----------- ----------- 1 SHILPA MYSORE INDIA | 11 SSS MYSORE INDIA| 111 CS 2 SHANKAR MYSORE INDIA | 22 SSS BANGALORE INDIA| 222 MECH 3 SHIVU MYSORE INDIA | 33 SSS MYSORE INDIA| 333 ELECTRONICS 4 ANJALI BANGALORE INDIA | 44 AAA MYSORE INDIA| 444 IP 5 BHAVYA BANGALORE INDIA | 55 BBB DELHI INDIA| 555 IS 6 BANU DELHI INDIA | 66 AAA MUMBAI INDIA| 666 CIVIL 7 GARIMA DELHI INDIA | 77 BBB CHENNAI INDIA| 777 IT 8 CHANDRU MUMBAI INDIA | 88 SSS DELHI INDIA| 888 ELECTRICAL 9 MANU MUMBAI INDIA | 99 SSS MUMBAI INDIA| 999 ENV 10 KANNA DELHI INDIA | | ------------------------------------------------------------------------------------------------ CATALOG ORDER_DETAILS ------- ------------- BOOK_ID TITLE A_ID P_ID C_ID YEAR PRICE|ORDER_NO BOOK_ID QUANTITY ------- --------- ---- ----- ---- ----- -----|-------- ------- --------- 10 IWP 1 11 111 2000 500 | 51 10 50 20 MIS 3 44 555 2000 300 | 52 20 60 30 TD 4 55 888 2001 400 | 53 30 40 40 SOM 7 88 666 2003 250 | 54 40 100 50 GRAPHICS 9 88 222 2002 300 | 55 50 170 60 LD 5 77 333 2001 400 | 56 60 200 70 IM 4 55 444 1999 300 | 57 70 150 80 DRAWING 2 77 777 2000 250 | 58 80 230 90 ENV_ENG 8 11 999 2001 300 | 59 90 210 100 CT 1 22 111 2000 350 | 110 CN 1 33 222 2000 400 | 120 MP 5 66 444 2000 600 | ------------------------------------------------------------------------------------------------ QUERIES: -------- (iii) SELECT NAME FROM AUTHOR WHERE AUTHOR_ID IN (SELECT AUTHOR_ID FROM CATALOG WHERE BOOK_ID IN (SELECT BOOK_ID FROM ORDER_DETAILS WHERE QUANTITY IN 27
  • 28. DBMS _ LAB V semester SIR MVGSC (SELECT MAX(QUANTITY) FROM ORDER_DETAILS))); (ii) SELECT * FROM AUTHOR WHERE AUTHOR_ID IN (SELECT AUTHOR_ID FROM CATALOG WHERE PRICE IN (SELECT PRICE FROM CATALOG WHERE PRICE > (SELECT AVG(PRICE) FROM CATALOG) AND YEAR=2000) GROUP BY AUTHOR_ID HAVING COUNT(AUTHOR_ID) >=2); (v) SELECT PRICE,PRICE*0.1 INC,PRICE+PRICE*0.1 TOTAL FROM CATALOG WHERE PUBLISHER_ID IN (SELECT PUBLISHER_ID FROM PUBLISHER WHERE NAME='SSS'); CREATE TABLE PERSON(DRIVER_ID VARCHAR2(5) PRIMARY KEY, NAME VARCHAR2(10), ADDRESS VARCHAR2(15)); INSERT INTO PERSON VALUES('&DRIVER_ID','&NAME','&ADDRESS'); DRIVE NAME ADDRESS ----- ---------- --------------- D111 SHILPA MYSORE D222 SHANKAR MYSORE D333 SHIVU MYSORE D444 ANJALI MYSORE D555 BHAVYA MYSORE D666 BANU MYSORE D777 GARIMA MYSORE D888 MANU MYSORE D999 CHANDRU MYSORE D1111 VIVEK MYSORE ------------------------------------------------------------------------------------------------ CREATE TABLE CAR(REGNO VARCHAR2(10) PRIMARY KEY, MODEL VARCHAR2(10), YEAR NUMBER(4)); INSERT INTO CAR VALUES('&REGNO','&MODEL',&YEAR); REGNO MODEL YEAR ---------- ---------- --------- KA09-S-383 SONATA 2004 KA09-S-735 MERCEDES 2000 KA09-S-200 MARUTI 2002 KA09-A-782 ESTEEM 2003 KA09-V-642 SANTRO 2003 KA09-R-710 SONATA 2002 KA09-G-421 MARUTI 2002 KA09-X-111 SANTRO 2004 KA09-D-478 ESTEEM 2001 KA09-G-564 SONATA 2003 ------------------------------------------------------------------------------------------------ 28
  • 29. DBMS _ LAB V semester SIR MVGSC CREATE TABLE ACCIDENT(REPORT_NO NUMBER(5) PRIMARY KEY, ODATE DATE, LOCATION VARCHAR2(12)); INSERT INTO ACCIDENT VALUES(&REPORT_NO,'&ODATE','&LOCATION'); REPORT_NO ODATE LOCATION --------- --------- ------------ 10 23-FEB-02 MYSORE 11 16-APR-02 DHARWAD 12 22-FEB-02 MANDYA 13 22-FEB-01 BANGALORE 14 22-FEB-03 MANGALORE 15 16-APR-01 MYSORE 16 22-FEB-00 NAGPUR 17 22-FEB-02 MUMBAI 18 16-APR-03 DELHI 19 22-FEB-04 CHENNAI 20 02-JAN-00 KASHMIR ------------------------------------------------------------------------------------------------ CREATE TABLE OWNS(DRIVER_ID REFERENCES PERSON, REGNO REFERENCES CAR); INSERT INTO OWNS VALUES('&DRIVER_ID','&REGNO'); DRIVE REGNO ----- ---------- D111 KA09-S-383 D111 KA09-S-735 D222 KA09-S-200 D222 KA09-A-782 D333 KA09-V-642 D444 KA09-R-710 D555 KA09-G-421 D888 KA09-X-111 D999 KA09-D-478 D1111 KA09-G-564 ------------------------------------------------------------------------------------------------ CREATE TABLE PARTICIPATED(DRIVER_ID REFERENCES PERSON, REGNO REFERENCES CAR, REPORT_NO REFERENCES ACCIDENT, DAMAGE_AMT NUMBER(6)); INSERT INTO PARTICIPATED VALUES('&DRIVER_ID','&REGNO',&REPORT_NO,&DAMAGE_AMT); DRIVE REGNO REPORT_NO DAMAGE_AMT ----- ---------- --------- ---------- D111 KA09-S-383 10 0 D111 KA09-S-735 11 0 D222 KA09-S-200 12 0 D222 KA09-A-782 13 0 D333 KA09-V-642 14 0 29
  • 30. DBMS _ LAB V semester SIR MVGSC D444 KA09-R-710 15 0 D555 KA09-G-421 16 0 D888 KA09-X-111 17 0 D999 KA09-D-478 18 0 D1111 KA09-G-564 19 0 ------------------------------------------------------------------------------------------------ PERSON CAR ACCIDENT ------ --- -------- DRIVE NAME ADDRESS | REGNO MODEL YEAR |REPORT_NO ODATE LOCATION ----- ------- ------- | ----- ----- ---- |--------- ----- -------- D111 SHILPA MYSORE |KA09-S-383 SONATA 2004 | 10 23-FEB-02 MYSORE D222 SHANKAR MYSORE |KA09-S-735 MERCEDES 2000 | 11 16-APR-02 DHARWAD D333 SHIVU MYSORE |KA09-S-200 MARUTI 2002 | 12 22-FEB-02 MANDYA D444 ANJALI MYSORE |KA09-A-782 ESTEEM 2003 | 13 22-FEB-01 BANGALORE D555 BHAVYA MYSORE |KA09-V-642 SANTRO 2003 | 14 22-FEB-03 MANGALORE D666 BANU MYSORE |KA09-R-710 SONATA 2002 | 15 16-APR-01 MYSORE D777 GARIMA MYSORE |KA09-G-421 MARUTI 2002 | 16 22-FEB-00 NAGPUR D888 MANU MYSORE |KA09-X-111 SANTRO 2004 | 17 22-FEB-02 MUMBAI D999 CHANDRU MYSORE |KA09-D-478 ESTEEM 2001 | 18 16-APR-03 DELHI D1111 VIVEK MYSORE |KA09-G-564 SONATA 2003 | 19 22-FEB-04 CHENNAI | | 20 02-JAN-00 KASHMIR ------------------------------------------------------------------------------------------------ OWNS PARTICIPATED ---- ------------ DRIVE REGNO |DRIVE REGNO REPORT_NO DAMAGE_AMT ----- ---------- |----- ----- --------- ----------- D111 KA09-S-383 |D111 KA09-S-383 10 0 D111 KA09-S-735 |D111 KA09-S-735 11 0 D222 KA09-S-200 |D222 KA09-S-200 12 0 D222 KA09-A-782 |D222 KA09-A-782 13 0 D333 KA09-V-642 |D333 KA09-V-642 14 0 D444 KA09-R-710 |D444 KA09-R-710 15 0 D555 KA09-G-421 |D555 KA09-G-421 16 0 D888 KA09-X-111 |D888 KA09-X-111 17 0 D999 KA09-D-478 |D999 KA09-D-478 18 0 D1111 KA09-G-564 |D1111 KA09-G-564 19 0 ------------------------------------------------------------------------------------------------ QUERIES: ------- (iii a) UPDATE PARTICIPATED SET DAMAGE_AMT=25000 WHERE REGNO='KA09-S-200' AND REPORT_NO=12; (iii b) INSERT INTO ACCIDENT 30
  • 31. DBMS _ LAB V semester SIR MVGSC VALUES(&REPORT_NO,'&ODATE','&LOCATION'); (iv) SELECT COUNT(*) FROM PERSON WHERE DRIVER_ID IN (SELECT DRIVER_ID FROM OWNS WHERE REGNO IN (SELECT REGNO FROM PARTICIPATED WHERE REPORT_NO IN (SELECT REPORT_NO FROM ACCIDENT WHERE ODATE IN (SELECT ODATE FROM ACCIDENT WHERE ODATE > '31-DEC-2001' AND ODATE < '1-JAN-2003')))); (v) SELECT COUNT(*) FROM ACCIDENT WHERE REPORT_NO IN (SELECT REPORT_NO FROM PARTICIPATED WHERE REGNO IN (SELECT REGNO FROM CAR WHERE MODEL='ESTEEM')); CREATE TABLE STUDENT(REGNO VARCHAR2(10) PRIMARY KEY, NAME VARCHAR2(10), MAJOR VARCHAR2(8), BDATE DATE); INSERT INTO STUDENT VALUES('&REGNO','&NAME','&MAJOR','&BDATE'); REGNO NAME MAJOR BDATE ---------- ---------- ------------------------- --------- MCA20 SHILPA OPERATING SYSTEM 23-FEB-02 MCA21 SHANKAR GRAPHICS 16-APR-04 MCA22 SHIVU SYSTEM PROGRAMMING 22-FEB-02 MCA1 ANJALI COMP TECH 01-JAN-00 MCA5 BHAVYA PROG LANG 05-DEC-00 ACC1 BANU ACCOUNTANCY 13-AUG-01 ACC2 GARIMA FINANCIAL MGT 27-NOV-03 ACC3 CHANDRU PERSONAL MGT 24-JUN-99 ENG4 MANU MECH ENG 06-NOV-86 MTECH6 KANNA ELECTRICAL ENG 21-JUL-94 ------------------------------------------------------------------------------------------------ CREATE TABLE COURSE(COURSE_NO NUMBER(5) PRIMARY KEY, CNAME VARCHAR2(10), DEPT VARCHAR2(10)); INSERT INTO COURSE VALUES(&COURSE_NO,'&CNAME','&DEPT'); COURSE_NO CNAME DEPT --------- ---------- ---------- 10 MCA CS-DEPT 11 MBA ACC-DEPT 12 ENG ENG-DEPT 14 BSC BSC-DEPT 13 MTECH CS-DEPT ------------------------------------------------------------------------------------------------ CREATE TABLE ENROLL(REGNO REFERENCES STUDENT, COURSE_NO REFERENCES COURSE, 31
  • 32. DBMS _ LAB V semester SIR MVGSC SEM NUMBER(2) NOT NULL, MARKS NUMBER(4)); INSERT INTO ENROLL VALUES('&REGNO',&COURSE_NO,&SEM,&MARKS); REGNO COURSE_NO SEM MARKS ---------- --------- --------- --------- MCA20 10 1 500 MCA21 10 1 500 MCA22 10 1 600 ACC1 11 3 400 ACC2 11 1 450 ENG4 12 5 600 MTECH6 13 4 450 ------------------------------------------------------------------------------------------------ CREATE TABLE TEXT(BOOK_ISBN NUMBER(5) PRIMARY KEY, BOOK_TITLE VARCHAR2(15), PUBLISHER VARCHAR2(25), AUTHOR VARCHAR2(10)); INSERT INTO TEXT VALUES(&BOOK_ISBN,'&BOOK_TITLE','&PUBLISHER','&AUTHOR'); BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR --------- --------------- ------------------------- ---------- 100 C SSS SHILPA 200 C++ AAA SHANKAR 300 JAVA BBB SHIVU 400 ORACLE SSS ANJALI 500 VB AAA BHAVYA 600 MIS SSS BANU 700 TALLY BBB GARIMA 800 ADA AAA KANNA 900 DBMS BBB KANNA ------------------------------------------------------------------------------------------------ CREATE TABLE BOOK_ADOPTION(COURSE_NO REFERENCES COURSE, SEM NUMBER(2) NOT NULL, BOOK_ISBN REFERENCES TEXT); INSERT INTO BOOK_ADOPTION VALUES(&COURSE_NO,&SEM,&BOOK_ISBN); COURSE_NO SEM BOOK_ISBN --------- --------- --------- 10 1 100 10 1 200 10 1 500 11 3 600 11 4 900 12 1 200 13 4 700 32
  • 33. DBMS _ LAB V semester SIR MVGSC ------------------------------------------------------------------------------------------------ STUDENT COURSE ENROLL ------- ------- ------- REGNO NAME MAJOR BDATE |COURSE_NO CNAME DEPT |REGNO COURSE_NO SEM MARKS ------ ------- ------------------ ---------|--------- ----- ---- |----- --------- --- ----- MCA20 SHILPA OPERATING SYSTEM 23-FEB-02| 10 MCA CS-DEPT |MCA20 10 1 500 MCA21 SHANKAR GRAPHICS 16-APR-04| 11 MBA ACC-DEPT|MCA21 10 1 500 MCA22 SHIVU SYSTEM PROGRAMMING 22-FEB-02| 12 ENG ENG-DEPT|MCA22 10 1 600 MCA1 ANJALI COMP TECH 01-JAN-00| 14 BSC BSC-DEPT|ACC1 11 3 400 MCA5 BHAVYA PROG LANG 05-DEC-00| 13 MTECH CS-DEPT |ACC2 11 1 450 ACC1 BANU ACCOUNTANCY 13-AUG-01| |ENG4 12 5 600 ACC2 GARIMA FINANCIAL MGT 27-NOV-03| |MTECH6 13 4 450 ACC3 CHANDRU PERSONAL MGT 24-JUN-99| | ENG4 MANU MECH ENG 06-NOV-86| | MTECH6 KANNA ELECTRICAL ENG 21-JUL-94| | ------------------------------------------------------------------------------------------------ TEXT BOOK_ADOPTION ---- ------------- BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR |COURSE_NO SEM BOOK_ISBN --------- ---------- --------- ------- |--------- --- ---------- 100 C SSS SHILPA | 10 1 100 200 C++ AAA SHANKAR | 10 1 200 300 JAVA BBB SHIVU | 10 1 500 400 ORACLE SSS ANJALI | 11 3 600 500 VB AAA BHAVYA | 11 4 900 600 MIS SSS BANU | 12 1 200 700 TALLY BBB GARIMA | 13 4 700 800 ADA AAA KANNA | 900 DBMS BBB KANNA | ------------------------------------------------------------------------------------------------ QUERIES: -------- SELECT DEPT FROM COURSE WHERE COURSE_NO IN (SELECT COURSE_NO FROM COURSE WHERE COURSE_NO IN (SELECT COURSE_NO FROM BOOK_ADOPTION WHERE BOOK_ISBN IN (SELECT BOOK_ISBN FROM TEXT WHERE PUBLISHER IN (SELECT PUBLISHER FROM TEXT GROUP BY PUBLISHER)))); CREATE VIEW S AS SELECT DISTINCT COURSE_NO,COUNT(TEXT.BOOK_ISBN)BOOK_NO,BOOK_TITLE FROM BOOK_ADOPTION,TEXT WHERE BOOK_ADOPTION.BOOK_ISBN=TEXT.BOOK_ISBN AND COURSE_NO IN (SELECT COURSE_NO FROM COURSE WHERE DEPT='CS-DEPT') GROUP BY TEXT.BOOK_TITLE,COURSE_NO; 33
  • 34. DBMS _ LAB V semester SIR MVGSC SELECT COURSE_NO FROM S GROUP BY COURSE_NO HAVING COUNT(COURSE_NO)>2; CREATE TABLE CUSTOMER(CUST_NO NUMBER(5) PRIMARY KEY, CNAME VARCHAR2(10), CITY VARCHAR2(12)); INSERT INTO CUSTOMER VALUES(&CUST_NO,'&CNAME','&CITY'); CUST_NO CNAME CITY --------- ---------- ------------ 111 SHILPA MYSORE 222 SHANKAR DHARWAD 333 SHIVU MANDYA 444 ANJALI BANGALORE 555 BHAVYA MANGALORE 666 CHANDRU NAGPUR 777 BANU MUMBAI 888 GARIMA DELHI 999 MANU CHENNAI 1010 KANNA KASHMIR ----------------------------------------------------------------------------------------------- CREATE TABLE OORDER(ORDER_NO NUMBER(5) PRIMARY KEY, ODATE DATE, CUST_NO REFERENCES CUSTOMER, ORD_AMT NUMBER(6)); INSERT INTO OORDER VALUES(&ORDER_NO,'&ODATE',&CUST_NO,&ORD_AMT); ORDER_NO ODATE CUST_NO ORD_AMT --------- --------- --------- --------- 100 23-FEB-02 111 10000 200 16-APR-01 111 25000 300 22-FEB-01 222 12000 400 23-FEB-00 333 5000 500 16-APR-03 333 9000 600 22-FEB-03 444 15000 700 23-FEB-02 555 20000 800 16-APR-04 666 8000 900 23-FEB-01 777 18000 1000 16-JAN-04 888 22000 ----------------------------------------------------------------------------------------------- CREATE TABLE ORDER_ITEM(ORDER_NO REFERENCES OORDER, ITEM_NO REFERENCES ITEM ON DELETE CASCADE, QTY NUMBER(5)); INSERT INTO ORDER_ITEM VALUES(&ORDER_NO,&ITEM_NO,&QTY); 34
  • 35. DBMS _ LAB V semester SIR MVGSC ORDER_NO ITEM_NO QTY --------- --------- --------- 100 2121 500 200 2121 400 300 2222 250 400 2323 200 500 2323 150 600 2424 100 700 2525 150 1000 2828 350 ----------------------------------------------------------------------------------------------- CREATE TABLE ITEM(ITEM_NO NUMBER(5) PRIMARY KEY, WAREHOUSE_NO REFERENCES WAREHOUSE, SHIP_DATE DATE); INSERT INTO ITEM VALUES(&ITEM_NO,&WAREHOUSE_NO,'&SHIP_DATE'); ITEM_NO WAREHOUSE_NO SHIP_DATE --------- ------------ --------- 2121 1111 12-JAN-02 2222 1111 01-DEC-03 2323 1111 06-SEP-01 2424 1212 03-AUG-02 2525 1212 05-OCT-01 2626 1212 15-JAN-01 2727 1313 22-FEB-00 2828 1414 30-NOV-03 2929 1515 10-JUN-03 ----------------------------------------------------------------------------------------------- CREATE TABLE WAREHOUSE(WAREHOUSE_NO NUMBER(5) PRIMARY KEY, CITY VARCHAR2(12)); INSERT INTO WAREHOUSE VALUES(&WAREHOUSE_NO,'&CITY'); WAREHOUSE_NO CITY ------------ ------------ 1111 MYSORE 1212 BANGALORE 1313 MYSORE 1414 BANGALORE 1515 MANGALORE 1616 MANGALORE 1717 MYSORE 1818 BANGALORE 1919 MANGALORE 2020 MYSORE ----------------------------------------------------------------------------------------------- CUSTOMER: ORDER: ORDER_ITEM: --------- ------ ----------- CUST_NO CNAME CITY | ORDER_NO ODATE CUST_NO ORD_AMT | 35
  • 36. DBMS _ LAB V semester SIR MVGSC ORDER_NO ITEM_NO QTY --------- ------ ---------- | --------- ----- -------- ------ | -------- ------- --- 111 SHILPA MYSORE |100 23-FEB-02 111 10000 |100 2121 500 222 SHANKAR DHARWAD |200 16-APR-01 111 25000 |200 2121 400 333 SHIVU MANDYA | 300 22-FEB-01 222 12000 |300 2222 250 444 ANJALI BANGALORE |400 23-FEB-00 333 5000 |400 2323 200 555 BHAVYA MANGALORE |500 16-APR-03 333 9000 |500 2323 150 666 CHANDRU NAGPUR |600 22-FEB-03 444 15000 |600 2424 100 777 BANU MUMBAI |700 23-FEB-02 555 20000 |700 2525 150 888 GARIMA DELHI |800 16-APR-04 666 8000 |1000 2828 350 999 MANU CHENNAI |900 23-FEB-01 777 1800 | 1010 KANNA KASHMIR |1000 16-JAN-04 888 22000 | ----------------------------------------------------------------------------------------------- ITEM WAREHOUSE ----- --------- ITEM_NO WAREHOUSE_NO SHIP_DATE| WAREHOUSE_NO CITY ------- ------------ ---------| ------------ ---- 2121 1111 12-JAN-02 | 1111 MYSORE 2222 1111 01-DEC-03 | 1212 BANGALORE 2323 1111 06-SEP-01 | 1313 MYSORE 2424 1212 03-AUG-02 | 1414 BANGALORE 2525 1212 05-OCT-01 | 1515 MANGALORE 2626 1212 15-JAN-01 | 1616 MANGALORE 2727 1313 22-FEB-00 | 1717 MYSORE 2828 1414 30-NOV-03 | 1818 BANGALORE 2929 1515 10-JUN-03 | 1919 MANGALORE | 2020 MYSORE ----------------------------------------------------------------------------------------------- QUERIES: -------- (iii) SELECT CNAME,COUNT(ORDER_NO) CNT,AVG(ORD_AMT) AVG FROM CUSTOMER,OORDER WHERE CUSTOMER.CUST_NO=OORDER.CUST_NO GROUP BY CNAME; (iv) SELECT COUNT(*) FROM WAREHOUSE WHERE WAREHOUSE_NO IN (SELECT WAREHOUSE_NO FROM ITEM WHERE ITEM_NO IN (SELECT ITEM_NO FROM ORDER_ITEM WHERE ORDER_NO IN (SELECT ORDER_NO FROM OORDER WHERE CUST_NO IN (SELECT CUST_NO FROM CUSTOMER WHERE CITY IN (SELECT CITY FROM CUSTOMER GROUP BY CITY))))); (v) DELETE FROM ITEM WHERE ITEM_NO=3030; CREATE TABLE 36
  • 37. DBMS _ LAB V semester SIR MVGSC STUDENT(REGNO VARCHAR2(10) PRIMARY KEY, NAME VARCHAR2(10), MAJOR VARCHAR2(8), BDATE DATE); INSERT INTO STUDENT VALUES('&REGNO','&NAME','&MAJOR','&BDATE'); REGNO NAME MAJOR BDATE ---------- ---------- ------------------------- --------- MCA20 SHILPA OPERATING SYSTEM 23-FEB-02 MCA21 SHANKAR GRAPHICS 16-APR-04 MCA22 SHIVU SYSTEM PROGRAMMING 22-FEB-02 MCA1 ANJALI COMP TECH 01-JAN-00 MCA5 BHAVYA PROG LANG 05-DEC-00 ACC1 BANU ACCOUNTANCY 13-AUG-01 ACC2 GARIMA FINANCIAL MGT 27-NOV-03 ACC3 CHANDRU PERSONAL MGT 24-JUN-99 ENG4 MANU MECH ENG 06-NOV-86 MTECH6 KANNA ELECTRICAL ENG 21-JUL-94 ------------------------------------------------------------------------------------------------ CREATE TABLE COURSE(COURSE_NO NUMBER(5) PRIMARY KEY, CNAME VARCHAR2(10), DEPT VARCHAR2(10)); INSERT INTO COURSE VALUES(&COURSE_NO,'&CNAME','&DEPT'); COURSE_NO CNAME DEPT --------- ---------- ---------- 10 MCA CS-DEPT 11 MBA ACC-DEPT 12 ENG ENG-DEPT 14 BSC BSC-DEPT 13 MTECH CS-DEPT ------------------------------------------------------------------------------------------------ CREATE TABLE ENROLL(REGNO REFERENCES STUDENT, COURSE_NO REFERENCES COURSE, SEM NUMBER(2) NOT NULL, MARKS NUMBER(4)); INSERT INTO ENROLL VALUES('&REGNO',&COURSE_NO,&SEM,&MARKS); REGNO COURSE_NO SEM MARKS ---------- --------- --------- --------- MCA20 10 1 500 MCA21 10 1 500 MCA22 10 1 600 ACC1 11 3 400 ACC2 11 1 450 ENG4 12 5 600 MTECH6 13 4 450 ------------------------------------------------------------------------------------------------ 37
  • 38. DBMS _ LAB V semester SIR MVGSC CREATE TABLE TEXT(BOOK_ISBN NUMBER(5) PRIMARY KEY, BOOK_TITLE VARCHAR2(15), PUBLISHER VARCHAR2(25), AUTHOR VARCHAR2(10)); INSERT INTO TEXT VALUES(&BOOK_ISBN,'&BOOK_TITLE','&PUBLISHER','&AUTHOR'); BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR --------- --------------- ------------------------- ---------- 100 C SSS SHILPA 200 C++ AAA SHANKAR 300 JAVA BBB SHIVU 400 ORACLE SSS ANJALI 500 VB AAA BHAVYA 600 MIS SSS BANU 700 TALLY BBB GARIMA 800 ADA AAA KANNA 900 DBMS BBB KANNA ------------------------------------------------------------------------------------------------ CREATE TABLE BOOK_ADOPTION(COURSE_NO REFERENCES COURSE, SEM NUMBER(2) NOT NULL, BOOK_ISBN REFERENCES TEXT); INSERT INTO BOOK_ADOPTION VALUES(&COURSE_NO,&SEM,&BOOK_ISBN); COURSE_NO SEM BOOK_ISBN --------- --------- --------- 10 1 100 10 1 200 10 1 500 11 3 600 11 4 900 12 1 200 13 4 700 ------------------------------------------------------------------------------------------------ STUDENT COURSE ENROLL ------- ------- ------- REGNO NAME MAJOR BDATE |COURSE_NO CNAME DEPT |REGNO COURSE_NO SEM MARKS ------ ------- ------------------ ---------|--------- ----- ---- |----- --------- --- ----- MCA20 SHILPA OPERATING SYSTEM 23-FEB-02| 10 MCA CS-DEPT |MCA20 10 1 500 MCA21 SHANKAR GRAPHICS 16-APR-04| 11 MBA ACC-DEPT|MCA21 10 1 500 MCA22 SHIVU SYSTEM PROGRAMMING 22-FEB-02| 12 ENG ENG-DEPT|MCA22 10 1 600 MCA1 ANJALI COMP TECH 01-JAN-00| 14 BSC BSC-DEPT|ACC1 11 3 400 38
  • 39. DBMS _ LAB V semester SIR MVGSC MCA5 BHAVYA PROG LANG 05-DEC-00| 13 MTECH CS-DEPT |ACC2 11 1 450 ACC1 BANU ACCOUNTANCY 13-AUG-01| |ENG4 12 5 600 ACC2 GARIMA FINANCIAL MGT 27-NOV-03| |MTECH6 13 4 450 ACC3 CHANDRU PERSONAL MGT 24-JUN-99| | ENG4 MANU MECH ENG 06-NOV-86| | MTECH6 KANNA ELECTRICAL ENG 21-JUL-94| | ------------------------------------------------------------------------------------------------ TEXT BOOK_ADOPTION ---- ------------- BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR |COURSE_NO SEM BOOK_ISBN --------- ---------- --------- ------- |--------- --- ---------- 100 C SSS SHILPA | 10 1 100 200 C++ AAA SHANKAR | 10 1 200 300 JAVA BBB SHIVU | 10 1 500 400 ORACLE SSS ANJALI | 11 3 600 500 VB AAA BHAVYA | 11 4 900 600 MIS SSS BANU | 12 1 200 700 TALLY BBB GARIMA | 13 4 700 800 ADA AAA KANNA | 900 DBMS BBB KANNA | ------------------------------------------------------------------------------------------------ QUERIES: -------- SELECT DEPT FROM COURSE WHERE COURSE_NO IN (SELECT COURSE_NO FROM COURSE WHERE COURSE_NO IN (SELECT COURSE_NO FROM BOOK_ADOPTION WHERE BOOK_ISBN IN (SELECT BOOK_ISBN FROM TEXT WHERE PUBLISHER IN (SELECT PUBLISHER FROM TEXT GROUP BY PUBLISHER)))); CREATE VIEW S AS SELECT DISTINCT COURSE_NO,COUNT(TEXT.BOOK_ISBN)BOOK_NO,BOOK_TITLE FROM BOOK_ADOPTION,TEXT WHERE BOOK_ADOPTION.BOOK_ISBN=TEXT.BOOK_ISBN AND COURSE_NO IN (SELECT COURSE_NO FROM COURSE WHERE DEPT='CS-DEPT') GROUP BY TEXT.BOOK_TITLE,COURSE_NO; SELECT COURSE_NO FROM S GROUP BY COURSE_NO HAVING COUNT(COURSE_NO)>2; CREATE TABLE CUSTOMER(CUST_NO NUMBER(5) PRIMARY KEY, CNAME VARCHAR2(10), CITY VARCHAR2(12)); INSERT INTO CUSTOMER VALUES(&CUST_NO,'&CNAME','&CITY'); CUST_NO CNAME CITY --------- ---------- ------------ 39
  • 40. DBMS _ LAB V semester SIR MVGSC 111 SHILPA MYSORE 222 SHANKAR DHARWAD 333 SHIVU MANDYA 444 ANJALI BANGALORE 555 BHAVYA MANGALORE 666 CHANDRU NAGPUR 777 BANU MUMBAI 888 GARIMA DELHI 999 MANU CHENNAI 1010 KANNA KASHMIR ----------------------------------------------------------------------------------------------- CREATE TABLE OORDER(ORDER_NO NUMBER(5) PRIMARY KEY, ODATE DATE, CUST_NO REFERENCES CUSTOMER, ORD_AMT NUMBER(6)); INSERT INTO OORDER VALUES(&ORDER_NO,'&ODATE',&CUST_NO,&ORD_AMT); ORDER_NO ODATE CUST_NO ORD_AMT --------- --------- --------- --------- 100 23-FEB-02 111 10000 200 16-APR-01 111 25000 300 22-FEB-01 222 12000 400 23-FEB-00 333 5000 500 16-APR-03 333 9000 600 22-FEB-03 444 15000 700 23-FEB-02 555 20000 800 16-APR-04 666 8000 900 23-FEB-01 777 18000 1000 16-JAN-04 888 22000 ----------------------------------------------------------------------------------------------- CREATE TABLE ORDER_ITEM(ORDER_NO REFERENCES OORDER, ITEM_NO REFERENCES ITEM ON DELETE CASCADE, QTY NUMBER(5)); INSERT INTO ORDER_ITEM VALUES(&ORDER_NO,&ITEM_NO,&QTY); ORDER_NO ITEM_NO QTY --------- --------- --------- 100 2121 500 200 2121 400 300 2222 250 400 2323 200 500 2323 150 600 2424 100 700 2525 150 1000 2828 350 ----------------------------------------------------------------------------------------------- CREATE TABLE ITEM(ITEM_NO NUMBER(5) PRIMARY KEY, WAREHOUSE_NO REFERENCES WAREHOUSE, SHIP_DATE DATE); 40
  • 41. DBMS _ LAB V semester SIR MVGSC INSERT INTO ITEM VALUES(&ITEM_NO,&WAREHOUSE_NO,'&SHIP_DATE'); ITEM_NO WAREHOUSE_NO SHIP_DATE --------- ------------ --------- 2121 1111 12-JAN-02 2222 1111 01-DEC-03 2323 1111 06-SEP-01 2424 1212 03-AUG-02 2525 1212 05-OCT-01 2626 1212 15-JAN-01 2727 1313 22-FEB-00 2828 1414 30-NOV-03 2929 1515 10-JUN-03 ----------------------------------------------------------------------------------------------- CREATE TABLE WAREHOUSE(WAREHOUSE_NO NUMBER(5) PRIMARY KEY, CITY VARCHAR2(12)); INSERT INTO WAREHOUSE VALUES(&WAREHOUSE_NO,'&CITY'); WAREHOUSE_NO CITY ------------ ------------ 1111 MYSORE 1212 BANGALORE 1313 MYSORE 1414 BANGALORE 1515 MANGALORE 1616 MANGALORE 1717 MYSORE 1818 BANGALORE 1919 MANGALORE 2020 MYSORE ----------------------------------------------------------------------------------------------- CUSTOMER: ORDER: ORDER_ITEM: --------- ------ ----------- CUST_NO CNAME CITY | ORDER_NO ODATE CUST_NO ORD_AMT | ORDER_NO ITEM_NO QTY --------- ------ ---------- | --------- ----- -------- ------ | -------- ------- --- 111 SHILPA MYSORE |100 23-FEB-02 111 10000 |100 2121 500 222 SHANKAR DHARWAD |200 16-APR-01 111 25000 |200 2121 400 333 SHIVU MANDYA | 300 22-FEB-01 222 12000 |300 2222 250 444 ANJALI BANGALORE |400 23-FEB-00 333 5000 |400 2323 200 555 BHAVYA MANGALORE |500 16-APR-03 333 9000 |500 2323 150 666 CHANDRU NAGPUR |600 22-FEB-03 444 15000 |600 2424 100 777 BANU MUMBAI |700 23-FEB-02 555 20000 |700 2525 150 41
  • 42. DBMS _ LAB V semester SIR MVGSC 888 GARIMA DELHI |800 16-APR-04 666 8000 |1000 2828 350 999 MANU CHENNAI |900 23-FEB-01 777 1800 | 1010 KANNA KASHMIR |1000 16-JAN-04 888 22000 | ----------------------------------------------------------------------------------------------- ITEM WAREHOUSE ----- --------- ITEM_NO WAREHOUSE_NO SHIP_DATE| WAREHOUSE_NO CITY ------- ------------ ---------| ------------ ---- 2121 1111 12-JAN-02 | 1111 MYSORE 2222 1111 01-DEC-03 | 1212 BANGALORE 2323 1111 06-SEP-01 | 1313 MYSORE 2424 1212 03-AUG-02 | 1414 BANGALORE 2525 1212 05-OCT-01 | 1515 MANGALORE 2626 1212 15-JAN-01 | 1616 MANGALORE 2727 1313 22-FEB-00 | 1717 MYSORE 2828 1414 30-NOV-03 | 1818 BANGALORE 2929 1515 10-JUN-03 | 1919 MANGALORE | 2020 MYSORE ----------------------------------------------------------------------------------------------- QUERIES: -------- (iii) SELECT CNAME,COUNT(ORDER_NO) CNT,AVG(ORD_AMT) AVG FROM CUSTOMER,OORDER WHERE CUSTOMER.CUST_NO=OORDER.CUST_NO GROUP BY CNAME; (iv) SELECT COUNT(*) FROM WAREHOUSE WHERE WAREHOUSE_NO IN (SELECT WAREHOUSE_NO FROM ITEM WHERE ITEM_NO IN (SELECT ITEM_NO FROM ORDER_ITEM WHERE ORDER_NO IN (SELECT ORDER_NO FROM OORDER WHERE CUST_NO IN (SELECT CUST_NO FROM CUSTOMER WHERE CITY IN (SELECT CITY FROM CUSTOMER GROUP BY CITY))))); (v) DELETE FROM ITEM WHERE ITEM_NO=3030; 42