Sie sind auf Seite 1von 5

/******************************************************/

/*First Assignment */
/*Basic DDLs And DMLs */
/******************************************************/
_____________________________________________________________
create table Member_table(
Member_Id Number(5),
Member_Name Varchar2(30),
Member_address Varchar2(50),
Acc_Open_Date Date,
Membership_type Varchar2(20),
Fees_paid Number(4),
Max_Books_Allowed Number(2),
Penalty_Amount Number(7,2)
)

_____________________________________________________________
create table Book_table(
Book_No Number(6),
Book_Name VarChar2(30),
Author_name Varchar2(30),
Cost Number(7,2),
Category Char(10)
)
_____________________________________________________________
create table Issue_table(
Lib_Issue_Id Number(10),
Book_No Number(6),
Member_Id Number(5),
Issue_Date Date,
Return_date Date
)
_____________________________________________________________
desc Issue_table
desc Member_table
desc Book_table
_____________________________________________________________
drop table Member_table
_____________________________________________________________'
create table Member_table(
Member_Id Number(5) primary key,
Member_Name Varchar2(30),
Member_address Varchar2(50),
Acc_Open_Date Date,
Membership_type Varchar2(20) check (Membership_type in('Lifetime', 'Annu
al', 'Half Yearly','Quarterly')),
Fees_paid Number(4),
Max_Books_Allowed Number(2),
Penalty_Amount Number(7,2)
)
_____________________________________________________________
Alter table Member_table Modify Member_Name char(30);
_____________________________________________________________
Alter table Issue_table ADD Referece_Of char(30);
_____________________________________________________________
Alter table Issue_table Drop column Referece_Of ;
_____________________________________________________________
rename Issue_table to Lib_Issue_table;
_____________________________________________________________
insert into Member_table values(1,'Richa Sharma','Pune','10-Dec-05','Lifetime',2
500,5,50);
insert into Member_table values(2,'Garima Sen','Pune',sysdate,'Annual',1000,3,NU
LL);
_____________________________________________________________

insert into Member_table values(3,'Kunal Mestri','Mumbai','14-Feb-05','Lifetime'


,5500,5,50);
insert into Member_table values(4,'Krutika Mestri','Mumbai','18-Feb-05','Annual'
,5500,5,50);
insert into Member_table values(5,'Bhupesh Parab','Mumbai','14-Mar-05','Lifetime
',5500,5,50);
insert into Member_table values(6,'Gauri Khadye','Mumbai','14-Nov-05','Lifetime'
,5500,5,50);
insert into Member_table values(7,'Kunal Mestri','Mumbai','14-Feb-05','Lifetime'
,5500,5,50);
_____________________________________________________________
alter table Member_table Modify Member_Name char(20);
//cannot decrease column length because some value is too big
_____________________________________________________________
insert into Member_table values(6,'Bhupesh Parab','Mumbai','14-Mar-05','Lifetime
',5500,110,50);
_____________________________________________________________
create table Member_table101 as select * from Member_table
_____________________________________________________________
alter table Member_table add Constraint Ck_Mem_MaxBook check(max_books_allowed <
100)
alter table Member_table add Constraint Ck_Mem_PenAmt check(Penalty_Amount <=100
0)
_____________________________________________________________
drop table book_table;
_____________________________________________________________

create table Book_table(


Book_No Number(6) primary key,
Book_Name VarChar2(30) not Null,
Author_name Varchar2(30),
Cost Number(7,2),
Category Char(10) constraint CK_BOOK_CATEGORY check (Category in ('Scien
ce','Fiction','Database','RDBMS','Others'))
)
_____________________________________________________________
insert into Book_table values(101,'Let us C','Denis Ritchie',450,'Others');
insert into Book_table values(102,'Oracle Complete Ref','Loni',550,'Database');
insert into Book_table values(103,'Mastering SQL','Loni',250,'Database');
insert into Book_table values(104,'PL SQL-Ref','Scott Urman', 750,'Database')
_____________________________________________________________
insert into Book_table values(&id,'&bk','&auth',&cost,'&type') ________________
_____________________________________________
create table Book_table101 as select * from book_table where 1=2;
_____________________________________________________________
insert into Book_table101 select * from book_table
_____________________________________________________________
commit
_____________________________________________________________
select * from Book_table101
_____________________________________________________________
insert into Book_table values(106,'National Geographic','Adis Scott', 1000,'Sci
ence');
_____________________________________________________________
rollback;
_____________________________________________________________
Update book_table set Cost=300,Category='RDBMS' where Book_No=103;
_____________________________________________________________

rename Lib_issue_table to issue_table;


_____________________________________________________________
drop table issue_table;
_____________________________________________________________
create table Issue_table(
Lib_Issue_Id Number(10) primary key,
Book_No Number(6) constraint FK_ISSUE_BKNO references Book_table(book_no),
Member_Id Number(5) constraint FK_ISSUE_MEMID references Member_table(Memb
er_Id),
Issue_Date Date,
Return_date Date,
check (Issue_Date < Return_date)
)
_____________________________________________________________
insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7001
,101,1,'10-Dec-06');
insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7002
,102,2,'25-Dec-06');
insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7003
,104,1,'15-Jan-06');

insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7004


,101,1,'04-Jul-06')
insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7005
,104,2,'15-Nov-06');
insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7006
,101,3,'18-Feb-06');
_____________________________________________________________
commit
_____________________________________________________________
alter table Issue_table disable constraint FK_ISSUE_MEMID
_____________________________________________________________

insert into Issue_table (Lib_Issue_Id,Book_No,Member_Id,Issue_Date) values(7008


,101,9,'18-Feb-06');
_____________________________________________________________
alter table Issue_table Enable constraint FK_ISSUE_MEMID

//cannot validate (SCOTT.FK_ISSUE_MEMID) - parent keys not found


_____________________________________________________________
delete from issue_table where Lib_Issue_Id=7008
alter table Issue_table Enable constraint FK_ISSUE_MEMID
_____________________________________________________________
delete from member_table where member_id=1
//integrity constraint (SCOTT.FK_ISSUE_MEMID) violated - child record found
_____________________________________________________________

update issue_table set Return_Date=Issue_date+15 where Lib_Issue_Id=7004 ;


update issue_table set Return_Date=Issue_date+15 where Lib_Issue_Id=7005 ;
_____________________________________________________________
update Member_table set PENALTY_AMOUNT=100 where MEMBER_NAME='Garima Sen';
_____________________________________________________________
SAVEPOINT X;
_____________________________________________________________

delete from issue_table where member_id=1 and issue_date <'10-Dec-06';


_____________________________________________________________
delete from book_table where category not in('RDBMS','Database');
_____________________________________________________________
commit;
_____________________________________________________________
drop table Member_table101;
_____________________________________________________________
drop table book_table101;
_____________________________________________________________
desc Member_table
desc Book_table
desc Issue_table
select * from Member_table;
select * from Book_table;
select * from Issue_table;
_____________________________________________________________
create sequence no_seq start with 100 maxvalue 200 increment by 2
_____________________________________________________________
drop sequence no_seq ;
_____________________________________________________________
create sequence book_seq start with 101 maxvalue 1000 increment by 1 nocycle
_____________________________________________________________
create sequence Member_seq start with 1 maxvalue 100 increment by 1 nocycle
_____________________________________________________________
drop sequence book_seq;
drop sequence Member_seq;
_____________________________________________________________
*************************************************************