Mca II dbms osmania university lab record

download Mca II dbms osmania university lab record

of 53

Transcript of Mca II dbms osmania university lab record

  • 7/27/2019 Mca II dbms osmania university lab record

    1/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 1 -

    MERIT INSTITUTE OF BUSINESS MGMT &TECH(Approved by AICTE, & Affiliated to OU)

    Manneguda X Roads, Turkayamzal, Hayathnagar Mandal, Ranga Reddy District.

    Department of Master of Computer ApplicationsDepartment of Master of Computer ApplicationsDepartment of Master of Computer ApplicationsDepartment of Master of Computer Applications

    CertificateCertificateCertificateCertificate

    Hall Ticket No.: __________________

    This is to certify that the bonafide record of the practical

    work done in the _____________________________Laboratory

    by Mr. / Ms. _____________________________________ of

    M.C.A. ________ year ______________ semester in during the

    academic year 2009-2010.

    Lecturer-in-charge Head of the Department

    Internal Examiner External Examiner

    Date: __________________

  • 7/27/2019 Mca II dbms osmania university lab record

    2/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 2 -

    MERIT INSTITUTE OF BUSINESS MGMT & TECH [M.C.A.]

    INDEX

    S.No.

    Experiment NamePageNo.

    Date

    1

    Create a table to represent sb-account of a bank consisting of account-no, customer-name, balance-amount.A] Write a PL/SQL block to implement deposit and withdraw.B] Withdraws should not be allowed if the balance goes below Rs.1000.

    2

    Create The following two tables: College-info; Faculty-info.College-info consists of fields: college-code, college-name, address.Faculty-info consists of fields: college-code, faculty-code, faculty-name,qualification, experience-in-no-of-years, and address. The field college-code is foreign key.

    A] Design a form to accept the data from the user.B] List all those faculty members whose experience is greater than or equal to 10 years

    and have M. Tech degree.

    C] List all those faculty members, who have at least 10 years of experience but do nothave M. Tech degree.

    3

    Create the following tables for Library Information System:Book: (accession-no, title, publisher, author, status)Status could be issued, present in the library, sent for binding, and cannot be issued.A] Write a trigger which sets the status of a book to "cannot be issued", if it is

    published 20 years back.

    4

    Create the following tables for Library Information System:Book (accession-no, title, publisher, author, status, date-of-purchase)Status could be issued, present in the library, sent for binding, and account beissued.

    A] Create a form to accept the data from the user create a form to accept the datafrom the user with appropriate validation checks.

    B] Generate queries to list all those books which are new arrivals. The books which areacquired during the last 6 months are categorized as new arrivals.

    (i) List all those books that cannot be issued and purchased 20 years ago.

    5

    Create the following tables:Student (roll-no, name, date-of-birth, course-id)

    Course (Course-id, name, fee, duration)A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to list all those students who are greater than 18 years of age and

    have opted for MCA course.(i) List all those courses whose fee is greater than that of MCA course.

    6

    Create the following table:Student (roll-no, name, subject-name, subject-opted)Subject (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validation checks.

    B] Generate queries to find the number of students who have enrolled for the subject"DBMS".(i) Find all those faculty members who have not offered any subject.

    7

    Create the following table:Item (item-code, item-name, qty-in-stock, reorder-level);Supplier (supplier-code, supplier-name, address); Can-supply(supplier-code, item-code)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to list all those suppliers who can supply the given item.(i) List all those items which cannot be supplied by given company.

    8

    Create the following tables:Student (roll-no, marks, category, district, state)Student-rank(roll-no, marks, rank)

    A] Create a form to accept the data from the user with appropriate validation checks.

    B] Generate queries to list all those students who have come from Tamilnadu state andsecured a rank above 100.

    (i) List all those students who come from Andhra Pradesh state and belong to given

  • 7/27/2019 Mca II dbms osmania university lab record

    3/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 3 -

    category who have secured a rank above 100.

    9

    Create the following tables:Branch (branch-id, branch-name, customer-city, branch-id)Customer (customer-id, customer-name, customer-city, branch-id)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to list all those customers who live in the same city as the branchin which they have account.

    (i) List all those customers who have an account in a given branch city.

    10

    Create the following tables:Book (accession-no, title, publisher, year, date-of-purchase, status)Member(member-id, name, number-of-books-issued, max-limit)Book-issue(accession-no, member-id, date-of-issue)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries list all those books which are due from the students to be

    returned. A book is considered to be due if it has been issued 15 days back and yetnot returned.

    11

    Create the following tables:Book (accession-no, title, publisher, year, date-of-purchase, status)Member(member-id, name, number-of-books-issued, max-limit)

    Book-issue(accession-no, member-id, date-of-issue)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Write a PL/SQL procedure to issue the book.

    12

    Create the following tables :Book(accession-no, title, publisher, year, date-of-purchase, status)Book-Place(accession-no, rack-id, rack-position)Member(member-id, name, number-of-books-issued, max-limit, status)Book-issue(accession-no, member-id, date-of-issue)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Write a PL/SQL procedure to issue the book.

    13

    Create the following table:

    Item (item-code, item-name, qty-in-stock, reorder-level)Supplier (supplier-code, supplier-name, address)Can-supply(supplier-code, item-code)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Write PL/SQL procedure to generate a report to list the items whose qty-in-stock isless than to their reorder-levels.

    14

    Create the following tables:Branch (branch-id, branch-name, branch-city)Customer (customer-id, customer-name, customer-city, branch-id)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to list all those customers who live in the same city as the branchin which they have account.

    15

    15. Create the following tables:Branch (branch-id, branch-name, customer-city)Customer (customer-id, customer-name, customer-city, branch-id)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to list all those customers who have more than a given number(here 4) of customers.

    16

    Create the following table:Student (roll-no, name, category, district, state)Student rank (roll-no, marks, rank)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to do list names of the students who are having same rank.

    17Create the following tables:

    Student(roll-no, name, date-of-birth, course-id)Course (Course-id, name, fee, duration)

  • 7/27/2019 Mca II dbms osmania university lab record

    4/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 4 -

    A] Create a form to accept the data from the user with appropriate validation checks.B] Generate queries to list all those students who are between 18-19 years of age and

    have opted for MCA course.

    18

    Create the following tables:Student(roll-no, name, date-of-birth, course-id)

    Course (Course-id, name, fee, duration, status)

    A] Create a form to accept the data from the user with appropriate validation checks.B] Write PL/SQL procedure to set the status of course to "not offered" in which thenumber of candidates is less than 5.

    19

    Create the following tables:Student (roll-no, name, date-of-birth, course-id)Course (Course-id, name, fee, duration, status)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write PL/SQL procedure to set the status of course to "not offered" in which thenumber of candidates is less than 5.

    20

    Create the following tables:Student (roll-no, name, date-of-birth, course-id)Course (Course-id, name, fee, duration, status)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write PL/SQL procedure to set the status of course to "offered" in which the numberof candidates is at least 10 otherwise set it to "not offered".

    21

    Create the following tables:Book (accession-no, title, publisher, year, date-of-purchase, status)Member(member-id, name, number-of-books-issued, max-limit, status)Book-issue(accession-no, member-id, date-of-issue, due-date)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write a PL/SQL to list all those students who are defaulters. A student is considererto be a defaulter if he has not returned a book even after due-date.

    22

    Create the following table:Item (item-code, item-name, qty-in-stock, reorder-level)Supplier (supplier-code, supplier-name, address, status)Can-supply(supplier-code, item-code).

    A] Create a form to accept the data from the user with appropriate validation checks.

    B] Write PL/SQL procedure to set the status of the supplier to "important" if thesupplier can supply more than five items

  • 7/27/2019 Mca II dbms osmania university lab record

    5/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 5 -

    23

    Create the following tables:Item (item-code, item-name, qty-in-stock, reorder-level)Supplier (supplier-code, supplier-name, address, status)Can-supply(supplier-code, item-code)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write PL/SQL procedure to generate a report of those items that are supplied bythose suppliers whose status is "important".

    24

    Create the following tables:Student (roll-no, name, category, district, state)Student rank (roll-no, marks, rank)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write PL/SQL procedure to generate a report to list of those districts from whichthe first hundred rankers come from.

    25

    Create the following tables:Student (roll-no, name, subject-opted)Subject rank (subject-code, subject-name, faculty-code, specialization)Faculty (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write PL/SQL procedure to set the status of the subject to "not offered" if thesubject is not opted by at least 5 students.

    26

    Create the following tables:Student (roll-no, name, subject-opted)Subject rank (subject-code, subject-name, faculty-code, specialization)Faculty (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Write PL/SQL procedure to set the status of the subject to "not offered" if thesubject is not offered by any of the faculty members.

  • 7/27/2019 Mca II dbms osmania university lab record

    6/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 6 -

    27

    Create the following tables:Student (roll-no, name, subject-opted)Subject rank (subject-code, subject-name, faculty-code)Faculty (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Generate queries to find the number of students who have enrolled for the subject"DBMS"

    28

    Create the following tables:Student (roll-no, name, subject-opted)Subject rank (subject-code, subject-name, faculty-code)Faculty (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Generate queries to find the number of students who have enrolled for the subject"DBMS"

    29

    Create the following tables:Student (roll-no, name, subject-opted)Subject rank (subject-code, subject-name, faculty-code)Faculty (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Generate queries to find the number of students who have enrolled for the subject"OS"

    30

    Create the following tables:Student (roll-no, name, subject-opted)Subject rank (subject-code, subject-name, faculty-code)

    Faculty (faculty-code, faculty-name, specialization)

    A] Create a form to accept the data from the user with appropriate validationchecks.

    B] Generate queries to find the number of students who have not enrolled for thesubject "DBMS"

  • 7/27/2019 Mca II dbms osmania university lab record

    7/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 7 -

    1. (A) Create A Table To Represent Sb-Account Of A Bank Consisting Of Account-No,Customer- Name, Balance-Amount.

    (B) Write A Pl/SQL Block To Implement Deposit And Withdraw. Withdraws Should NotBe Allowed If The Balance Goes Below Rs.1000.

    CREATING SB_ACCOUNT TABLE

    SQL > CREATE TABLE sb_account(account_no number(30)PRIMARY KEY ,customer_namevarchar2(30),balance_amount number(8,2));

    table created.

    INSERTING RECORDS INTO SB_ACCOUNT TABLE

    SQL >INSERT into sb_account values(&acno,'&acname',&balamt);

    enter value for acno: 10001enter value for acname: rajenter value for balamt: 3000old 1:INSERT into sb_account values(&acno,'&acname',&balamt)new 1:INSERT into sb_account values(10001,'raj',3000)

    1 row created.

    SQL > /

    enter value for acno: 10002enter value for acname: ranienter value for balamt: 6000old 1:INSERT into sb_account values(&acno,'&acname',&balamt)new 1:INSERT into sb_account values(10002,'rani',6000)

    1 row created.

    SQL > commit;

    VIEW SB_ACCOUNT RECORDS

    SQL > SELECT * from sb_account;

    account_no customer_name balance_amount---------- ------------------------------ --------------

    10001 raj 280010002 rani 600010003 sri 800010004 mohan 900010005 rohini 1000

    commit complete.

  • 7/27/2019 Mca II dbms osmania university lab record

    8/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 8 -

    (b)write a pl/SQL block to implement deposit and withdraw. withdraws should not be allowed if thebalance goes below rs.1000.

    declarev_acno number:=&acno;v_amt number:=&amt;

    v_bal number;v_rembal number;

    beginSELECT balance_amount into v_bal from sb_account where account_no=v_acno;v_rembal:=v_bal-v_amt;if (v_rembal>1000) thenupdate sb_account set balance_amount=v_rembal where account_no=v_acno;commit;elsedbms_output.put_line('withdraw not possible');end if;end;

    /

    enter value for acno: 10001old 2: v_acno number:=&acno;new 2: v_acno number:=10001;enter value for amt: 100old 3: v_amt number:=&amt;new 3: v_amt number:=100;

    pl/SQL procedure successfully completed.

    SQL > set serveroutput onSQL > /enter value for acno: 10001old 2: v_acno number:=&acno;new 2: v_acno number:=10001;enter value for amt: 100old 3: v_amt number:=&amt;new 3: v_amt number:=100;

    pl/SQL procedure successfully completed.

    SQL > SELECT * from sb_account;

    account_no customer_name balance_amount---------- ------------------------------ --------------10001 raj 280010002 rani 600010003 sri 800010004 mohan 900010005 rohini 1000

  • 7/27/2019 Mca II dbms osmania university lab record

    9/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE - 9 -

    declarev_acno number:=&acno;v_amt number:=&amt;v_bal number;beginSELECT balance_amount into v_bal from sb_account where account_no=v_acno;

    v_bal:=v_bal+v_amt;update sb_account set balance_amount=v_bal where account_no=v_acno;commit;

    end;/

    enter value for acno: 10001old 2: v_acno number:=&acno;new 2: v_acno number:=10001;enter value for amt: 1000old 3: v_amt number:=&amt;new 3: v_amt number:=1000;

    pl/SQL procedure successfully completed.

    SQL > set serveroutput on

    SQL > /

    enter value for acno: 10001old 2: v_acno number:=&acno;new 2: v_acno number:=10001;enter value for amt: 100old 3: v_amt number:=&amt;new 3: v_amt number:=100;

    pl/SQL procedure successfully completed.

    SQL > SELECT * from sb_account;

    account_no customer_name balance_amount---------- ------------------------------ --------------

    10001 raj 390010002 rani 600010003 sri 800010004 mohan 900010005 rohini 1000

  • 7/27/2019 Mca II dbms osmania university lab record

    10/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 10 -

    2. Create the following table :

    faculty-infofaculty-info consists of fields : college-code, faculty-code, faculty-name,qualification, experience-in-no-of-years, address.

    Generate queries to do the following :(i) List all those faculty members whose experience is greater than or equal to 10 years

    and have m. Tech degree.(ii) List all those faculty members, who have at least 10 years of experience but do not

    have m. Tech degree.

    SQL > CREATE TABLE faculty(faccode char(5), name varchar2(20),experience number,qualification varchar2(20));

    table created.

    SQL >INSERT into faculty values('f05','devender',13,'m.tech,m.s');1 row created.SQL >INSERT into faculty values('f03 ','radhika',5,' b.tech');1 row created.SQL >INSERT into faculty values('f07',' rahul ',10,' m.sc,stats');1 row created.

    list all those faculty whose experience is greater than or equal to 10 yrs and have m.tec h degree.

    SQL > SELECT name from facultywhere experience>=10 and qualification like '%m.tech%';

    name--------------------devender

    list all those faculty members, who have at least 10 years of experience but do not have m.tech degree.

    SQL > SELECT name from facultywhere experience>=10 and qualification not like '%m.tech%';

    name--------------------rahul

  • 7/27/2019 Mca II dbms osmania university lab record

    11/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 11 -

    3. Create the following tables for library information system :book : (accession-no, title, publisher, author, status)status could be issued, present in the library, sent for binding, and cannot be issued.

    Write atrigger which sets the status of a book to "cannot be issued", if it is published 20 years back.

    SQL > CREATE TABLE book( accno char(10) PRIMARY KEY , title varchar2(30),publishervarchar2(20),author 2 varchar2(10),status char(10),dtpur date);

    table created.

    SQL > ALTER TABLE book add(constraint status_ck check (status in ('issued','present','binding','cantissue')) );

    table altered.

    SQL >INSERT into book values('1','hp-chamber of secrets','london','jkrowling','','20-aug-2006');

    1 row created.SQL >INSERT into book values('2','hp-philisopher stone','london','jkrowling','','20-aug-2008');1 row created.

    write a trigger which sets the status of a book to cant issue if it is published 20 years back.

    SQL > create or replace trigger book_stat_trigafterINSERT on bookbeginupdate book set status='cantissue'where (months_between(sysdate,dtpur)/12)>=20;end;

    /trigger created.

    SQL >INSERT into book values('4','negotiation possible','hyderabad','','','16-oct-1987');1 row created.

    SQL > SELECT * from book;accno title publisher author status dtpur---------- ------------------------------ -------------------- ---------- ---------- ---------1 hp-chamber of secrets london jkrowling 20-aug-062 hp-philisopher stone london jkrowling 20-aug-084 negotiation possible hyderabad cantissue 16-oct-87

  • 7/27/2019 Mca II dbms osmania university lab record

    12/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 12 -

    4. Create the following tables for library information system :book(accession-no, title, publisher, author, status, date-of-purchase)status could be issued,

    presentin the library, sent for binding, and account be issued.

    Generate queries to do the following :

    (i) List all those books which are new arrivals. The books which are acquired during the last 6months are categorized as new arrivals.(ii) List all those books that cannot be issued and purchased 20 years ago.

    SQL > CREATE TABLE book(accno number PRIMARY KEY ,title varchar2(50),publisher varchar(25),authorvarchar2(25),dop date);

    table created.

    SQL > ALTER TABLE book add (status varchar2(50));

    table altered.

    SQL > ALTER TABLE book add constraint c1 check (status in ('issued','present in library','sent for binding','a/cbe issued'))

    table altered.

    SQL > desc bookname null? type----------------------------------------- -------- ----------------------------

    accno not null numbertitle varchar2(50)publisher varchar2(25)author varchar2(25)dop datestatus varchar2(50)

    SQL >INSERT intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop');enter value for acno: 100enter value for pub: tata

    enter value for st: issuedenter value for title: networkaenter value for author: stallingsenter value for dop: 01-aug-84old 1:INSERT intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop')new 1:INSERT intobook(accno,publisher,status,title,author,dop)values(100,'tata','issued','networka','stallings','01-aug-84')

    1 row created.

    SQL > /enter value for acno: 180enter value for pub: oracleenter value for st: abcdenter value for title: ad

  • 7/27/2019 Mca II dbms osmania university lab record

    13/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 13 -

    enter value for author: williamenter value for dop: 01-feb-08old 1:INSERT intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop')new 1:INSERT into book(accno,publisher,status,title,author,dop)values(180,'oracle','abcd','ad','william','01-feb-08')

    insert into book(accno,publisher,status,title,author,dop)values(180,'oracle','abcd','ad','william','01-feb-08')*error at line 1:ora-02290: check constraint (neerus.c1) violated

    SQL > commit;

    commit complete.

    SQL >INSERT intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop');enter value for acno: 150

    enter value for pub: chandenter value for st: sent for bindingenter value for title: numericalenter value for author: schandenter value for dop: 01-sep-08old 1:INSERT intobook(accno,publisher,status,title,author,dop)values(&acno,'&pub','&st','&title','&author','&dop')new 1:INSERT into book(accno,publisher,status,title,author,dop)values(150,'chand','sent forbinding','numerical','schand','01-sep-08')

    1 row created.

    SQL > commit;

    list all those books which are new arrivals. the books which are acquired during the last 6 months arecategorized as new arrivals.

    commit complete.

    SQL > SELECT * from book where dopSELECT * from book where add_months(sysdate,-6)

  • 7/27/2019 Mca II dbms osmania university lab record

    14/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 14 -

    LIST ALL THOSE BOOKS THAT CANNOT BE ISSUED AND PURCHASED 20 YEARS AGO.

    SQL >SELECT * from book where (sysdate-dop)/365>=20

    accno title---------- --------------------------------------------------publisher author dop------------------------- ------------------------- ---------status--------------------------------------------------

    100 networkatata stallings 01-aug-84issued

    SQL > commit;

    commit complete.

  • 7/27/2019 Mca II dbms osmania university lab record

    15/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 15 -

    5. Create the following tables :student(roll-no, name, date-of-birth, course-id)course (course-id, name, fee, duration)

    (a) create a form to accept the data from the user withappropriate validation checks.

    (b) generate queries to do the following :(i) list all those students who are greater than 18 years of

    age and have opted for mca course.(ii) list all those courses whose fee is greater than that of

    mca course.

    SQL > CREATE TABLE student( roll char(10) PRIMARY KEY , dob date, name varchar2(10),courseid char(10));

    table created.

    SQL > CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10), fee number, durationnumber);table created.

    SQL >INSERT into course values ('c001','mca',75000,3);1 row created.SQL >INSERT into course values ('m003','mba',200000,2);1 row created.SQL >INSERT into student values ('04808015','06-aug-1978','suchitra','c001');1 row created.SQL >INSERT into student values ('04708015','07-sep-1991','radhika','c001');1 row created.

    (b) (i) list all student names who have opted for mca course and are above 18 yrs of age.

    SQL >SELECT s.name "student list" from student "s",course "c" where (months_between(sysdate,dob)/12)>=18 and c.name='mca' and c.courseid=s.courseid;student li----------suchitra

    (b) (ii) list all the course whose fee is more than coursemca.

    SQL > SELECT c.name from course "c"2 where fee > (SELECT fee from course where name='mca');

    name----------

    mba

  • 7/27/2019 Mca II dbms osmania university lab record

    16/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 16 -

    6. Create the following table :student (roll-no, name, subject-name, subject-opted)subject(faculty-code, faculty-name, specialization)

    generate queries to do the following :(i) find the number of students who have enrolled for the

    subject "dbms".(ii) find all those faculty members who have not offered any

    subject.

    SQL > CREATE TABLE student( roll char(5), name varchar2(20),subjopt varchar2(30));

    table created.

    SQL >CREATE TABLE subject(subcode char(3),name varchar2(10), faccode char(5), specializationvarchar2(10),status varchar2(15));

    table created.

    SQL > CREATE TABLE faculty( faccode char(5),name varchar2(20),experience number, 2 specializationvarchar2(20));

    table created.

    SQL >INSERT into student values('s8010','rekha','m01,s01,s02');1 row created.SQL >INSERT into student values('s8021','ravi','s01,m02,d01');1 row created.SQL >INSERT into subject values('m01','dismaths','f10','','');

    1 row created.SQL >INSERT into subject values('m02',' geomaths','','','');1 row created.SQL >INSERT into subject values('s01',' stats',' f07','','');1 row created.SQL >INSERT into subject values('s02','opresearch','f07','','');1 row created.SQL >INSERT into subject values('d01','dbms',' f03','','');1 row created.SQL >INSERT into faculty values('f10','lavanya',5,' m.sc,matha');1 row created.SQL >INSERT into faculty values('f07',' rahul ',5,' m.sc,stats');1 row created.SQL >INSERT into faculty values('f05','devender',3,'m.tech,m.s');1 row created.SQL >INSERT into faculty values('f03 ','radhika',10,' b.tech');1 row created.

    (i) list the number of students who have enrolled for the subject dbms.

    SQL > SELECT count(*) from student,subject where (subcode=substr(subjopt,0,3)2 or subcode=substr(subjopt,5,3) or subcode=substr(subjopt,9,3)) and subject.name='dbms';count(*)---------

    1

  • 7/27/2019 Mca II dbms osmania university lab record

    17/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 17 -

    (ii) list those faculty members who have not offered any subject.SQL > SELECT name from faculty where faccode not in (SELECT faculty.faccode from2 subject,faculty where subject.faccode=faculty.faccode);

    name--------------------

    devenderradhika

  • 7/27/2019 Mca II dbms osmania university lab record

    18/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 18 -

    7. Create the following table :item (item-code, item-name, qty-in-stock, reorder-level)supplier (supplier-code, supplier-name, address)can-supply(supplier-code, item-code)

    Generate queries to do the following :

    (i) List all those suppliers who can supply the given item.(ii) List all those items which cannot be supplied by given company.

    SQL > CREATE TABLE item( itcode char(10) PRIMARY KEY , itname varchar2(20),qtysk number,reordernumber);

    table created.

    SQL > CREATE TABLE supplier( supcode char(10) PRIMARY KEY ,supname varchar2(20),addressvarchar2(20), status varchar2(10));

    table created.

    SQL > CREATE TABLE cansupply(supcode char(10),itcode char(10));

    table created.

    SQL >INSERT into item values('i001','sugar',5,3);1 row created.SQL >INSERT into item values('i002','salt',2,6);1 row created.SQL >INSERT into item values('i003','lentils',10,5);1 row created.SQL >INSERT into supplier values('s001','ashok','patna','');

    1 row created.SQL >INSERT into cansupply values('s001','i001');1 row created.SQL >INSERT into cansupply values('s001','i002');1 row created.

    (i) list all those suppliers who can supply the given item.SQL > SELECT item.itname, supplier.supname from item, supplier, cansupplywhere

    cansupply.itcode=item.itcode and cansupply.supcode=supplier.supcode;itname supname-------------------- --------------------sugar ashoksalt ashok

    (ii) list all those items which cannot be supplied by given company.SQL > SELECT item.itname from item where item.itcode not in (SELECT itcode from cansupply);itname--------------------lentils

  • 7/27/2019 Mca II dbms osmania university lab record

    19/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 19 -

    8. Create the following tables:student (roll-no, marks, category, district, state)student-rank(roll-no, marks, rank)

    generate queries to do the following :(i) list all those students who have come from tamilnadu

    state and secured a rank above 100.(ii)list all those students who come from andhra pradesh

    state and belong to given category who have secured arank above 100.

    SQL > CREATE TABLE student( roll char(10) PRIMARY KEY , name varchar2(20),category char(2), districtvarchar2(20),state varchar2(20));

    table created.

    SQL > CREATE TABLE rank(roll char(10),marks number, rank number);table created.

    SQL >INSERT into student values('s003','siddhu','oc','karimnagar','ap');SQL >INSERT into student values('s004','rekha','bc','chennai','tamilnadu');SQL >INSERT into student values('s005','hema','bc','pondichery','tamilnadu');SQL >INSERT into student values('s006','sudheer','oc','karimnagar','ap');

    SQL >INSERT into rank values('s003',650,135);SQL >INSERT into rank values('s004',600,101);SQL >INSERT into rank values('s005',600,102);SQL >INSERT into rank values('s006',700,120);

    list all those students who have come from tamilnadu state and secured a rank above 100.SQL > SELECT student.roll,student.name from student,rank where

    student.roll=rank.roll and rank>100 and state= 'tamilnadu';

    roll name---------- --------------------s004 rekhas005 hema

    list all students who come from andhrapradesh state and belong to given category who have secured a rankabove 100.SQL > SELECT student.roll,name,category,rank from student,rank where

    student.roll=rank.roll and rank>100 and state='ap' order by category;

    roll name ca rank---------- -------------------- -- ---------s003 siddhu oc 135s006 sudheer oc 120

  • 7/27/2019 Mca II dbms osmania university lab record

    20/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 20 -

    9.create the following tables :branch (branch-id, branch-name, customer-city, branch-id)customer (customer-id, customer-name, customer-city, branch-id)

    generate queries to do the following :(i) list all those customers who live in the same city as the branch

    in which they have account.(ii) list all those customers who have an account in a given branch city.

    SQL > CREATE TABLE branch( branchid char(5) PRIMARY KEY ,name varchar2(10),city varchar2(10));table created.

    SQL > CREATE TABLE customer(custid char(5) PRIMARY KEY , name varchar2(20),city varchar2(10),branchid char(5));

    table created.

    SQL >INSERT into branch values('b002','chikkad','hyd');

    1 row created.SQL >INSERT into branch values('b003','marred','sec');1 row created.

    SQL >INSERT into customer values('c002','suchitra2','hyd','b002');1 row created.SQL >INSERT into customer values('c003','suchitra3','hyd','b002');1 row created.SQL >INSERT into customer values('c004','suchitra4','hyd','b003');1 row created.

    list all those customers who live in the same city as the branch in which they have account.SQL > SELECT customer.name, branch.name from branch,customer

    where branch.branchid=customer.branchid and customer.city=branch.city;name name-------------------- ----------suchitra2 chikkadsuchitra3 chikkad

    list all customers who have an account in a given branch city.SQL > SELECT customer.name from customer,branch

    where customer.branchid=branch.branchid and branch.city='sec';name--------------------suchitra4

  • 7/27/2019 Mca II dbms osmania university lab record

    21/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 21 -

    10. Create the following tables :book(accession-no, title, publisher, year, date-of-purchase, status)member(member-id, name, number-of-books-issued, max-limit)book-issue(accession-no, member-id, date-of-issue)

    Generate queries to do the following :

    (i) list all those books which are due from the students to be returned. A book is considered tobe due if it has been issued 15 days back and yet not returned.

    (ii) list all those members who cannot be issued any more books.

    SQL > CREATE TABLE book( accno char(10) PRIMARY KEY , title varchar2(30),publisher varchar2(20),2 author varchar2(10),status char(10),dtpur date);

    table created.

    SQL > ALTER TABLE book add(constraint status_ck check (status in ('issued','present','binding','cantissue')) );table altered.

    SQL > CREATE TABLE member( memid char(10) PRIMARY KEY , name varchar2(20),no_bk_issued number,

    2 maxlt number, status varchar2(10));table created.

    SQL > CREATE TABLE issued(accno char(10), memid char(10),dt date);table created.SQL >INSERT into book values('1','hp-chamber of secrets','london','jkrowling','','20-aug-2006');1 row created.SQL >INSERT into book values('2','hp-philisopher stone','london','jkrowling','','20-aug-2008');1 row created.SQL >INSERT into member values('h001','suchitra',1,10,'');1 row created.SQL >INSERT into member values('s001','siddharth',1,1,'');1 row created.

    SQL >INSERT into issued values('1','h001','01-feb-2008');1 row created.SQL >INSERT into issued values('2','s001','20-oct-2008');1 row created.

    list all the book which are due from the students to be returned. a book is considered due if it hasbeen issued 15 days back and yet not returned.

    SQL > SELECT book.title, book.accno from book , issued where issued.accno=book.accno2 and (months_between(sysdate,issued.dt)*30)>15;

    title accno------------------------------ ----------hp-chamber of secrets 1

    list all those members who cannot be issued any more books.

    SQL > SELECT name from member where no_bk_issued=maxlt;name--------------------siddharth

  • 7/27/2019 Mca II dbms osmania university lab record

    22/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 22 -

    11. Create the following tables :book(accession-no, title, publisher, year, date-of-purchase, status)member(member-id, name, number-of-books-issued, max-limit)book-issue(accession-no, member-id, date-of-issue)(a) create a form to accept the data from the user with appropriate validation

    checks.

    (b) write a pl/sql procedure to issue the book.write a trigger to set the status of students to "back listed" if they have takenbook but not returned even after one year.

    SQL > CREATE TABLE book(accno char(10) PRIMARY KEY , title varchar2(30),publisher varchar2(20),2 author varchar2(10),status char(10),dtpur date);

    table created.

    SQL > ALTER TABLE book add(constraint status_ck check (status in ('issued','present','binding','cantissue')) );table altered.

    SQL > CREATE TABLE member(memid char(10) PRIMARY KEY ,name varchar2(20),no_bk_issued number,

    2 maxlt number,status varchar2(10));table created.

    SQL > CREATE TABLE issued(accno char(10),memid char(10),dt date);table created.

    SQL >INSERT into book values('1','hp-cham of secrets','london','jkrowling','issued','20-aug-2007');1 row created.SQL >INSERT into book values('2','hp-philis stone','london','jkrowling','issued','20-aug-2008');1 row created.SQL >INSERT into book values('5','databaseappl','hyderabad','ramakrish','','17-jan-2007');1 row created.SQL >INSERT into member values('h001','suchitra',1,10,'');

    1 row created.SQL >INSERT into member values('s001','siddharth',1,5,'');1 row created.SQL >INSERT into issued values('1','h001','01-feb-2007');1 row created.SQL >INSERT into issued values('2','s001','20-oct-2008');1 row created.

    write pl/SQL procedure to issue the book.SQL > edit issue.SQL ;declarebkno char(10);memid char(10);flag number;

    beginbkno:=&accessionno;memid:=&memberid;flag:=0;SELECT count(*) into flag from book,memberwhere bkno=accno and memid=member.memid;

    if flag>0 theninsert into issued values(bkno,memid,sysdate);update book

    set status= issued where accno=bkno;end if;end;

  • 7/27/2019 Mca II dbms osmania university lab record

    23/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 23 -

    SQL > start issue.SQL ;19 /

    enter value for accessionno: 5old 7: bkno:=&accessionno;new 7: bkno:=5;

    enter value for memberid: 's001'old 8: memid:=&memberid;new 8: memid:='s001';

    pl/SQL procedure successfully completed.

    SQL > SELECT * from issued;accno memid dt---------- ---------- ---------1 h001 01-feb-072 s001 20-oct-085 s001 23-oct-08

    SQL > SELECT * from book where accno=5;accno title publisher author status dtpur---------- ------------------------------ -------------------- ---------- ---------- ---------5 databaseappl hyderabad ramakrish issued 17-jan-07

    write a trigger to set the status of students to backlisted if they have taken book but not returnedeven after one year.

    SQL > create or replace trigger mem_stat_trig2 afterINSERT on member3 declare4 begin5 update member

    6 set status='backlist'7 where memid in (SELECT memid from issued8 where (months_between(sysdate,dt)/12)>=1);9 end;

    10 /trigger created.

    SQL >INSERT into member values('s002','sadhana',0,5,'');1 row created.

    SQL > SELECT * from member;memid name no_bk_issued maxlt status---------- -------------------- ------------ --------- ----------h001 suchitra 1 10 backlists001 siddharth 1 5s002 sadhana 0 5

  • 7/27/2019 Mca II dbms osmania university lab record

    24/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 24 -

    12. Create the following tables :book(accession-no, title, publisher, year, date-of-purchase, status)book-place(accession-no, rack-id, rack-position)member(member-id, name, number-of-books-issued, max-limit, status)book-issue(accession-no, member-id, date-of-issue)(a) create a form to accept the data from the user with appropriate validation

    checks.(b) write a pl/sql procedure to issue the book.

    write a trigger to set the status of a book neither to "lost" which is neitherissued nor in the library.

    SQL > CREATE TABLE book( accno char(10) PRIMARY KEY , title varchar2(30),publisher varchar2(20),2 author varchar2(10),status char(10),dtpur date);

    table created.

    SQL > ALTER TABLE book add(constraint status_ck check (status in ('issued','present','binding','cantissue')) );table altered.

    SQL > CREATE TABLE member( memid char(10) PRIMARY KEY , name varchar2(20), no_bk_issued number,2 maxlt number, status varchar2(10));

    table created.

    SQL > CREATE TABLE issued(accno char(10),memid char(10),dt date);table created.

    SQL > CREATE TABLE bookpl( accno char(10), rackid char(3),rackposition char(5));table created.

    SQL >INSERT into book values('1','hp-cham of secrets','london','jkrowling','issued','20-aug-2007');1 row created.

    SQL >INSERT into book values('2','hp-philisr stone','london','jkrowling','issued','20-aug-2008');1 row created.

    SQL >INSERT into book values('5','databaseappl','hyderabad','ramakrish','','17-jan-2007');1 row created.

    SQL >INSERT into member values('h001','suchitra',1,10,'');1 row created.

    SQL >INSERT into member values('s001','siddharth',1,5,'');1 row created.

    SQL >INSERT into issued values('1','h001','01-feb-2007');1 row created.

    SQL >INSERT into issued values('2','s001','20-oct-2008');1 row created.

    SQL >INSERT into bookpl values ('3','005','south');1 row created.

    write pl/SQL procedure to issue the book.SQL > edit issue.SQL ;declarebkno char(10);

    memid char(10);flag number;

  • 7/27/2019 Mca II dbms osmania university lab record

    25/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 25 -

    beginbkno:=&accessionno;memid:=&memberid;flag:=0;SELECT count(*) into flag from book,memberwhere bkno=accno and memid=member.memid;

    if flag>0 theninsert into issued values(bkno,memid,sysdate);update bookset status= issued where accno=bkno;end if;end;

    SQL > start issue.SQL ;19 /

    enter value for accessionno: 5old 7: bkno:=&accessionno;new 7: bkno:=5;

    enter value for memberid: 's001'old 8: memid:=&memberid;new 8: memid:='s001';

    pl/SQL procedure successfully completed.SQL > SELECT * from issued;accno memid dt---------- ---------- ---------1 h001 01-feb-072 s001 20-oct-085 s001 23-oct-08

    SQL > SELECT * from book where accno=5;

    accno title publisher author status dtpur---------- ------------------------------ -------------------- ---------- ---------- ---------5 databaseappl hyderabad ramakrish issued 17-jan-07

    write a trigger to set the status of the book to lost which is neither issued not in the library.

    SQL > create or replace trigger book_stat_trig22 afterINSERT on book3 begin4 update book5 set status='lost'6 where accno not in (SELECT accno from issued)7 and accno not in (SELECT accno from bookpl);8 end;9 /

    trigger created.

  • 7/27/2019 Mca II dbms osmania university lab record

    26/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 26 -

    SQL >INSERT into book values('3','negotaing','secun','','','18-mar-2007');1 row created.

    SQL > SELECT * from book;accno title publisher author status dtpur---------- ------------------------------ -------------------- ---------- ---------- ---------1 hp-cham of secrets london jkrowling issued 20-aug-072 hp-philis stone london jkrowling issued 20-aug-085 databaseappl hyderabad ramakrish issued 17-jan-073 negotaing secun lost 18-mar-07

    SQL > SELECT * from bookpl;accno rac rackp---------- --- -----1 005 south

    SQL > SELECT * from issued;accno memid dt---------- ---------- ---------1 h001 01-feb-072 s001 20-oct-085 s001 23-oct-08

  • 7/27/2019 Mca II dbms osmania university lab record

    27/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 27 -

    13. Create the following tables :book(accession-no, title, publisher, year, date-of-purchase, status)member(member-id, name, number-of-books-issued, max-limit, status)book-issue(accession-no, member-id, date-of-issue, due-date)(a) create a form to accept the data from the user with appropriate validation

    checks.

    (b) write a pl/sql to list all those students who are defaulters. A student isconsiderer to be a defaulter if he has not returned a book even after due-date.write a trigger to set the status of students to "back listed" if they have takenbook but not returned even after one year.

    SQL > CREATE TABLE book( accno char(10) PRIMARY KEY , title varchar2(30),publisher varchar2(20),2 author varchar2(10),status char(10),dtpur date);

    table created.

    SQL > ALTER TABLE book add(constraint status_ck check (status in ('issued','present','binding','cantissue')) );table altered.

    SQL > CREATE TABLE member(memid char(10) PRIMARY KEY , name varchar2(20), no_bk_issued number,2 maxlt number, status varchar2(10));

    table created.

    SQL > CREATE TABLE issued( accno char(10), memid char(10),dt date);table created.

    SQL > CREATE TABLE bookpl(accno char(10), rackid char(3),rackposition char(5));table created.

    SQL >INSERT into book values('1','hp-cham of secrets','london','jkrowling','issued','20-aug-2007');1 row created.

    SQL >INSERT into book values('2','hp-philis stone','london','jkrowling','issued','20-aug-2008');1 row created.

    SQL >INSERT into book values('5','databaseappl','hyderabad','ramakrish','','17-jan-2007');1 row created.

    SQL >INSERT into member values('h001','suchitra',1,10,'');1 row created.

    SQL >INSERT into member values('s001','siddharth',1,5,'');1 row created.

    SQL >INSERT into issued values('1','h001','01-feb-2007');1 row created.

    SQL >INSERT into issued values('2','s001','20-oct-2008');1 row created.

    SQL >INSERT into bookpl values ('3','005','south');1 row created.

  • 7/27/2019 Mca II dbms osmania university lab record

    28/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 28 -

    write a pl/SQL to list all those students who are defaulters. a student is considered to be defaulter ifhe has not returned a book even after due date.

    SQL > SELECT member.name from member2 where memid in (SELECT memid from issued3 where (months_between(sysdate,dt)/12)>=1

    4 and accno not in (SELECT accno from bookpl));

    name--------------------suchitra

    write a trigger to set the status of students to backlisted if they have taken book but not returnedeven after one year.

    SQL > create or replace trigger mem_stat_trig2 afterINSERT on member3 declare4 begin

    5 update member6 set status='backlist'7 where memid in (SELECT memid from issued8 where (months_between(sysdate,dt)/12)>=1);9 end;

    10 /trigger created.

    SQL >INSERT into member values('s002','sadhana',0,5,'');1 row created.

    SQL > SELECT * from member;memid name no_bk_issued maxlt status

    ---------- -------------------- ------------ --------- ----------h001 suchitra 1 10 backlists001 siddharth 1 5s002 sadhana 0 5

  • 7/27/2019 Mca II dbms osmania university lab record

    29/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 29 -

    14. Create the following tables :branch (branch-id, branch-name, branch-city)customer (customer-id, customer-name, customer-city, branch-id)generate queries to do the following :

    (i) list all those customers who live in the same city as the branch in which theyhave account.

    (ii) list all those customers who have an account in more than one branch.

    SQL > CREATE TABLE branch(branchid char(5) PRIMARY KEY , name varchar2(10),city varchar2(10));table created.

    SQL > CREATE TABLE customer(custid char(5),name varchar2(20),city varchar2(10),branchid char(5));table created.

    SQL >INSERT into branch values('b002','chikkad','hyd');1 row created.

    SQL >INSERT into branch values('b003','marred','sec');

    1 row created.

    SQL >INSERT into branch values('b004','patni','sec');1 row created.

    SQL >INSERT into customer values('c002','suchitra2','hyd','b002');1 row created.

    SQL >INSERT into customer values('c003','suchitra3','sec','b002');1 row created.

    SQL >INSERT into customer values('c002','suchitra2','hyd','b003');1 row created.

    SQL >INSERT into customer values('c002','suchitra2','hyd','b004');1 row created.

    list all those customers who live in the same city as the branch in which they have account.SQL > SELECT customer.name, branch.name

    2 from branch,customer3 where branch.branchid=customer.branchid4 and customer.city=branch.city;

    name name-------------------- ----------suchitra2 chikkad

    list all customers who have an account in more than one branch.SQL > SELECT unique customer.name

    2 from customer3 where custid in(4 SELECT custid from customer group by custid having count(*)>=2);

    name--------------------suchitra2

  • 7/27/2019 Mca II dbms osmania university lab record

    30/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 30 -

    15. Create the following tables :branch (branch-id, branch-name, customer-city)customer (customer-id, customer-name, customer-city, branch-id)generate queries to do the following :

    (i) list all those customers who have more than 100 customer.(ii) list all those customers who have an account in more than one branch

    SQL > CREATE TABLE branch(branchid char(5) PRIMARY KEY , name varchar2(10),city varchar2(10));table created.

    SQL > CREATE TABLE customer(custid char(5) PRIMARY KEY , name varchar2(20),city varchar2(10),2 branchid char(5));

    table created.

    SQL >INSERT into branch values('b002','chikkad','hyd');1 row created.SQL >INSERT into branch values('b003','marred','sec');1 row created.SQL >INSERT into branch values('b004','patni','sec');

    1 row created.

    SQL >INSERT into customer values('c002','suchitra2','hyd','b002');1 row created.SQL >INSERT into customer values('c003','suchitra3','sec','b002');1 row created.SQL >INSERT into customer values('c002','suchitra2','hyd','b003');1 row created.SQL >INSERT into customer values('c002','suchitra2','hyd','b004');1 row created.SQL >INSERT into customer values('c004','suchitra4','hyd','b002');1 row created.SQL >INSERT into customer values('c005','suchitra5','hyd','b002');

    1 row created.SQL >INSERT into customer values('c006','suchitra6','hyd','b002');1 row created.

    list all the branch who have more than a given number(here 4) of customers.SQL > SELECT unique branch.name from branch,customer

    2 where branch.branchid=customer.branchid3 and customer.branchid in (SELECT branchid from customer4 group by branchid having count(*)>=4);

    name----------chikkad

    list all customers who have an account in more than one branch.SQL > SELECT unique customer.name

    2 from customer3 where custid in(4 SELECT custid from customer group by custid having count(*)>=2);

    name--------------------suchitra2

  • 7/27/2019 Mca II dbms osmania university lab record

    31/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 31 -

    16. Create the following table :student (roll-no, name, category, district, state)student rank (roll-no, marks, rank)

    generate queries to do the following :1. List names of the students who are having same rank but they should reside in

    different districts.2.list details of students they belongs to same category with same rank.

    SQL > CREATE TABLE student( roll char(10) PRIMARY KEY , name varchar2(20),category char(2),district varchar2(20), state varchar2(20));

    table created.SQL > CREATE TABLE rank(roll char(10),marks number, rank number);table created.SQL >INSERT into student values('s002','suchitra','oc','patna','bihar');1 row created.SQL >INSERT into student values('s003','siddhu','oc','karimnagar','ap');1 row created.

    SQL >INSERT into student values('s006','sudheer','bc','karimnagar','ap');1 row created.SQL >INSERT into rank values('s002',650,35);1 row created.SQL >INSERT into rank values('s003',650,35);1 row created.SQL >INSERT into rank values('s006',700,35);1 row created.

  • 7/27/2019 Mca II dbms osmania university lab record

    32/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 32 -

    17. Create the following tables :student(roll-no, name, date-of-birth, course-id)course (course-id, name, fee, duration)

    generate queries to do the following :1. list all those students who are between 18-19 years of age and have opted for

    mca course.2.List all those courses in which number of students are less than 10.

    SQL > CREATE TABLE student(roll char(10) PRIMARY KEY , dob date, name varchar2(10),courseid char(10));table created.

    SQL > CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10),fee number,2 duration number);

    table created.

    SQL >insert into course values ('c001','mca',75000,3);

    insert into course values ('m003','mba',200000,2);insert into student values ('04808015', '07-sep-1990','suchitra','c001');insert into student values ('04708015', '07-sep-1990','radhika','c001');insert into student values ('04708012','12-jan-1988','hemasri','c001');insert into student values ('04807010','26-dec-1990','jayasri','c001');insert into student values ('04708016','07-jul-1985','radha','c001');insert into student values ('04708013','12-jun-1988','hemalatha','c001');insert into student values ('04807011','26-dec-1990','vasuda','c001');insert into student values ('04808018','06-nov-1978','sadhana','c001');insert into student values ('04708019','07-oct-1985','ragini','c001');insert into student values ('04708020','21-feb-1988','anmol','m003');insert into student values ('04807021','20-dec-1990','teja','m003');insert into student values('0460909','17-jul-1990','kareena','c001');

    list all those students who are between 18-19 yrs of age and have opted for mca course.

    SQL > SELECT s.name "student list"2 from student "s",course "c"3 where (months_between(sysdate,dob)/12) between 18 and 194 and c.name='mca' and c.courseid=s.courseid;

    student li----------suchitraradhikakareena

    list all those courses in which number of students are less than 10.SQL > SELECT name from course

    2 where courseid in (3 SELECT courseid from student group by courseid having count(*)

  • 7/27/2019 Mca II dbms osmania university lab record

    33/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 33 -

    18. Create the following tables :student(roll-no, name, date-of-birth, course-id)course (course-id, name, fee, duration, status)

    write pl/sql procedure to do the following :set the status of course to "not offered" in which the number of candidates isless than 5.

    SQL > CREATE TABLE student(roll char(10) PRIMARY KEY , dob date, name varchar2(10), courseid char(10));table created.SQL > CREATE TABLE course( courseid char(10) PRIMARY KEY , name varchar2(10),fee number,2 duration number status varchar2(10));table created.insert into course values ('c001','mca',75000,3,'');insert into course values ('m003','mba',200000,2,'');insert into student values ('04808015', '07-sep-1990','suchitra','c001');insert into student values ('04708015', '07-sep-1990','radhika','c001');insert into student values ('04708012','12-jan-1988','hemasri','c001');insert into student values ('04807010','26-dec-1990','jayasri','c001');insert into student values ('04708016','07-jul-1985','radha','c001');

    insert into student values ('04708013','12-jun-1988','hemalatha','c001');insert into student values ('04807011','26-dec-1990','vasuda','c001');insert into student values ('04808018','06-nov-1978','sadhana','c001');insert into student values ('04708019','07-oct-1985','ragini','c001');insert into student values ('04708020','21-feb-1988','anmol','m003');insert into student values ('04807021','20-dec-1990','teja','m003');insert into student values('0460909','17-jul-1990','kareena','c001');

    pl/SQL procedure to set the status of course to not offered in which the number of candidates is lessthan 5.

    SQL > edit status.SQL ;declare

    id char(10);num number;

    cursor course_cr is SELECT * from course;course_val course_cr%rowtype;

    beginopen course_cr;loopfetch course_cr into course_val;exit when course_cr%notfound;

    id:=course_val.courseid;SELECT count(*) into num from student where courseid=id;where courseid=id;

    if num < 3 thenupdate course set status='not-off'where courseid=id;end if;

    if num >= 3 thenupdate course set status='offered'where courseid=id;end if;

    end loop;close course_cr;

  • 7/27/2019 Mca II dbms osmania university lab record

    34/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 34 -

    end;

    SQL > SELECT * from course;courseid name fee duration status---------- ---------- --------- --------- --------------------

    c001 mca 75000 3m003 mba 200000 2SQL > start status.SQL ;31 /

    pl/SQL procedure successfully completed.SQL > SELECT * from course;courseid name fee duration status---------- ---------- --------- --------- ---------------c001 mca 75000 3 offeredm003 mba 200000 2 not-off

  • 7/27/2019 Mca II dbms osmania university lab record

    35/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 35 -

    19. Create the following tables :student(roll-no, name, date-of-birth, course-id)course (course-id, name, fee, duration, status)write pl/sql procedure to do the following :set the status of course to "not offered" in which the number of candidates is less than 5.

    SQL > CREATE TABLE student(roll char(10) PRIMARY KEY , dob date, name varchar2(10), courseid char(10));table created.SQL > CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10),fee number,

    2 duration number);table created.insert into course values ('c001','mca',75000,3);insert into course values ('m003','mba',200000,2);insert into student values ('04808015', '07-sep-1990','suchitra','c001');insert into student values ('04708015', '07-sep-1990','radhika','c001');insert into student values ('04708012','12-jan-1988','hemasri','c001');insert into student values ('04807010','26-dec-1990','jayasri','c001');insert into student values ('04708016','07-jul-1985','radha','c001');insert into student values ('04708013','12-jun-1988','hemalatha','c001');

    insert into student values ('04807011','26-dec-1990','vasuda','c001');insert into student values ('04808018','06-nov-1978','sadhana','c001');insert into student values ('04708019','07-oct-1985','ragini','c001');insert into student values ('04708020','21-feb-1988','anmol','m003');insert into student values ('04807021','20-dec-1990','teja','m003');insert into student values('0460909','17-jul-1990','kareena','c001');

    pl/SQL procedure to set the status of course to not offered in which the number of candidates is lessthan 5.SQL > edit status.SQL ;declareid char(10);num number;

    cursor course_cr is SELECT * from course;course_val course_cr%rowtype;

    beginopen course_cr;loopfetch course_cr into course_val;exit when course_cr%notfound;

    id:=course_val.courseid;SELECT count(*) into num from studentwhere courseid=id;

    if num < 5 thenupdate course set status='not-off'where courseid=id;end if;

    end loop;close course_cr;end;

    SQL > SELECT * from course;courseid name fee duration status

    ---------- ---------- --------- --------- --------------------c001 mca 75000 3m003 mba 200000 2

  • 7/27/2019 Mca II dbms osmania university lab record

    36/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 36 -

    SQL > start status.SQL ;31 /

    pl/SQL procedure successfully completed.

    SQL > SELECT * from course;courseid name fee duration status

    ---------- ---------- --------- --------- ---------------c001 mca 75000 3m003 mba 200000 2 not-off

  • 7/27/2019 Mca II dbms osmania university lab record

    37/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 37 -

    20. Create the following tables :student(roll-no, name, date-of-birth, course-id)course (course-id, name, fee, duration, status)(a) create a form to accept the data from the user with appropriate validation

    checks.(b) write pl/sql procedure to do the following :

    set the status of course to "offered" in which the number of candidates is atleast 10 otherwise set it to "not offered".

    SQL > CREATE TABLE student(roll char(10) PRIMARY KEY ,dob date, name varchar2(10),courseid char(10));table created.

    SQL > CREATE TABLE course(courseid char(10) PRIMARY KEY , name varchar2(10),2 fee number, duration number);

    table created.

    insert into course values ('c001','mca',75000,3);insert into course values ('m003','mba',200000,2);insert into student values ('04808015', '07-sep-1990','suchitra','c001');

    insert into student values ('04708015', '07-sep-1990','radhika','c001');insert into student values ('04708012','12-jan-1988','hemasri','c001');insert into student values ('04807010','26-dec-1990','jayasri','c001');insert into student values ('04708016','07-jul-1985','radha','c001');insert into student values ('04708013','12-jun-1988','hemalatha','c001');insert into student values ('04807011','26-dec-1990','vasuda','c001');insert into student values ('04808018','06-nov-1978','sadhana','c001');insert into student values ('04708019','07-oct-1985','ragini','c001');insert into student values ('04708020','21-feb-1988','anmol','m003');insert into student values ('04807021','20-dec-1990','teja','m003');insert into student values('0460909','17-jul-1990','kareena','c001');

    pl/SQL procedure to set the status of course to 'offered' in which the number of candidates is at least

    10 otherwise set to not offered .

    SQL > edit status.SQL ;declareid char(10);num number;

    cursor course_cr is SELECT * from course;course_val course_cr%rowtype;beginopen course_cr;loopfetch course_cr into course_val;exit when course_cr%notfound;

    id:=course_val.courseid;SELECT count(*) into num from student_allwhere courseid=id;

    if num < 10 thenupdate course set status='not-off'where courseid=id;end if;

    if num >= 10 then

    update course set status='offered'where courseid=id;end if;

  • 7/27/2019 Mca II dbms osmania university lab record

    38/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 38 -

    end loop;close course_cr;end;

    SQL > SELECT * from course;

    courseid name fee duration status---------- ---------- --------- --------- --------------------c001 mca 75000 3m003 mba 200000 2

    SQL > start status.SQL ;31 /

    pl/SQL procedure successfully completed.

    SQL > SELECT * from course;courseid name fee duration status---------- ---------- --------- --------- ---------------c001 mca 75000 3 offered

    m003 mba 200000 2 not-off

  • 7/27/2019 Mca II dbms osmania university lab record

    39/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 39 -

    21. create the following table :item (item-code, item-name, qty-in-stock, reorder-level)supplier (supplier-code, supplier-name, address)can-supply(supplier-code, item-code)write pl/SQL procedure to do the following :

    generate a report to list the items whose qty-in-stock is less than or equal to their reorder-levels.

    SQL > CREATE TABLE item( itcode char(10) PRIMARY KEY , itname varchar2(20), qtysk number,2 reordernumber);

    table created.

    SQL > CREATE TABLE supplier(supcode char(10) PRIMARY KEY , 3 supname varchar2(20), 4 addressvarchar2(20), 5 status varchar2(10));

    table created.

    SQL > CREATE TABLE cansupply( supcode char(10), itcode char(10));table created.

    insert into item values(i001,sugar,5,3);insert into item values(i002,salt,2,6);insert into item values(i003,lentils,10,5);insert into item values(i004,turmeric,3,2);insert into item values(i005,chilli-dry,7,5);insert into item values(i006,chilli-whole,2,5);insert into item values(i007,oil,10,5);insert into item values(i008,cummin,5,7);

    insert into item values(i009,coriander,5,5);insert into supplier values(s001,ashok,patna,);insert into supplier values(s002,ramu,hyd);insert into cansupply values(s001,i001);insert into cansupply values(s001,i002);insert into cansupply values(s001,i005);insert into cansupply values(s001,i006);insert into cansupply values(s001,i009);insert into cansupply values(s002,i002);insert into cansupply values(s002,i003);insert into cansupply values(s002,i004);

    pl/SQL procedure to generate a report to list the items whose quantity in stock is less than thereorder level.

    SQL > edit report.SQL ;set heading oncolumn itname heading 'item name'column supname heading 'supplier name'

    SELECT supplier.supname, item.itnamefrom item,supplierwhere item.itcode in (SELECT itcode from cansupply

    where supplier.supcode=supcode)and supplier.supcode in (SELECT supcode from cansupply

    where item.itcode=itcode);

  • 7/27/2019 Mca II dbms osmania university lab record

    40/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 40 -

    SQL > start report.SQL ;supplier name item name-------------------- --------------------ashok sugarashok saltashok chilli-dry

    ashok chilli-wholeashok corianderramu saltramu lentilsramu turmeric8 rows SELECT ed.

  • 7/27/2019 Mca II dbms osmania university lab record

    41/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 41 -

    22. create the following table :item (item-code, item-name, qty-in-stock, reorder-level)supplier (supplier-code, supplier-name, address, status)can-supply(supplier-code, item-code)write pl/SQL procedure to do the following :

    set the status of the supplier to "important" if the supplier can supply more

    than five items.

    SQL > CREATE TABLE item(itcode char(10) PRIMARY KEY , itname varchar2(20),qtysk number,2 reorder number);

    table created.

    SQL > CREATE TABLE supplier(supcode char(10) PRIMARY KEY , supname varchar2(20),2 address varchar2(20),status varchar2(10));

    table created.

    SQL > CREATE TABLE cansupply(supcode char(10), itcode char(10));table created.insert into item values(i001,sugar,5,3);

    insert into item values(i002,salt,2,6);insert into item values(i003,lentils,10,5);insert into item values(i004,turmeric,3,2);insert into item values(i005,chilli-dry,7,5);insert into item values(i006,chilli-whole,2,5);insert into item values(i007,oil,10,5);insert into item values(i008,cummin,5,7);insert into item values(i009,coriander,5,5);

    insert into supplier values(s001,ashok,patna,);insert into supplier values(s002,ramu gs,hyd,);

    insert into cansupply values(s001,i001);insert into cansupply values(s001,i002);insert into cansupply values(s001,i005);insert into cansupply values(s001,i006);insert into cansupply values(s001,i009);insert into cansupply values(s002,i002);insert into cansupply values(s002,i003);insert into cansupply values(s002,i004);

    pl/SQL procedure to set the status of the supplier to important if the supplier can supply more than5 items.SQL > edit status.SQL ;beginupdate supplierset status='important'where supcode in (SELECT supcode from cansupply group by supcodehaving count(*)>=5);end;

    SQL > SELECT * from supplier;supcode supplier name address status---------- -------------------- -------------------- ----------s001 ashok patna

    s002 ramu hyd

  • 7/27/2019 Mca II dbms osmania university lab record

    42/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 42 -

    SQL > start status.SQL ;8 /

    pl/SQL procedure successfully completed.

    SQL > SELECT * from supplier;

    supcode supplier name address status---------- -------------------- -------------------- ----------s001 ashok patna importants002 ramu hyd

  • 7/27/2019 Mca II dbms osmania university lab record

    43/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 43 -

    23. create the following tables :item (item-code, item-name, qty-in-stock, reorder-level)supplier (supplier-code, supplier-name, address, status)can-supply(supplier-code, item-code)write pl/SQL procedure to do the following :

    generate a report of those items that are supplied by those suppliers whosestatus is "important".

    SQL > CREATE TABLE item(itcode char(10) PRIMARY KEY , itname varchar2(20),qtysk number,2 reorder number);

    table created.

    SQL > CREATE TABLE supplier(supcode char(10) PRIMARY KEY , supname varchar2(20),2 address varchar2(20),status varchar2(10));

    table created.

    SQL > CREATE TABLE cansupply(supcode char(10),itcode char(10));table created.

    insert into item values(i001,sugar,5,3);insert into item values(i002,salt,2,6);insert into item values(i003,lentils,10,5);insert into item values(i004,turmeric,3,2);insert into item values(i005,chilli-dry,7,5);insert into item values(i006,chilli-whole,2,5);insert into item values(i007,oil,10,5);insert into item values(i008,cummin,5,7);insert into item values(i009,coriander,5,5);

    insert into supplier values(s001,ashok,patna,);insert into supplier values(s002,ramu gs,hyd,);insert into supplier values(s003,spencer,hyd,);

    insert into cansupply values(s001,i001);insert into cansupply values(s001,i002);insert into cansupply values(s001,i005);insert into cansupply values(s001,i006);insert into cansupply values(s001,i009);insert into cansupply values(s002,i002);insert into cansupply values(s002,i003);insert into cansupply values(s002,i004);

    pl/SQL procedure to generate a report on those items that are supplied by those suppliers whosestatus is important.SQL > edit report.SQL ;set heading oncolumn itname heading 'item name'column supname heading 'supplier name'

    SELECT supplier.supname, item.itnamefrom item,supplierwhere status= 'important'and item.itcode in (SELECT itcode from cansupply

    where supplier.supcode=supcode)and supplier.supcode in (SELECT supcode from cansupplywhere item.itcode=itcode);

  • 7/27/2019 Mca II dbms osmania university lab record

    44/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 44 -

    SQL > SELECT * from supplier;supcode supplier name address status---------- -------------------- -------------------- ----------s001 ashok patna importants002 ramu hyd

    SQL > start report.SQL ;supplier name item name-------------------- --------------------ashok sugarashok saltashok chilli-dryashok chilli-wholeashok coriander

  • 7/27/2019 Mca II dbms osmania university lab record

    45/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 45 -

    24. create the following tables :student (roll-no, name, category, district, state)student rank (roll-no, marks, rank)write pl/SQL procedure to the following :

    generate a report to list of those districts from which the first hundred rankers come from.

    SQL > CREATE TABLE student( roll char(10) PRIMARY KEY , name varchar2(20),category char(2),2 district varchar2(20),state varchar2(20));

    table created.

    SQL > CREATE TABLE rank(roll char(10),marks number,rank number);table created.insert into student values(s002,suchitra,oc,patna,bihar);insert into student values(s003,siddhu,oc,karimnagar,ap);insert into student values(s004,rekha,bc,chennai,tamilnadu);insert into student values(s005,hema,bc,pondichery,tamilnadu);insert into student values(s006,sudheer,oc,karimnagar,ap);

    insert into rank values(s002,650,35);

    insert into rank values(s003,650,35);insert into rank values(s004,600,101);insert into rank values(s005,600,102);insert into rank values(s006,700,20);

    pl/SQL procedure to generate a report to list those districts from which the first hundred rankerscome from.

    SQL > edit report.SQL ;set heading oncolumn district heading '-district-'SELECT unique districtfrom studentr,rank

    where studentr.roll=rank.roll and rank.rank

  • 7/27/2019 Mca II dbms osmania university lab record

    46/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 46 -

    25. create the following tables :student (roll-no, name, subject-opted)subject rank (subject-code, subject-name, faculty-code, specialization)faculty (faculty-code, faculty-name, specialization)

    write pl/SQL procedure to the following :set the status of the subject to "not offered" if the subject is not opted by atleast 5 students.

    SQL > CREATE TABLE student(roll char(5), 3 name varchar2(20),subjopt varchar2(30));table created.

    SQL > CREATE TABLE subject(subcode char(3),name varchar2(10),faccode char(5),2 specialization varchar2(10), status varchar2(15));

    table created.

    SQL > CREATE TABLE faculty(faccode char(5),name varchar2(20),experience number,2 specialization varchar2(10));

    table created.

    insert into student values('s8015','suchitra','m01,m02,s01');insert into student values('s8012',' siddu','m01,s02,p01');insert into student values('s8010','rekha','m01,s01,m02,');insert into student values('s8021','ravi','s01,m02,d01');insert into student values('s8016','chitragada','m01,m02,s01);insert into student values('s8013',' sid roy','m01,m02,s01);insert into subject values('m01','dismaths','f07','','');insert into subject values('m02',' geomaths','','','');insert into subject values('s01',' stats',' f07','','');insert into subject values('p01','physics',' f05','','');insert into subject values('s02','opresearch','f07','','');

    insert into subject values('d01','dbms',' f03','','');

    pl/SQL procedure to set the status of the subject tonot offered if the subject is not opted by at least5 students.

    SQL > edit status.SQL ;declaresub varchar2(10);num_student number;cursor sub_cr is SELECT * from subject;sub_val sub_cr%rowtype;

    beginopen sub_cr;

    loopfetch sub_cr into sub_val;exit when sub_cr%notfound;

    sub:=sub_val.name;

    SELECT count(*) into num_studentfrom student,subjectwhere (subcode=substr(subjopt,0,3)or subcode=substr(subjopt,5,3)

    or subcode=substr(subjopt,9,3))and subject.name=sub;

  • 7/27/2019 Mca II dbms osmania university lab record

    47/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 47 -

    if num_student SELECT * from subject;sub name facco specializa status--- ---------- ----- ---------- ---------------m01 dismaths f07m02 geomathss01 stats f07p01 physics f05s02 opresearch f07d01 dbms f03

    6 rows SELECT ed.SQL > start status.SQL ;32 /

    pl/SQL procedure successfully completed.SQL > SELECT * from subject;sub name facco specializa status--- ---------- ----- ---------- ---------------m01 dismaths f07m02 geomathss01 stats f07p01 physics f05 notoffereds02 opresearch f07 notofferedd01 dbms f03 notoffered

    6 rows SELECT ed.

  • 7/27/2019 Mca II dbms osmania university lab record

    48/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 48 -

    26. create the following tables :student (roll-no, name, subject-opted)subject rank (subject-code, subject-name, faculty-code, specialization)faculty (faculty-code, faculty-name, specialization)

    write pl/SQL procedure to the following :set the status of the subject to "not offered" if the subject is not offered by anyof the faculty members.

    SQL > CREATE TABLE student( roll char(5), name varchar2(20),subjopt varchar2(30));table created.

    SQL > CREATE TABLE subject( subcode char(3),name varchar2(10),faccode char(5),2 specialization varchar2(10), status varchar2(15));

    table created.SQL > CREATE TABLE faculty(faccode char(5), name varchar2(20),experience number,

    2 specialization varchar2(10));table created.

    insert into student values('s8015','suchitra','m01,m02,s01');insert into student values('s8012',' siddu','m01,s02,p01');insert into student values('s8010','rekha','m01,s01,m02,');insert into student values('s8021','ravi','s01,m02,d01');insert into student values('s8016','chitragada','m01,m02,s01);insert into student values('s8013',' sid roy','m01,m02,s01);

    insert into subject values('m01','dismaths','f07','','');insert into subject values('m02',' geomaths','','','');

    insert into subject values('s01',' stats',' f07','','');insert into subject values('p01','physics',' f05','','');insert into subject values('s02','opresearch','f07','','');insert into subject values('d01','dbms',' f03','','');

    insert into faculty values('f10','lavanya','', 5,' m.sc,matha');insert into faculty values('f07',' rahul ','', 5,' m.sc,stats');insert into faculty values('f05','devender','',3,'m.tech,m.s');insert into faculty values('f03 ','radhika','',10,' b.tech');

    pl/SQL procedure to set the status of the subject to not offered if the subject is not offered by anyof the faculty members.beginupdate subjectset status='notoffered'where faccode is null;end;

    SQL > SELECT * from subject;sub name facco specializa status--- ---------- ----- ---------- ---------------m01 dismaths f07m02 geomaths

    s01 stats f07p01 physics f05s02 opresearch f07

  • 7/27/2019 Mca II dbms osmania university lab record

    49/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 49 -

    d01 dbms f036 rows SELECT ed.SQL > start ex.SQL ;

    6 /pl/SQL procedure successfully completed.SQL > SELECT * from subject;

    sub name facco specializa status--- ---------- ----- ---------- ---------------m01 dismaths f07m02 geomaths notoffereds01 stats f07p01 physics f05s02 opresearch f07d01 dbms f036 rows SELECT ed.

  • 7/27/2019 Mca II dbms osmania university lab record

    50/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 50 -

    27. create the following tables :student (roll-no, name, subject-opted)subject rank (subject-code, subject-name, faculty-code)faculty (faculty-code, faculty-name, specialization)

    generate queries to do the following :

    find the number of students who have enrolled for the subject "dbms" find all those subjects which are not offered by any faculty members.

    SQL > CREATE TABLE student( roll char(5),name varchar2(20),subjopt varchar2(30));table created.

    SQL > CREATE TABLE subject( subcode char(3), name varchar2(10),faccode char(5),2 specialization varchar2(10),status varchar2(15));

    table created.

    SQL > CREATE TABLE faculty(faccode char(5), name varchar2(20),experience number,2 specialization varchar2(10));

    table created.

    insert into student values('s8015','suchitra','m01,m02,s01');insert into student values('s8012',' siddu','m01,s02,p01');insert into student values('s8010','rekha','m01,s01,s02');insert into student values('s8021','ravi','s01,m02,d01');

    insert into subject values('m01','dismaths','f07','','');insert into subject values('m02',' geomaths','','','');insert into subject values('s01',' stats',' f07','','');insert into subject values('p01','physics',' f05','','');insert into subject values('s02','opresearch','f07','','');insert into subject values('d01','dbms',' f03','','');

    insert into faculty values('f10','lavanya','', 5,' m.sc,matha');insert into faculty values('f07',' rahul ','', 5,' m.sc,stats');insert into faculty values('f05','devender','',3,'m.tech,m.s');insert into faculty values('f03 ','radhika','',10,' b.tech');

    list the number of students who have enrolled for the subject dbms.SQL > SELECT count(*)2 from student,subject3 where4 (subcode=substr(subjopt,0,3)5 or subcode=substr(subjopt,5,3)

    6 or subcode=substr(subjopt,9,3))7 and subject.name='dbms';count(*)

    ---------1

    list all those subjects which are not offered by any of the faculty members.SQL > SELECT name from subject where faccode is null;name----------geomaths

  • 7/27/2019 Mca II dbms osmania university lab record

    51/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 51 -

    28. create the following tables :student (roll-no, name, subject-opted)subject rank (subject-code, subject-name, faculty-code)faculty (faculty-code, faculty-name, specialization)generate queries to do the following :(i) find the number of students who have enrolled for the subject "dbms"(ii) find all those subjects which are offered by more than one faculty member.

    SQL > CREATE TABLE student(roll char(5),name varchar2(20),subjopt varchar2(30));table created.

    SQL > CREATE TABLE subject(subcode char(3), name varchar2(10),faccode char(5),2 specialization varchar2(10),status varchar2(15));

    table created.

    SQL > CREATE TABLE faculty( faccode char(5), name varchar2(20),experience number,2 specialization varchar2(10));

    table created.

    insert into student values('s8015','suchitra','m01,m02,s01');insert into student values('s8012',' siddu','m01,s02,p01');insert into student values('s8010','rekha','m01,s01,s02');insert into student values('s8021','ravi','s01,m02,d01');

    insert into subject values('m01','dismaths','f07','','');insert into subject values('m02',' geomaths','','','');insert into subject values('s01',' stats',' f07','','');insert into subject values('p01','physics',' f05','','');insert into subject values('s02','opresearch','f07','','');insert into subject values('d01','dbms',' f03','','');

    insert into faculty values('f10','lavanya', 5,' m.sc,matha');insert into faculty values('f07',' rahul ', 5,' m.sc,stats');insert into faculty values('f05','devender', 3,'m.tech,m.s');insert into faculty values('f03 ','radhika',10,' b.tech');

    list the students who have enrolled for the subject dbms.SQL > SELECT student.name2 from student,subject3 where4 (subcode=substr(subjopt,0,3)5 or subcode=substr(subjopt,5,3)6 or subcode=substr(subjopt,9,3))7 and subject.name='dbms';

    name--------------------ravi

    find those subjects which are offered by more than one faculty member.SQL > SELECT name from subject

    2 where faccode =(SELECT faccode from subject group by faccode having count(*)>1);name----------dismathsopresearch

  • 7/27/2019 Mca II dbms osmania university lab record

    52/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    PAGE- 52 -

    29. create the following tables :student (roll-no, name, subject-opted)subject rank (subject-code, subject-name, faculty-code)faculty (faculty-code, faculty-name, specialization)generate queries to do the following :

    (i) find the number of students who have enrolled for the subject "os"(ii) find all those students who opted for more than 5 subjects.

    SQL > CREATE TABLE student( roll char(5), name varchar2(20),subjopt varchar2(30));table created.

    SQL > CREATE TABLE subject( subcode char(3), name varchar2(10),faccode char(5),2 specialization varchar2(10), status varchar2(15));

    table created.

    SQL > CREATE TABLE faculty( faccode char(5), name varchar2(20),experience number,2 specialization varchar2(10));

    table created.

    insert into student values('s8015','suchitra','m01,m02,s01');insert into student values('s8012',' siddu','m01,s02,p01');insert into student values('s8010','rekha','m01,s01,d01');insert into student values('s8021','ravi','s01,m02,d01,m01,s02,p01');insert into subject values('m01','dismaths','f07','','');insert into subject values('m02',' geomaths','','','');insert into subject values('s01',' stats',' f07','','');insert into subject values('p01','physics',' f05','','');insert into subject values('s02','os','f07','','');insert into subject values('d01','dbms',' f03','','');

    find all those students who have enrolled for the subject os.SQL > SELECT student.name

    2 from student,subject3 where4 (subcode=substr(subjopt,0,3)5 or subcode=substr(subjopt,5,3)6 or subcode=substr(subjopt,9,3))7 and subject.name='os';

    name--------------------siddu

    find all those students who opted for more than 5 subjects.SQL > SELECT name from student where instr(subjopt,',',1,5)>0;name--------------------ravi

  • 7/27/2019 Mca II dbms osmania university lab record

    53/53

    MERIT INST. OF BUSINESS MANAGEMENT & TECHNOLOGY

    30. create the following tables :student (roll-no, name, subject-opted)subject rank (subject-code, subject-name, faculty-code)faculty (faculty-code, faculty-name, specialization)generate queries to do the following :(i) find the number of students who have not enrolled for the subject "dbms"(ii) find all those subjects which are offered by more than one faculty member.

    SQL > CREATE TABLE student( roll char(5),name varchar2(20),subjopt varchar2(30));table created.

    SQL > CREATE TABLE subject( subcode char(3),name varchar2(10),faccode char(5),2 specialization varchar2(10), status varchar2(15));

    table created.

    SQL > CREATE TABLE faculty(faccode char(5), name varchar2(20), experience number,2 specialization varchar2(10));

    table created.

    insert into student values('s8015','suchitra','m01,m02,s01');insert into student values('s8012',' siddu','m01,s02,p01');insert into student values('s8010','rekha','m01,s01,s02');insert into student values('s8021','ravi','s01,m02,d01');

    insert into subject values('m01','dismaths','f07','','');insert into subject values('m02',' geomaths','','','');insert into subject values('s01',' stats',' f07','','');insert into subject values('p01','physics',' f05','','');insert into subject values('s02','opresearch','f07','','');insert into subject values('d01','dbms',' f03','','');

    insert into faculty values('f10','lavanya','', 5,' m.sc,matha');

    insert into faculty values('f07',' rahul ','', 5,' m.sc,stats');insert into faculty values('f05','devender','',3,'m.tech,m.s');insert into faculty values('f03 ','radhika','',10,' b.tech');

    list the number of students who have not enrolled for the subject dbms.SQL > SELECT count(*)

    2 from student3 where substr(subjopt,0,3) not like4 (SELECT subcode from subject5 where name='dbms')6 and substr(subjopt,5,3) not like7 (SELECT subcode from subject8 where name='dbms')9 and substr(subjopt,9,3) not like

    10 (SELECT subcode from subject11 where name='dbms');count(*)

    ---------3

    find those subjects which are offered by more than one faculty member.SQL > SELECT name from subject

    2 where faccode =(SELECT faccode from subject group by faccode having count(*)>1);