Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

RACHIT BHALLA - 16BIT0218 (EXAM044)

Book (Acc_No, Title, Publisher, Shelf)

Book_Author (Acc_No, Author_Name)

Member (Id, Name, School, Type)

Issue_Record (Acc_No, Id, Issue_Date, Due_Date)

1. Create tables identifying the primary keys and foreign keys, Insert necessary tuples into the
tables.

m
er as
Enter user-name: EXAM044@SITEORA

co
eH w
Enter password:

o.
Connected to:
rs e
ou urc
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options
o
aC s

SQL> create table Book(Acc_No number(10), Title varchar(20), Publisher varchar(2


vi y re

0),Shelf varchar(10));

SQL> create table Book_Author(Acc_No number(10),Author_Name varchar(20));


ed d
ar stu

SQL> create table Member(Id number(10),Name varchar(20),School varchar(10), Type

varchar(10));
is

SQL> create table Issue_Record(Acc_No number(10),Id number(10),Issue_Date date,D


Th

ue_Date date);

SQL> alter table Book add constraint Acc_No primary key(Acc_No);


sh

SQL> alter table Book_Author add constraint Acc_Nofk foreign key(Acc_No) referen

ces Book(Acc_No);

SQL> alter table Member add constraint Idpk primary key(Id)

This study source was downloaded by 100000807485648 from CourseHero.com on 11-14-2021 23:06:25 GMT -06:00

https://www.coursehero.com/file/59606897/DBMS-Lab2pdf/
SQL> alter table Issue_Record add constraint Idfk foreign key(Id) references Mem

ber(Id);

alter table Issue_Record add constraint Acc_Nofk2 foreign key(Acc_No) refer

ences Book(Acc_No);

2. Simple Queries (20%)

(a)Write constraints to insert only stack or reference to Book (shelf) and student or staff to Member
(type).

SQL> alter table Book add constraint ch_slf check (Shelf in('stack','reference'));

SQL> alter table Member add constraint ch_type check (Type in('student','staff'));

m
er as
co
(b) Display the author names of all book where the last letter of the name is e.

eH w
o.
SQL> select Author_Name from Book_Author where Author_Name like '%e';

rs e
ou urc
AUTHOR_NAME

--------------------
o

Kankie
aC s
vi y re

(c ) Display the all the book details in ascending order.

SQL> select * from book order by Title;


ed d

ACC_NO TITLE PUBLISHER SHELF


ar stu

---------- -------------------- -------------------- ----------

1004 Amilie abc reference


is

1003 Emele abc stack


Th

1005 India 2020 xyz reference

1001 Lord of the rings xyz stack


sh

1002 Wings of fire pqr stack

(d) Display the acc_no of all the books which is having due_date in between January 2007 and December
2007.

This study source was downloaded by 100000807485648 from CourseHero.com on 11-14-2021 23:06:25 GMT -06:00

https://www.coursehero.com/file/59606897/DBMS-Lab2pdf/
SQL> select Acc_No from Issue_Record where Due_Date between '01-Jan-2017' and '31-Dec-2017';

ACC_NO

--------- ------

1001

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

This study source was downloaded by 100000807485648 from CourseHero.com on 11-14-2021 23:06:25 GMT -06:00

https://www.coursehero.com/file/59606897/DBMS-Lab2pdf/
Powered by TCPDF (www.tcpdf.org)

You might also like