-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
26 lines (22 loc) · 770 Bytes
/
Copy pathdatabase.sql
File metadata and controls
26 lines (22 loc) · 770 Bytes
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
/* PostgreSQL */
CREATE DATABASE book_store;
CREATE TABLE authors (
author_id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age SMALLINT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE books (
book_id SERIAL PRIMARY KEY,
isbn VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
cant_pages INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
author_id INTEGER,
CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES authors(author_id) ON DELETE CASCADE
);
INSERT INTO authors (name, age) VALUES ('Diego', 29);
INSERT INTO books (isbn, name, cant_pages, author_id) VALUES
('10-000-0000-00-0','Book 1', 100, 1),
('20-000-0000-00-0','Book 2', 200, 1),
('30-000-0000-00-0','Book 3', 300, 1);