Skip to content

Instantly share code, notes, and snippets.

@andrew8088
Created July 6, 2012 01:41
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 andrew8088/3057504 to your computer and use it in GitHub Desktop.
Save andrew8088/3057504 to your computer and use it in GitHub Desktop.
Intrepid Detectives database for the SQL Essentials course for Tuts+ Premium
CREATE DATABASE intrepid_detectives;
USE intrepid_detectives;
CREATE TABLE detectives(
id INTEGER NOT NULL AUTO_INCREMENT,
first_name VARCHAR(50),
last_name VARCHAR(50) NOT NULL,
phone_number VARCHAR(10) NOT NULL,
certification_date DATE NOT NULL,
CONSTRAINT detectives_pk PRIMARY KEY (id)
);
CREATE TABLE criminals(
id INTEGER NOT NULL AUTO_INCREMENT,
first_name VARCHAR(50),
last_name VARCHAR(50) NOT NULL,
date_of_birth DATE NOT NULL,
CONSTRAINT criminals_pk PRIMARY KEY (id)
);
CREATE TABLE cases(
id INT NOT NULL AUTO_INCREMENT,
detective_id INTEGER NOT NULL,
criminal_id INTEGER NOT NULL,
title VARCHAR(100),
start_date DATE NOT NULL,
hours_to_solve INT,
CONSTRAINT cases_pk PRIMARY KEY (id),
CONSTRAINT detective_fk FOREIGN KEY (detective_id) REFERENCES detectives(id),
CONSTRAINT criminal_fk FOREIGN KEY (criminal_id) REFERENCES criminals(id)
);
SELECT TOP 5 * FROM cases;
INSERT INTO detectives
VALUES(1, "Carlotta", "McOwen", "8061234567", "2004-04-05"),
(2, "Luther", "Ellery", "8069865433", "1995-11-20"),
(3, "Finch", "Hosky", "3170987654", "2010-07-18"),
(4, "Carson", "Andrews", "3174561230", "2009-01-31"),
(5, "Mac", "Parker","7280912345", "1998-05-25"),
(6, "", "Barney", '9081234567', '2001-04-08');
INSERT INTO criminals
VALUES(1, "Jim", "Roberts", "1970-12-12"),
(2, "Alec","Ivanes", "1984-10-03"),
(3, "Garland", "Ernest", "1989-03-14"),
(4, "Luke", "Malcolm", "1992-07-28"),
(5, "Tyrell", "Preston", "1978-09-13");
INSERT INTO cases
VALUES(1, 1, 1, "Finnigan's Fault", '2008-09-26', 24 * 4),
(2, 2, 3, "The Missing Tree", '2006-12-30', 24 * 2),
(3, 3, 2, "A Case of Allergies", '2004-03-12', 24 * 2.5),
(4, 4, 5, "The Man that Shouldn't have Been", '2001-09-12', 300),
(5, 2, 4, "Digital Nightmare", '2010-10-10', 23),
(6, 1, 3, "Evidentially Frozen", '2008-07-07', 240),
(7, 5, 2, "The Other Car", '2004-11-12', 489),
(8, 5, 5, "Valentine's Dagger", '2011-02-14', 29),
(9, 3, 1, "All Three Hats", "2002-08-15", 340);
@gubnota
Copy link

gubnota commented Nov 24, 2013

In the TutsPlus course there is MySQL DB server, but that syntax wouldn't work with it.

SELECT TOP 5 * FROM cases; cause syntax error with MySQL like database servers (MariaDB in mine case),
may be it would be better to separate with two files for that expression, like:
SELECT * FROM cases LIMIT 5;

for MySQL like DB Servers?

@fedelibre
Copy link

@gubnota thanks, without your fix the tables are copied but not the values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment