SQL Bookstore V1

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

create table users(

user_id number(30,0) constraint id_u primary key,


name nvarchar2(20)not null,
password nvarchar2(20)not null)

create table writers(


writer_id number(30,0),
writer_name nvarchar2(20)not null,
contact number(30,0)not null,
constraint id_w primary key(writer_id))

create table book_type(


type_id number(30,0),
type nvarchar2(20)not null,
constraint id_t primary key(type_id))

create table genre_type(


genre_id number(30,0),
genre nvarchar2(20)not null,
constraint id_g primary key(genre_id))

create table translator(


translator_id number(30,0),
translator_name nvarchar2(20)not null,
contact number(30,0)not null,
constraint id_tr primary key(translator_id))

create table all_language(


language_id number(30,0),
language nvarchar2(20)not null,
constraint id_lang primary key(language_id))

create table pdf(


pdf_id number(30,0),
book_pdf blob ,
pdf_book_part number(2,0),
constraint id_pdf primary key(pdf_id));

create table printed(


print_id number(30) ,
print_date date,
print_price number(6,3),
Print_count number(3),
constraint id_printed primary key(print_id)
)

create table books(


book_id number(30,0) constraint id_bok_pk primary key,
no_page number(30,0)not null,
print_year number(30,0)not null,
edition number(30,0)not null,
book_title nvarchar2(20)not null,
book_type_id number(30,0) ,
genre_id number(30,0),
written_in_language_id number(30,0),
book_cover blob,
book_pdf_id number(30,0) ,
constraint book_pdf_fk foreign key (book_pdf_id)references pdf(pdf_id),
constraint book_type_fk foreign key (book_type_id)references book_type(type_id),
constraint gen_id_fk foreign key (genre_id)references genre_type(genre_id),
constraint lang_id_fk foreign key(written_in_language_id)references
all_language(language_id),
writer_id number(30,0) constraint writer references writers(writer_id))

create table is_a_translated_books(


book_id number(30,0) constraint id_book_fk references books(book_id),
translated_to_lang number(30,0) constraint translated_to_lang references
all_language(language_id),
translator_id number(30,0),
constraint pk_book_id_translated primary key(book_id)

create table translated_book(


translator_id number(30,0),
language_id number(30,0),
translated_bookID number(30,0),
constraint tr_id foreign key (translator_id)references translator(translator_id),
constraint tr_book_id foreign key (translated_bookID)references books(book_id),
constraint lang_id foreign key (language_id)references all_language(language_id),
constraint trans_books_pk primary key (translated_bookID,translator_id))

create table printed_books(


printed_book number(30) constraint printed_book_id references books(book_id) ,
printing_id number(30) constraint printed_id references printed(print_id)
constraint printed_book_pk primary key
)

create table sales(


sale_id number(30) ,
book_sale_price number(6,3),
sale_date date,
sale_discount number(3,0),
sale_count number(3),
constraint id_sale primary key(sale_id)
)

create table saled_books(


saled_book number(30) constraint saled_book_id references sales(sale_id)
constraint saled_book_id_pk primary key ,
print_id number(30) constraint print_id references printed_books(printing_id)
)
create table users(
user_id number(30,0) constraint id_u primary key,
name nvarchar2(20)not null,
password nvarchar2(20)not null)

create table writers(


writer_id number(30,0),
writer_name nvarchar2(20)not null,
contact number(30,0)not null,
constraint id_w primary key(writer_id))

create table book_type(


type_id number(30,0),
type nvarchar2(20)not null,
constraint id_t primary key(type_id))

create table genre_type(


genre_id number(30,0),
genre nvarchar2(20)not null,
constraint id_g primary key(genre_id))

create table translator(


translator_id number(30,0),
translator_name nvarchar2(20)not null,
contact number(30,0)not null,
constraint id_tr primary key(translator_id))

create table all_language(


language_id number(30,0),
language nvarchar2(20)not null,
constraint id_lang primary key(language_id))

create table pdf(


pdf_id number(30,0),
book_pdf blob ,
pdf_book_part number(2,0),
constraint id_pdf primary key(pdf_id));
create table printed(
print_id number(30) ,
print_date date,
print_price number(6,3),
Print_count number(3),
constraint id_printed primary key(print_id)
)

create table books(


book_id number(30,0) constraint id_bok_pk primary key,
no_page number(30,0)not null,
print_year number(30,0)not null,
edition number(30,0)not null,
book_title nvarchar2(20)not null,
book_type_id number(30,0) ,
genre_id number(30,0),
written_in_language_id number(30,0),
book_pdf_id number(30,0) ,
constraint book_pdf_fk foreign key (book_pdf_id)references pdf(pdf_id),
constraint book_type_fk foreign key (book_type_id)references book_type(type_id),
constraint gen_id_fk foreign key (genre_id)references genre_type(genre_id),
constraint lang_id_fk foreign key(written_in_language_id)references
all_language(language_id),
writer_id number(30,0) constraint writer references writers(writer_id))

create table is_a_translated_books(


book_id number(30,0) constraint id_book_fk references books(book_id),
translated_to_lang number(30,0) constraint translated_to_lang references
all_language(language_id),
translator_id number(30,0),
constraint pk_book_id_translated primary key(book_id)

create table translated_book(


translator_id number(30,0),
language_id number(30,0),
translated_bookID number(30,0),
constraint tr_id foreign key (translator_id)references translator(translator_id),
constraint tr_book_id foreign key (translated_bookID)references books(book_id),
constraint lang_id foreign key (language_id)references all_language(language_id),
constraint trans_books_pk primary key (translated_bookID,translator_id))

create table printed_books(


printed_book number(30) constraint printed_book_id references books(book_id) ,
printing_id number(30) constraint printed_id references printed(print_id)
constraint printed_book_pk primary key
)

create table sales(


sale_id number(30) ,
book_sale_price number(6,3),
sale_date date,
sale_discount number(3,0),
sale_count number(3),
constraint id_sale primary key(sale_id)
)

create table saled_books(


saled_book number(30) constraint saled_book_id references sales(sale_id)
constraint saled_book_id_pk primary key ,
print_id number(30) constraint print_id references printed_books(printing_id)
)

CREATE SEQUENCE seq_book_id


START WITH 1
INCREMENT BY 1
CACHE 10;

insert into book_type(type_id,type) values (seq_btypye_id.nextval,'‫)'ڕۆمان‬

insert into genre_type(genre_id,genre) values (seq_genere_id.nextval,'historical')

insert into genre_type(genre_id,genre) values (seq_genere_id.nextval,'‫)'مێژویی‬

You might also like