Skip to content

Commit 4d608c0

Browse files
change formatting for consistency
1 parent d34654f commit 4d608c0

21 files changed

+482
-397
lines changed

Diff for: albums_migration.sql

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
USE codeup_test_db;
22
DROP TABLE IF EXISTS albums;
33

4-
CREATE TABLE IF NOT EXISTS albums (
5-
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
6-
artist VARCHAR(100) NOT NULL,
7-
name VARCHAR(50) NOT NULL,
4+
CREATE TABLE IF NOT EXISTS albums
5+
(
6+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
7+
artist VARCHAR(100) NOT NULL,
8+
name VARCHAR(50) NOT NULL,
89
release_date INT UNSIGNED,
9-
sales FLOAT UNSIGNED NOT NULL,
10-
genre VARCHAR(150),
10+
sales FLOAT UNSIGNED NOT NULL,
11+
genre VARCHAR(150),
1112
PRIMARY KEY (id)
1213
);
1314

@@ -26,7 +27,9 @@ CREATE TABLE IF NOT EXISTS albums (
2627
#
2728
# DELETE FROM albums WHERE release_date < 2000; #deletes all under 2000
2829

29-
SELECT 'albums' as prefix , a.* FROM albums a WHERE release_date > 2021;
30+
SELECT 'albums' as prefix, a.*
31+
FROM albums a
32+
WHERE release_date > 2021;
3033

3134
DESCRIBE albums;
3235

Diff for: albums_seeder.sql

+65-66
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,71 @@
11
USE codeup_test_db;
22
TRUNCATE albums; #removes, ends up with same number, prevents copies
33
INSERT INTO albums(artist, name, release_date, sales, genre)
4-
VALUES
5-
('Michael Jackson', 'Thriller', 1982, 49200000,
6-
'pop, post-disco, funk, rock'),
7-
('AC/DC', 'Back in Black', 1980, 29500000,
8-
'hard rock'),
9-
('Whitney Houston', 'The Bodyguard', 1992, 32400000,
10-
'R&B, soul, pop, soundtrack'),
11-
('Meat Loaf', 'Bat Out of Hell', 1977, 21700000,
12-
'hard rock, glam rock, progressive rock'),
13-
('Eagles', 'Their Greatest Hits', 1976, 41200000,
14-
'country rock, soft rock, folk rock'),
15-
('Pink Floyd', 'The Dark Side of the Moon', 1973, 24400000,
16-
'progressive rock'),
17-
('Eagles', 'Hotel California', 1976, 31500000,
18-
'soft rock'),
19-
('Bee Gees', 'Saturday Night Fever', 1977, 21600000,
20-
'disco'),
21-
('Fleetwood Mac', 'Rumors', 1977, 27900000,
22-
'soft rock'),
23-
('Shania Twain', 'Come On Over', 1997, 29600000,
24-
'country, pop'),
25-
('One Greaser', 'Grease: The Original Soundtrack', 1978, 14400000,
26-
'rock and roll'),
27-
('Led Zeppelin', 'Led Zeppelin IV', 1971, 29000000,
28-
'hard rock, heavy metal, folk rock'),
29-
('Michael Jackson', 'Bad', 1987, 21100000,
30-
'pop, rhythm and blues, funk and rock'),
31-
('Alanis Morissette', 'Jagged Little Pill', 1995, 24300000,
32-
'alternative rock'),
33-
('Michael Jackson', 'Dangerous', 1991, 17000000,
34-
'New jack swing, R&B and pop'),
35-
('Celine Dion', 'Falling into You', 1996, 21100000,
36-
'pop, soft rock'),
37-
('The Beatles', 'Sgt. Pepper\'s Lonely Hearts Club Band', 1967, 18200000,
38-
'rock'),
39-
('One Singer', 'Dirty Dancing', 1987, 17900000,
40-
'Pop, rock, R&B'),
41-
('Adele', '21', 2011, 26400000,
42-
'Pop, soul'),
43-
('Celine Dion', 'Let\'s Talk About Love', 1997, 19300000,
44-
'Pop, soft rock'),
45-
('Metallica', 'Metallica', 1991, 25200000,
46-
'Heavy metal'),
47-
('The Beatles', '1', 2000, 23500000,
48-
'rock'),
49-
('The Beatles', 'Abbey Road', 1969, 14400000,
50-
'rock'),
51-
('ABBA', 'Gold: Greatest Hits', 1992, 23000000,
52-
'Pop, disco'),
53-
('Bruce Springsteen', 'Born in the U.S.A.', 1984, 19600000,
54-
'Heartland rock'),
55-
('Madonna', 'The Immaculate Collection', 1990, 19500000,
56-
'Pop, dance'),
57-
('Pink Floyd', 'The Wall', 1979, 18700000,
58-
'Progressive rock'),
59-
('James Horner', 'Titanic: Music from the Motion Picture', 1997, 18100000, 'Film score'),
60-
('Dire Straits', 'Brothers in Arms', 1985, 17700000,
61-
'Roots rock, blues rock, soft rock'),
62-
('Nirvana', 'Nevermind', 1991, 16700000,
63-
'Grunge, alternative rock'),
64-
('Santana', 'Supernatural', 1999, 20500000,
65-
'Latin rock'),
66-
('Guns N\' Roses', 'Appetite for Destruction', 1987, 21900000,
67-
'Hard rock'),
68-
('Elton John', 'Goodbye Yellow Brick Road', 1973, 8500000,
69-
'rock, pop rock, glam rock');
4+
VALUES ('Michael Jackson', 'Thriller', 1982, 49200000,
5+
'pop, post-disco, funk, rock'),
6+
('AC/DC', 'Back in Black', 1980, 29500000,
7+
'hard rock'),
8+
('Whitney Houston', 'The Bodyguard', 1992, 32400000,
9+
'R&B, soul, pop, soundtrack'),
10+
('Meat Loaf', 'Bat Out of Hell', 1977, 21700000,
11+
'hard rock, glam rock, progressive rock'),
12+
('Eagles', 'Their Greatest Hits', 1976, 41200000,
13+
'country rock, soft rock, folk rock'),
14+
('Pink Floyd', 'The Dark Side of the Moon', 1973, 24400000,
15+
'progressive rock'),
16+
('Eagles', 'Hotel California', 1976, 31500000,
17+
'soft rock'),
18+
('Bee Gees', 'Saturday Night Fever', 1977, 21600000,
19+
'disco'),
20+
('Fleetwood Mac', 'Rumors', 1977, 27900000,
21+
'soft rock'),
22+
('Shania Twain', 'Come On Over', 1997, 29600000,
23+
'country, pop'),
24+
('One Greaser', 'Grease: The Original Soundtrack', 1978, 14400000,
25+
'rock and roll'),
26+
('Led Zeppelin', 'Led Zeppelin IV', 1971, 29000000,
27+
'hard rock, heavy metal, folk rock'),
28+
('Michael Jackson', 'Bad', 1987, 21100000,
29+
'pop, rhythm and blues, funk and rock'),
30+
('Alanis Morissette', 'Jagged Little Pill', 1995, 24300000,
31+
'alternative rock'),
32+
('Michael Jackson', 'Dangerous', 1991, 17000000,
33+
'New jack swing, R&B and pop'),
34+
('Celine Dion', 'Falling into You', 1996, 21100000,
35+
'pop, soft rock'),
36+
('The Beatles', 'Sgt. Pepper\'s Lonely Hearts Club Band', 1967, 18200000,
37+
'rock'),
38+
('One Singer', 'Dirty Dancing', 1987, 17900000,
39+
'Pop, rock, R&B'),
40+
('Adele', '21', 2011, 26400000,
41+
'Pop, soul'),
42+
('Celine Dion', 'Let\'s Talk About Love', 1997, 19300000,
43+
'Pop, soft rock'),
44+
('Metallica', 'Metallica', 1991, 25200000,
45+
'Heavy metal'),
46+
('The Beatles', '1', 2000, 23500000,
47+
'rock'),
48+
('The Beatles', 'Abbey Road', 1969, 14400000,
49+
'rock'),
50+
('ABBA', 'Gold: Greatest Hits', 1992, 23000000,
51+
'Pop, disco'),
52+
('Bruce Springsteen', 'Born in the U.S.A.', 1984, 19600000,
53+
'Heartland rock'),
54+
('Madonna', 'The Immaculate Collection', 1990, 19500000,
55+
'Pop, dance'),
56+
('Pink Floyd', 'The Wall', 1979, 18700000,
57+
'Progressive rock'),
58+
('James Horner', 'Titanic: Music from the Motion Picture', 1997, 18100000, 'Film score'),
59+
('Dire Straits', 'Brothers in Arms', 1985, 17700000,
60+
'Roots rock, blues rock, soft rock'),
61+
('Nirvana', 'Nevermind', 1991, 16700000,
62+
'Grunge, alternative rock'),
63+
('Santana', 'Supernatural', 1999, 20500000,
64+
'Latin rock'),
65+
('Guns N\' Roses', 'Appetite for Destruction', 1987, 21900000,
66+
'Hard rock'),
67+
('Elton John', 'Goodbye Yellow Brick Road', 1973, 8500000,
68+
'rock, pop rock, glam rock');
7069

7170

7271

Diff for: aliases_exercises.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ USE employees;
44
#in the format of 'last name, first name' for each employee.
55

66
SELECT CONCAT(emp_no, '-', last_name, ',', first_name) AS full_name, #alias... like var
7-
birth_date AS DOB #like var...
7+
birth_date AS DOB #like var...
88
FROM employees;

Diff for: blog_app

+46-34
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,83 @@
1-
CREATE TABLE IF NOT EXISTS users (
2-
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
3-
name VARCHAR(50),
4-
email VARCHAR (100),
5-
job_title VARCHAR (100),
6-
address VARCHAR (200),
1+
CREATE TABLE IF NOT EXISTS users
2+
(
3+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
4+
name VARCHAR(50),
5+
email VARCHAR(100),
6+
job_title VARCHAR(100),
7+
address VARCHAR(200),
78
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
89
PRIMARY KEY (id)
9-
);
10+
);
1011
CREATE DATABASE IF NOT EXISTS blog_app;
1112
-- pluralizing the name of the table
1213
USE blog_app;
1314
# Creating a table
1415

1516
DROP TABLE IF EXISTS users;
16-
CREATE TABLE IF NOT EXISTS users (
17+
CREATE TABLE IF NOT EXISTS users
18+
(
1719
# unsigned,NOT SIGNED , no negative values!
18-
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
19-
name VARCHAR(50) NOT NULL,
20-
email VARCHAR(100),
21-
job_title VARCHAR(100),
22-
address VARCHAR(200),
23-
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
24-
PRIMARY KEY (id)
20+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
21+
name VARCHAR(50) NOT NULL,
22+
email VARCHAR(100),
23+
job_title VARCHAR(100),
24+
address VARCHAR(200),
25+
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
26+
PRIMARY KEY (id)
2527
);
2628

2729
DROP TABLE IF EXISTS posts;
28-
CREATE TABLE IF NOT EXISTS posts (
29-
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
30+
CREATE TABLE IF NOT EXISTS posts
31+
(
32+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
3033
user_id INT UNSIGNED NOT NULL,
31-
title VARCHAR(100),
32-
body TEXT,
34+
title VARCHAR(100),
35+
body TEXT,
3336
PRIMARY KEY (id)
3437
);
3538

3639

3740
DROP TABLE IF EXISTS posts_label;
38-
CREATE TABLE IF NOT EXISTS posts_label (
39-
post_id INT UNSIGNED NOT NULL, -- relates to table post.id
40-
label_id INT UNSIGNED NOT NULL -- relates to table labels.id
41+
CREATE TABLE IF NOT EXISTS posts_label
42+
(
43+
post_id INT UNSIGNED NOT NULL, -- relates to table post.id
44+
label_id INT UNSIGNED NOT NULL -- relates to table labels.id
4145
);
4246

4347
DROP TABLE IF EXISTS labels;
44-
CREATE TABLE IF NOT EXISTS labels (
45-
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
48+
CREATE TABLE IF NOT EXISTS labels
49+
(
50+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
4651
# only characters 25 max, not to be empty, or null
47-
name CHAR(25) NOT NULL,
52+
name CHAR(25) NOT NULL,
4853
primary key (id)
4954
);
5055

5156

5257
INSERT INTO users (name, email, job_title, address)
53-
VALUES ('Dane Miller', '[email protected]','Web Developer and Instructor', '1234 my place');
58+
VALUES ('Dane Miller', '[email protected]', 'Web Developer and Instructor', '1234 my place');
5459

5560
INSERT INTO posts (user_id, title, body)
56-
VALUES (1,'My first post', 'lots of text and stuff here');
61+
VALUES (1, 'My first post', 'lots of text and stuff here');
5762

58-
INSERT INTO labels (name) VALUES ('Awesome');
59-
INSERT INTO labels (name) VALUES ('The worst');
60-
INSERT INTO labels (name) VALUES ('Ok');
63+
INSERT INTO labels (name)
64+
VALUES ('Awesome');
65+
INSERT INTO labels (name)
66+
VALUES ('The worst');
67+
INSERT INTO labels (name)
68+
VALUES ('Ok');
6169

6270

63-
INSERT INTO posts_label (post_id, label_id) VALUES (1,1), (1,2), (1,3);
71+
INSERT INTO posts_label (post_id, label_id)
72+
VALUES (1, 1),
73+
(1, 2),
74+
(1, 3);
6475

6576

66-
SELECT p.id, l.name as label_name FROM posts p
67-
INNER JOIN posts_label pl ON (pl.post_id = p.id)
68-
INNER JOIN labels l ON (l.id = pl.label_id)
77+
SELECT p.id, l.name as label_name
78+
FROM posts p
79+
INNER JOIN posts_label pl ON (pl.post_id = p.id)
80+
INNER JOIN labels l ON (l.id = pl.label_id)
6981
WHERE p.id = 1;
7082

7183
# describing tables

Diff for: clauses_lecture.sql

+19-22
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@ USE employees;
55
# LIKE keyword - for finding results that contain a substring
66
# Select the last name from all employees with a last name ending in z
77

8-
SELECT last_name FROM employees
8+
SELECT last_name
9+
FROM employees
910
WHERE last_name LIKE 'a%z%';
1011

1112

1213

1314
# DISTINCT - for filtering out duplicate results
1415
# Select distinct first names from employees where first name contains a z
1516

16-
SELECT first_name, last_name FROM employees
17+
SELECT first_name, last_name
18+
FROM employees
1719
WHERE first_name LIKE 'a%z%';
1820

19-
SELECT first_name FROM employees
21+
SELECT first_name
22+
FROM employees
2023
WHERE first_name LIKE 'a%z%';
2124

22-
SELECT DISTINCT first_name FROM employees
25+
SELECT DISTINCT first_name
26+
FROM employees
2327
WHERE first_name LIKE 'a%z%';
2428

25-
SELECT DISTINCT first_name, last_name FROM employees
29+
SELECT DISTINCT first_name, last_name
30+
FROM employees
2631
WHERE first_name LIKE 'a%z%';
2732

2833

@@ -31,7 +36,8 @@ WHERE first_name LIKE 'a%z%';
3136

3237
describe employees;
3338

34-
SELECT * FROM employees
39+
SELECT *
40+
FROM employees
3541
WHERE emp_no BETWEEN 10001 AND 10010
3642
OR emp_no BETWEEN 10201 AND 10210;
3743

@@ -42,15 +48,15 @@ FROM employees
4248
WHERE first_name LIKE 'Georgi'
4349
OR first_name LIKE 'Parto';
4450
#is the same as...
45-
SELECT * from employees where first_name IN ('Georgi', 'Parto');
51+
SELECT *
52+
from employees
53+
where first_name IN ('Georgi', 'Parto');
4654
# REFACTOR...
4755
SELECT *
4856
FROM employees
4957
WHERE first_name IN ('Georgi', 'Parto');
5058

5159

52-
53-
5460
# Select employee number, first name, last name for employees with a last name of Herber, Dredge, Lipner, or Baek
5561
SELECT emp_no, first_name, last_name
5662
FROM employees
@@ -60,7 +66,8 @@ describe employees;
6066

6167
# Chaining WHERE clauses - for defining multiple filtering criteria
6268
# Select all data from female employees where employee number is less than 10200
63-
SELECT * FROM employees
69+
SELECT *
70+
FROM employees
6471
WHERE gender = 'F'
6572
AND emp_no < 10200;
6673

@@ -83,13 +90,6 @@ WHERE emp_no < 10200
8390

8491

8592

86-
87-
88-
89-
90-
91-
92-
9393
# ======================== ORDER BY
9494

9595
# Select employee first and last names from highest to lowest employee number
@@ -125,11 +125,8 @@ WHERE first_name = 'Leni'
125125
ORDER by gender DESC, last_name;
126126

127127

128-
129-
130-
131-
132128
# ======================== LIMIT / OFFSET
133129

134-
SELECT * FROM employees
130+
SELECT *
131+
FROM employees
135132
LIMIT 16 OFFSET 0;

0 commit comments

Comments
 (0)