-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.CRUD Challenges.sql
102 lines (76 loc) · 2.02 KB
/
06.CRUD Challenges.sql
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
95
96
97
98
99
100
101
102
/*
Shirt table
*/
shirt_id article color shirt_size last_worn
---------------------------------------------------------
1 t-shirt white S 10
2 t-shirt green S 200
3 polo shirt black M 10
4 tank top blue S 50
5 t-shirt pink S 0
6 polo shirt red M 5
7 tank top white S 200
8 tank top blue M 15
/*create table shirts*/
CREATE TABLE shirts(
shirt_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
article VARCHAR(50),
color VARCHAR(50),
shirt_size VARCHAR(1),
last_worn INT
);
SHOW TABLES;
DESC shirts;
/*add 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 That Data In There With a single line*/
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 all shirts
But Only Print Out Article and Color*/
SELECT article,color
FROM shirts;
/*SELECT all medium shirts
Print Out Everything But shirt_id*/
SELECT article,color,shirt_size,last_worn FROM shirts
WHERE shirt_size = 'M';
/*Update all polo shirts
Change their size to L*/
UPDATE shirts
SET shirt_size = 'L'
WHERE article = 'polo shirt';
/*Update the shirt last worn 15 days ago
Change last_worn to 0*/
UPDATE shirts
SET last_worn = 0
WHERE last_worn = 15;
/*alter table of shirtsize*/
ALTER TABLE shirts
MODIFY COLUMN shirt_size VARCHAR(2);
/*Update all white shirts
Change size to 'XS' and color to 'off white'*/
UPDATE shirts
SET color = 'off white',
shirt_size = 'XS'
WHERE color = 'white';
/*Delete all old shirts
Last worn 200 days ago*/
DELETE FROM shirts
WHERE last_worn = 200;
/*Delete all tank tops
Your tastes have changed...*/
DELETE FROM shirts
WHERE article = 'tank top';
/*Delete all shirts*/
DELETE FROM shirts;