Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LaurMo/5621616 to your computer and use it in GitHub Desktop.
Save LaurMo/5621616 to your computer and use it in GitHub Desktop.
First crack at "fun with relational databases" first steps
CREATE TABLE users (
id integer PRIMARY KEY,
name string,
email string
);
CREATE TABLE questions (
id integer PRIMARY KEY,
question varchar,
user_id integer
);
CREATE TABLE comments (
id integer PRIMARY KEY,
comment varchar,
user_id integer,
question_id integer,
comment_id integer
);
CREATE TABLE votes (
id integer PRIMARY KEY,
comments CHECK (boolean),
comment_id integer,
user_id integer
);
@LaurMo
Copy link
Author

LaurMo commented May 21, 2013

Updated one:

CREATE TABLE users (
id integer PRIMARY KEY,
name varchar,
email varchar
);

CREATE TABLE questions (
id integer PRIMARY KEY,
question varchar,
user_id integer
);

CREATE TABLE comments (
id integer PRIMARY KEY,
comment varchar,
user_id integer,
question_id integer,
comment_id integer
);

CREATE TABLE votes (
id integer PRIMARY KEY,
comments boolean,
comment_id integer,
user_id integer
);

@LaurMo
Copy link
Author

LaurMo commented May 21, 2013

INSERT INTO users (1, 'Lauren', 'lmo2u@aol.com')
INSERT INTO users (2, 'LMo', 'lauren.mosenthal@gmail.com')
INSERT INTO users (3, 'Mo', 'lauren.mosenthal@colorado.edu')

CREATE TABLE users (
id integer PRIMARY KEY,
name varchar,
email varchar
);

INSERT INTO questions (1, 'why')
INSERT INTO questions (2, 'who')
INSERT INTO questions (3, 'what')

CREATE TABLE questions (
id integer PRIMARY KEY,
question varchar,
user_id integer
);

INSERT INTO comments (1, 'comment 1')
INSERT INTO comments (2, 'comment 2')
INSERT INTO comments (3, 'comment 3')

CREATE TABLE comments (
id integer PRIMARY KEY,
comment varchar,
user_id integer,
question_id integer,
comment_id integer
);

INSERT INTO votes (1, t )
INSERT INTO votes (2, f )
INSERT INTO votes (3, t )

CREATE TABLE votes (
id integer PRIMARY KEY,
sentiment boolean
comment_id integer,
user_id integer
);

@LaurMo
Copy link
Author

LaurMo commented May 21, 2013

CREATE TABLE users (
id integer PRIMARY KEY,
name varchar,
email varchar
);

INSERT INTO users (id, name, email) VALUES
(1, 'Lauren', 'lmo2u@aol.com'),
(2, 'LMo', 'lauren.mosenthal@gmail.com'),
(3, 'Mo', 'lauren.mosenthal@colorado.edu');

CREATE TABLE questions (
id integer PRIMARY KEY,
question varchar,
user_id integer
);

INSERT INTO questions (id, questions, user_id) VALUES
(1, 'why',1),
(2, 'who',1),
(3, 'what', 2);

CREATE TABLE comments (
id integer PRIMARY KEY,
comment varchar,
user_id integer,
question_id integer,
comment_id integer
);

INSERT INTO comments (id, comment, user_id, question_id, comment_id) VALUES
(1, 'millennials comment',1,2,3),
(2, 'comment from millennial',2,3,1),
(3, 'comment comment',2,2,3);

CREATE TABLE votes (
id integer PRIMARY KEY,
sentiment boolean
comment_id integer,
user_id integer
);

INSERT INTO votes (id, sentiment, comment_id, user_id) VALUES
(1, t ,1,2),
(2, f,1,2),
(3, t,2,3);

@LaurMo
Copy link
Author

LaurMo commented May 21, 2013

CREATE TABLE users (
id integer PRIMARY KEY,
name varchar,
email varchar
);

INSERT INTO users (id, name, email) VALUES
(1, 'Lauren', 'lmo2u@aol.com'),
(2, 'LMo', 'lauren.mosenthal@gmail.com'),
(3, 'Mo', 'lauren.mosenthal@colorado.edu');

CREATE TABLE questions (
id integer PRIMARY KEY,
question varchar,
user_id integer
);

INSERT INTO questions (id, question, user_id) VALUES
(1, 'why',1),
(2, 'who',1),
(3, 'what', 2);

CREATE TABLE comments (
id integer PRIMARY KEY,
comment varchar,
user_id integer,
question_id integer,
comment_id integer
);

INSERT INTO comments (id, comment, user_id, question_id, comment_id) VALUES
(1, 'millennials comment',1,2,3),
(2, 'comment from millennial',2,3,1),
(3, 'comment comment',2,2,3);

CREATE TABLE votes (
id integer PRIMARY KEY,
sentiment boolean
comment_id integer,
user_id integer
);

INSERT INTO votes (id, sentiment, comment_id, user_id) VALUES
(1, 't' ,1,2),
(2, 'f',1,2),
(3, 't',2,3);

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