Skip to content

Instantly share code, notes, and snippets.

@sohamkamani
Last active October 12, 2023 19:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sohamkamani/c6820c3edd7608afb085763a33877edb to your computer and use it in GitHub Desktop.
Save sohamkamani/c6820c3edd7608afb085763a33877edb to your computer and use it in GitHub Desktop.
Script to create tables for my tutorial on https://www.sohamkamani.com/sql-guide/
CREATE TABLE books (
bookid serial PRIMARY KEY,
title text,
author text,
published date,
stock int
);
INSERT INTO
books (bookid, title, author, published, stock)
VALUES
(
1,
'Scion of Ikshvaku',
'Amish Tripathi',
'06-22-2015',
2
),
(
2,
'The Lost Symbol',
'Dan Brown',
'07-22-2010',
3
),
(
3,
'Who Will Cry When You Die?',
'Robin Sharma',
'06-15-2006',
4
),
(4, 'Inferno', 'Dan Brown', '05-05-2014', 3),
(
5,
'The Fault in our Stars',
'John Green',
'01-03-2015',
3
);
CREATE TABLE members (
memberid serial PRIMARY KEY,
firstname text,
lastname text
);
INSERT INTO
members (firstname, lastname)
VALUES
('Mike', 'Willis'),
('Ellen', 'Horton'),
('John', 'Doe');
CREATE TABLE borrowings (
bookid int,
memberid int,
returndate date
);
INSERT INTO
borrowings (bookid, memberid, returndate)
VALUES
(1, 3, '2022-03-19'),
(2, 1, '2022-03-23'),
(3, 3, '2022-03-30'),
(2, 2, '2022-04-19'),
(4, 2, '2022-04-19');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment