-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddl.sql
56 lines (56 loc) · 1.73 KB
/
ddl.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
CREATE TABLE author
(
id INTEGER DEFAULT nextval('author_id_seq'::regclass) PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
ob_url TEXT
);
CREATE TABLE book
(
id INTEGER DEFAULT nextval('book_id_seq'::regclass) PRIMARY KEY NOT NULL,
id_genre INTEGER,
title TEXT NOT NULL,
image_url TEXT,
publication_date DATE DEFAULT '1900-01-01'::date NOT NULL,
isbn_10 TEXT,
isbn_13 INTEGER NOT NULL,
description TEXT,
id_publisher INTEGER,
CONSTRAINT book_id_genre_fkey FOREIGN KEY (id_genre) REFERENCES genre (id),
CONSTRAINT book_id_publisher_fkey FOREIGN KEY (id_publisher) REFERENCES publisher (id)
);
CREATE TABLE book_author
(
id INTEGER DEFAULT nextval('book_author_id_seq'::regclass) PRIMARY KEY NOT NULL,
id_author INTEGER,
id_book INTEGER,
CONSTRAINT book_author_id_author_fkey FOREIGN KEY (id_author) REFERENCES author (id),
CONSTRAINT book_author_id_book_fkey FOREIGN KEY (id_book) REFERENCES book (id)
);
CREATE TABLE genre
(
id INTEGER DEFAULT nextval('genre_id_seq'::regclass) PRIMARY KEY NOT NULL,
name TEXT NOT NULL
);
CREATE TABLE publisher
(
id INTEGER DEFAULT nextval('publisher_id_seq'::regclass) PRIMARY KEY NOT NULL,
name TEXT NOT NULL
);
CREATE TABLE shop
(
id INTEGER DEFAULT nextval('shop_id_seq'::regclass) PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
zip TEXT,
street TEXT,
city TEXT,
position TEXT
);
CREATE TABLE storage
(
id INTEGER DEFAULT nextval('storage_id_seq'::regclass) PRIMARY KEY NOT NULL,
id_shop INTEGER,
id_book INTEGER,
amount INTEGER DEFAULT 0 NOT NULL,
CONSTRAINT storage_id_shop_fkey FOREIGN KEY (id_shop) REFERENCES shop (id),
CONSTRAINT storage_id_book_fkey FOREIGN KEY (id_book) REFERENCES book (id)
);