Created
July 18, 2020 03:48
-
-
Save abranhe/444a77f3325af1c833481481571bc002 to your computer and use it in GitHub Desktop.
Example SQL Relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE books ( | |
id serial, | |
title varchar(100) NOT NULL, | |
author varchar(100) NOT NULL, | |
published_date timestamp NOT NULL, | |
isbn char(12), | |
PRIMARY KEY (id), | |
UNIQUE (isbn) | |
); | |
CREATE TABLE reviews ( | |
id serial, | |
book_id integer NOT NULL, | |
reviewer_name varchar(255), | |
content varchar(255), | |
rating integer, | |
published_date timestamp DEFAULT CURRENT_TIMESTAMP, | |
PRIMARY KEY (id), | |
FOREIGN KEY (book_id) REFERENCES books(id) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE books ( | |
id serial, | |
title varchar(100) NOT NULL, | |
author varchar(100) NOT NULL, | |
published_date timestamp NOT NULL, | |
isbn char(12), | |
PRIMARY KEY (id), | |
UNIQUE (isbn) | |
); | |
CREATE TABLE reviews ( | |
id serial, | |
book_id integer REFERENCES books(id), | |
reviewer_name varchar(255), | |
content varchar(255), | |
rating integer, | |
published_date timestamp DEFAULT CURRENT_TIMESTAMP, | |
PRIMARY KEY (id) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment