Sie sind auf Seite 1von 4

1-

LOANHIST
LOAN
COPY
RESERVATION
ITEM
TITLE
JUVENILE
ADULT
MEMBER
2-
Retorna os campos firstname e lastname da tabela member concatenados com alias N
ome,
Retorna os campos city e state da tabela adult concatenados e separados por virg
ula com alias Estado,
Retorna o campo title da tabela title com alias Livro,
Retorna o campo author da tabela title com alias Autor.
Retornando todos os emprestimos ordenado pelos campos city e state da tabela adu
lt concatenados e separados por virgula com alias Estado.
3-
Executar os comandos nesta ordem
DELETE FROM loanhist t WHERE t.title_no = 18;
DELETE FROM loan t WHERE t.title_no = 18;
DELETE FROM copy t WHERE t.title_no = 18;
DELETE FROM item t WHERE t.title_no = 18;
DELETE FROM title t WHERE t.title_no = 18;

4-
select distinct m.member_no Numero, m.firstname || ' ' || m.lastname Nome, l.out
_date Data_Saida
from member m, loan l
where m.member_no = l.member_no
and l.out_date between to_date('20/09/2009','DD/MM/YYYY')and to_date('19/10/2009
','DD/MM/YYYY')
order by l.out_date, m.member_no
5-
select j.member_no Codigo_Menor, m.firstname || ' ' || m.lastname Nome_Menor, j.
adult_member_no Codigo_Adulto, m1.firstname || ' ' || m1.lastname Nome_Adulto
from juvenile j, member m, adult a, member m1
where j.member_no = m.member_no
and j.adult_member_no = a.member_no
and a.member_no = m1.member_no
and j.birth_date > to_date('01/01/2000','DD/MM/YYYY')

// Script para criação de tabelas


create table MEMBER
(
member_no number(5),
lastname varchar2(15) not null,
firstname varchar2(15) not null,
middleinitial varchar2(1),
photograph varchar2(255)
)
;
alter table MEMBER
add constraint member_pk primary key (MEMBER_NO);
create table TITLE
(
title_no number(5),
title varchar2(100) not null,
author varchar2(50) not null,
synopsis varchar2(255)
)
;
alter table TITLE
add constraint title_pk primary key (TITLE_NO);

create table ITEM


(
isbn number(5),
title_no number(5),
translation varchar2(20),
cover varchar2(20),
loanable varchar2(1)
)
;
alter table ITEM
add constraint item_pk primary key (ISBN);
alter table ITEM
add constraint item_title_fk foreign key (TITLE_NO)
references title (TITLE_NO);

create table COPY


(
isbn number(5),
copy_no number(2),
title_no number(5),
on_loan varchar2(1) not null
)
;
alter table COPY
add constraint copy_pk primary key (ISBN, COPY_NO);
alter table COPY
add constraint copy_item_fk foreign key (ISBN)
references item (ISBN);
alter table COPY
add constraint copy_title_fk foreign key (TITLE_NO)
references title (TITLE_NO);

create table RESERVATION


(
isbn number(5),
member_no number(5),
log_date date,
remarks varchar2(50)
)
;
alter table RESERVATION
add constraint reservation_pk primary key (ISBN, MEMBER_NO);
alter table RESERVATION
add constraint reservation_item_fk foreign key (ISBN)
references item (ISBN);
alter table RESERVATION
add constraint reservation_member_fk foreign key (MEMBER_NO)
references member (MEMBER_NO);

create table LOAN


(
isbn number(5),
copy_no number(2),
title_no number(5),
member_no number(5),
out_date date not null,
due_date date not null
)
;
alter table LOAN
add constraint loan_pk primary key (ISBN, COPY_NO);
alter table LOAN
add constraint loan_copy_fk foreign key (ISBN, COPY_NO)
references copy (ISBN, COPY_NO);
alter table LOAN
add constraint loan_title_fk foreign key (TITLE_NO)
references title (TITLE_NO);
alter table LOAN
add constraint loan_member_fk foreign key (MEMBER_NO)
references member (MEMBER_NO);

create table ADULT


(
member_no number(5),
street varchar2(15) not null,
city varchar2(15) not null,
state varchar2(2) not null,
zip varchar2(15) not null,
phone_no varchar2(15),
expr_date date not null
)
;
alter table ADULT
add constraint adult_pk primary key (MEMBER_NO);
alter table ADULT
add constraint adult_member_fk foreign key (MEMBER_NO)
references member (MEMBER_NO);

create table JUVENILE


(
member_no number(5),
adult_member_no number(5),
birth_date date not null
)
;
alter table JUVENILE
add constraint juvenile_pk primary key (MEMBER_NO);
alter table JUVENILE
add constraint juvenile_member_fk foreign key (MEMBER_NO)
references member (MEMBER_NO);
alter table JUVENILE
add constraint juvenile_adult_fk foreign key (ADULT_MEMBER_NO)
references adult (MEMBER_NO);

create table LOANHIST


(
isbn number(5),
copy_no number(2),
out_date date,
title_no number(5),
member_no number(5),
due_date date,
in_date date,
fine_assessed number(9,4),
fine_paid number(9,4),
fine_waived number(9,4),
remarks varchar2(50)
)
;
alter table LOANHIST
add constraint loanhist_pk primary key (ISBN, COPY_NO, OUT_DATE);
alter table LOANHIST
add constraint loanhist_copy_fk foreign key (ISBN, COPY_NO)
references copy (ISBN, COPY_NO);
alter table LOANHIST
add constraint loanhist_title_fk foreign key (TITLE_NO)
references title (TITLE_NO);
alter table LOANHIST
add constraint loanhist_member_fk foreign key (MEMBER_NO)
references member (MEMBER_NO);

Das könnte Ihnen auch gefallen