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

reate table publishers ( id_publishers integer primary key not null, name varchar(20) not null, city varchar(20)

not null );

create table branches

id_branches integer primary key not null, name varchar(20) not null, location varchar(20) not null, no_employees integer default 0

);

create table authors

id_authors integer primary key, name varchar(20) not null );

create table books

id_books integer primary key, name varchar(20) not null, id_publishers integer not null, foreign key(id_publishers) references publishers(id_publishers),

publish_year integer not null, price integer not null, type varchar(20) not null, paperback varchar(10) not null );

create table books_authors ( id_books integer not null, foreign key(id_books) references books(id_books), id_authors integer not null, foreign key(id_authors) references authors(id_authors) );

create table branches_books ( id_books integer not null, foreign key(id_books) references books(id_books), id_branches integer not null, foreign key(id_branches) references branches(id_branches) );

insert into branches values ( 1, 'Filiala X','Craiova ',23); insert into branches values ( 2, 'Filiala Y','Bucuresti 3',5); insert into branches values ( 3, 'Filiala 22','Pitesti 3',2); insert into branches values ( 4, 'Filiala21','Ploiesti 3',1); insert into branches values ( 5, 'Filiala Z','Timisoara 2',0);

insert into publishers values (1, 'Editor X','Craiova'); insert into publishers values (2, 'Editor Y','Bucuresti'); insert into publishers values (3, 'Editor Z','Pitesti'); insert into publishers values (4, 'Editor 23','Ploiesti'); insert into publishers values (5, 'Editor 5','Timisoara');

insert into authors values ( 1, 'Mihai Eminescu'); insert into authors values ( 2, 'Vasile Alecsandri'); insert into authors values ( 3, 'Liviu Rebreanu'); insert into authors values ( 4, 'Lucian Blaga'); insert into authors values ( 5, 'Jules Verne');

insert into books values ( 1, 'Poezii' , 1 , 2000 , 25 , 'ART', 'true'); insert into books values ( 2, 'Alte poezii' , 1 , 2001 , 35 , ' ART ', 'true'); insert into books values ( 3, 'Povesti' , 1 , 2002 , 31 , ' ART ', 'true'); insert into books values ( 4, 'Moas Craciun' , 2 , 2003 , 53 , ' SF', 'true'); insert into books values ( 5, 'Mos Nicolae' , 2 , 2004 , 63 , ' ART ', 'false'); insert into books values ( 6, 'Perry' , 2 , 2005 , 23 , 'ART', 'true'); insert into books values ( 7, 'Ornitorincul' , 3 , 2006 , 125 , ' ART ', 'true'); insert into books values ( 8, 'Puiul' , 4 , 2007 , 525 , 'ART', 'false'); insert into books values ( 9, 'Ziua Z' , 5 , 2008 , 316 , 'SF', 'true');

insert into books_authors values (1,1); insert into books_authors values (1,2);

insert into books_authors values (2,3); insert into books_authors values (2,4); insert into books_authors values (3,5); insert into books_authors values (4,1); insert into books_authors values (5,1);

insert into branches_books values (1,1); insert into branches_books values (2,1); insert into branches_books values (4,2); insert into branches_books values (5,2); insert into branches_books values (6,3); insert into branches_books values (7,4); insert into branches_books values (8,5);

select name from publishers where city like 'Craiova'; select name from publishers where city not like 'Craiova'; select id_books,name from books where id_books = 1 or id_publishers = 3 ; select id_books,name,price from books where price > 50; select no_employees from branches ;

You might also like