For the above schema, perform the following a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the student names with their membership numbers d) List all the issues for the current date with student and Book names e) List the details of students who borrowed book whose author is CJDATE f) Give a count of how many books have been bought by each student g) Give a list of books taken by student with stud_no as 5 h) List the book details which are issued as of today i) Create a view which lists out the iss_no, iss _date, stud_name, book name j) Create a view which lists the daily issues-date wise for the last one week
AIM: Create the tables with the appropriate integrity constraints Insert around 10 records in each of the tables
HW/SW requirements: Processor : AMD Athelon 1.67 GH z RAM : 256 MB Hard Disk : 40 GB Software : Oracle
Name Null? Type . MEM_NO NOT NULL NUMBER(5) STUD_NO NUMBER(5)
SQL>insert into membership values(&mem_no,&stud_no); Enter value for mem_no:5440 Enter value for stud_no:510 old 1:insert into membership values(&mem_no,&stud_no) new 1:insert into membership values(5440,510) insert into membership values(5440,510) * Errors Observed:
ERROR at line 1: ORA-02291:integrity constraint(HARISH.SYS_C002724)violated-primary key not found
Name Null? Type .. BOOK_NO NOT NULL NUMBER(5) BOOK_NAME VARCHAR2(20) AUTHOR VARCHAR2(20)
SQL>insert into book values(&book_no,&book_name,&author); SQL>select * from book;
BOOK_NO BOOK_NAME AUTHOR .. 9123 DBMS Rama Krishna 2342 JAVA Robett wilkins 4523 Fearless tales Alfred 8723 my ambition Harish 7821 Harry Potter JK Rowling
ISS_NO NOT NULL NUMBER ISS_DATE DATE MEM_NO NUMBER(5) BOOK_NO NUMBER(5)
SQL>select * from iss_rec; ISS_NO ISS_DATE MEM_NO BOOK_NO
43 05-JAN-06 5443 4523 81 28-DEC-05 5441 8723 22 08-DEC-05 5440 7821 53 07-JAN-06 5442 9123 35 06-JAN-06 5444 2342 c) List all the student names with their membership numbers
SQL> select s.studname, m.memno from student s, membership m where m.studno=s.studno;
d) List all the issues for the current date with student and Book names
SQL> select i.issno, s.studname, b.bookname from iss_rec I, membership m, student s, book b 2 where i.memno=m.memno and m.studno=s.studno and i.issdate=to_char(sysdate);
e) List the details of students who borrowed book whose author is CJDATE
SQL> select * from student where studno in(select studno from membership where memno in 2 (select memno from iss_rec where bookno in(select bookno from book where author=CJDATE)));
f) Give a count of how many books have been bought by each student
SQL> select s.studno, count(i.bookno) from student s.membership m, book b, 2 iss_rec I where s.studno=m.studno and b.bookno=i.bookno group by s.studno;
g) Give a list of books taken by student with stud_no as 5
SQL> select bookname from book where bookno in (select bookno from iss_rec where 2 memno in(select memno from membership where 3 studno in(select studno from student where studno=5)));
BOOKNAME ------------- NT
h) List the book details which are issued as of today
SQL> delete from book where bookno in(select bookno from iss_rec where issdate=to_char(sysdate)); delete from book where bookno in (select bookno from iss_rec where issdate=to_char(sysdate))
Errors Observed:
ERROR at line 1: ORA-02292: integrity constraint (SCOTT.SYS_C00840) violated child record found
i) Create a view which lists out the iss_no, iss _date, stud_name, book name
j) Create a view which lists the daily issues-date wise for the last one week
Viva-Vice:
1. Describe the three levels of data abstraction? The are three levels of abstraction: Physical level: The lowest level of abstraction describes how data are stored. Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data. View level: The highest level of abstraction describes only part of entire database. 2. Define the "integrity rules" There are two Integrity rules. Entity Integrity: States that Primary key cannot have NULL value Referential Integrity: States that Foreign Key can be either a NULL value or should be Primary Key value of other relation.
3. What is extension and intension? Extension - It is the number of tuples present in a table at any instance. This is time dependent. Intension - It is a constant value that gives the name, structure of table and the constraints laid on it.
4. What is System R? What are its two major subsystems? System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be used in a real life environment to solve real life problems, with performance at least comparable to that of existing system. Its two subsystems are Research Storage System Relational Data System.
5. How is the data structure of System R different from the relational structure? Unlike Relational systems in System R Domains are not supported Enforcement of candidate key uniqueness is optional Enforcement of entity integrity is optional Referential integrity is not enforced
6. What is Data Independence? Data independence means that the application is independent of the storage structure and access strategy of data. In other words, The ability to modify the schema definition in one level should not affect the schema definition in the next higher level. Two types of Data Independence: Physical Data Independence: Modification in physical level should not affect the logical level. Logical Data Independence: Modification in logical level should affect the view level. NOTE: Logical Data Independence is more difficult to achieve
7. What is a view? How it is related to data independence? A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is instead derived from one or more underlying base table. In other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary. Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the effects of restructuring and growth in the database. Hence accounts for logical data independence.