Skip to content

Instantly share code, notes, and snippets.

@jgoerner
Created April 6, 2022 04:10
Show Gist options
  • Save jgoerner/74f0aa4d43cf53657bf82adc9df29d7b to your computer and use it in GitHub Desktop.
Save jgoerner/74f0aa4d43cf53657bf82adc9df29d7b to your computer and use it in GitHub Desktop.
SQLite snippet to create a fraction of a movie database to show the Six Degrees of Kevin Bacon
BEGIN TRANSACTION;
DROP TABLE IF EXISTS "actors";
CREATE TABLE IF NOT EXISTS "actors" (
"actor_id" INTEGER,
"name" TEXT,
PRIMARY KEY("actor_id")
);
DROP TABLE IF EXISTS "roles";
CREATE TABLE IF NOT EXISTS "roles" (
"role_id" INTEGER,
"actor_id" INTEGER,
"movie_id" INTEGER,
PRIMARY KEY("role_id")
);
DROP TABLE IF EXISTS "movies";
CREATE TABLE IF NOT EXISTS "movies" (
"movie_id" INTEGER,
"name" INTEGER,
PRIMARY KEY("movie_id")
);
INSERT INTO "actors" ("actor_id","name") VALUES (1,'Al Pacino'),
(2,'Charlize Theron'),
(3,'Tom Hanks'),
(4,'Kevin Bacon');
INSERT INTO "roles" ("role_id","actor_id","movie_id") VALUES (1,1,1),
(2,2,1),
(3,2,2),
(4,3,2),
(5,3,3),
(6,4,3),
(7,1,4),
(8,1,5);
INSERT INTO "movies" ("movie_id","name") VALUES (1,'The Devil''s Advocate'),
(2,'That Thing You Do'),
(3,'Apollo 13'),
(4,'The Godfather'),
(5,'Any Given Sunday');
COMMIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment