Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SQL


See [the Lambda page on Relational
Databases](https://github.com/LambdaSchool/Relational-Databases) for more
information. (Note that page is for PostgreSQL, but the SQL information is valid
Expand Down
Binary file added mydatabase.db
Binary file not shown.
41 changes: 41 additions & 0 deletions notes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
PRAGMA foreign_keys = ON;

DROP TABLE IF EXISTS notes;
DROP TABLE IF EXISTS author;

create table notes (
id integer primary key autoincrement,
title varchar(128),
content varchar(128),
created_on datetime,
author_id integer,
foreign key(author_id) references author(id)
);

create table author (
id integer primary key autoincrement,
name varchar(128)
);

insert into author (name) values ("Jane Austen");
insert into author (name) values ("PG Wodehouse");
insert into author (name) values ("Mortimer Adler");
insert into author (name) values ("Anton Chekhov");

insert into notes (title, content, created_on, author_id) values ("Pride and Prejudice", "It is a truth universally acknowledged...", current_timestamp, 1);
insert into notes (title, content, created_on, author_id) values ("Jeeves and Wooster", "Good morning, Jeeves!", current_timestamp, 2);
insert into notes (title, content, created_on, author_id) values ("How to Read a Book", "In the case of books...", current_timestamp, 3);

select title, content from notes, author
where notes.author_id = author.id and
author.name = "Jane Austen";

select name from notes, author
where notes.author_id = author.id and
notes.id = 3;

select name, count(*) from notes, author
where notes.author_id = author.id
group by author_id;

delete from author where id >= 4;