Skip to content

Instantly share code, notes, and snippets.

@mattmarcello
Last active August 29, 2015 14:07
Show Gist options
  • Save mattmarcello/54e527e79871c1d62c5a to your computer and use it in GitHub Desktop.
Save mattmarcello/54e527e79871c1d62c5a to your computer and use it in GitHub Desktop.
-- create database
CREATE DATABASE sportz_teams;
-- connect to database
\c sportz_teams
-- create tables
CREATE TABLE teams (id SERIAL PRIMARY KEY, name varchar(100), location varchar(100), slogan varchar(250));
CREATE TABLE players (id SERIAL PRIMARY KEY, name varchar(100), age integer, team_id integer);
-- create some teams
INSERT INTO teams (name, location, slogan) VALUES ('Lemurs', 'Madagascar Bay', 'Time to climb de fence');
INSERT INTO teams (name, location, slogan) VALUES ('Racoons', 'Jersey', 'Awwwwwwww... No.');
INSERT INTO teams (name, location, slogan) VALUES ('Cheddarsaurs', 'Vermont', 'Time to Smile');
INSERT INTO teams (name, location, slogan) VALUES ('Sailors', 'Atlantic', 'Red sky all day...');
--update team_id's of players
UPDATE players SET team_id=(SELECT id FROM teams WHERE name LIKE 'Racoons')
WHERE name LIKE 'Kathew Bod';
UPDATE players SET team_id=(SELECT id FROM teams WHERE name LIKE 'Cheddarsaurs')
WHERE name LIKE 'Omily';
UPDATE players SET team_id=(SELECT id FROM teams WHERE name LIKE 'Lemurs')
WHERE name LIKE 'Willip';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment