-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise 03 - Combining all Learnings.sql
More file actions
94 lines (68 loc) · 1.8 KB
/
Exercise 03 - Combining all Learnings.sql
File metadata and controls
94 lines (68 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- Exercise 3
USE shirts_db;
-- Create a DB for shirts
CREATE DATABASE shirts_db ;
-- Create Table shirts
CREATE TABLE shirts (
shirt_id INT AUTO_INCREMENT,
article VARCHAR(50) ,
color VARCHAR(50) ,
shirt_size VARCHAR(5) ,
last_worn INT ,
PRIMARY KEY (shirt_id)
);
-- Insert values
INSERT INTO shirts (article, color, shirt_size, last_worn)
VALUES
('t-shirt', 'white', 'S', 10),
('t-shirt', 'green', 'S', 200),
('polo shirt', 'black', 'M', 10),
('tank top', 'blue', 'S', 50),
('t-shirt', 'pink', 'S', 0),
('polo shirt', 'red', 'M', 5),
('tank top', 'white', 'S', 200),
('tank top', 'blue', 'M', 15);
-- Get all the Data
SELECT * FROM shirts;
-- Add A New Shirt: Purple polo shirt, size M last worn 50 days ago
INSERT INTO shirts (article, color, shirt_size, last_worn)
VALUES ('polo shirt', 'purple', 'M', 50);
-- select practice on shirts
SELECT article, color
FROM shirts;
SELECT * FROM shirts
WHERE shirt_size='M';
SELECT article, color, shirt_size, last_worn
FROM shirts
WHERE shirt_size='M';
-- Updating practice
UPDATE shirts
SET
shirt_size = 'L'
WHERE
article = 'polo shirt';
-- ----------------- --
UPDATE shirts
SET
last_worn = 0
WHERE
last_worn = 15;
-- ----------------- --
UPDATE shirts
SET
color = 'off white',
shirt_size = 'XS'
WHERE
color = 'white';
-- Deleting practice
-- always check the where clause with a SELECT statement to ensure deleting the right thing
SELECT * FROM shirts WHERE last_worn=200;
DELETE FROM shirts WHERE last_worn=200;
-- ----------------- --
SELECT * FROM shirts WHERE article='tank top';
DELETE FROM shirts WHERE article='tank top';
-- ----------------- --
SELECT * FROM shirts;
DELETE FROM shirts;
-- ----------------- --
DROP TABLE shirts;