Last active
August 29, 2015 14:07
-
-
Save mattmarcello/54e527e79871c1d62c5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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