-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create-a-table.sql
90 lines (68 loc) · 1.56 KB
/
Create-a-table.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
/*In this project, you will create your own friends table and add/delete data from it!
Create a table named friends with three columns:
id that stores INTEGER
name that stores TEXT
birthday that stores DATE
*/
CREATE TABLE friends (
id INTEGER,
name TEXT,
birthday DATE
);
/*
Beneath your current code, add Ororo Munroe to friends.
Her birthday is May 30th, 1940.
*/
INSERT INTO friends (
id, name, birthday)
VALUES (1, 'Ororo Munroe', '1940-5-30');
/*
Let’s make sure that Ororo has been added to the database:
*/
SELECT * FROM friends;
/*
Add two of your friends to the table.
Insert an id, name, and birthday for each of them.
*/
INSERT INTO friends (
id, name, birthday)
VALUES (2, 'Naomi Ade', '1995-4-12');
INSERT INTO friends (
id, name, birthday
)
VALUES (3, 'Amen Ogun', '2002-8-12');
/*
Ororo Munroe just realized that she can control the weather and decided to change her name. Her new name is “Storm”.
Update her record in friends.
*/
UPDATE friends
SET name = 'Ororo Munroe'
WHERE id = 1;
/*
Add a new column named email.
*/
ALTER TABLE friends
ADD COLUMN email TEXT;
/*
Update the email address for everyone in your table.
Storm’s email is [email protected].
*/
UPDATE friends
SET email = '[email protected]'
WHERE id = 1;
UPDATE friends
SET email = '[email protected]'
WHERE id = 2;
UPDATE friends
SET email = '[email protected]'
WHERE id = 3;
/*
Wait, Storm is fictional…
Remove her from friends.
*/
DELETE FROM friends
WHERE id = 1;
/*
Great job! Let’s take a look at the result one last time:
*/
SELECT * FROM friends;