-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1_basicTable.sql
More file actions
54 lines (40 loc) · 1.28 KB
/
Copy pathproject1_basicTable.sql
File metadata and controls
54 lines (40 loc) · 1.28 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
-- CREATE TABLE name(
-- data TYPE
-- );
CREATE TABLE friends (
id INTEGER PRIMARY KEY, --PRIMARY KEY constraint (unique value for identity)
name TEXT UNIQUE, --UNIQUE constraint (unique but other cols can share val)
birthday DATE NOT NULL, --NOT NULL constraint (requires value)
death TEXT DEFAULT 'Not Applicable' --DEFAULT contraint (fills in data if nothing given)
);
-- INSERT INTO for adding data
INSERT INTO friends (id, name, birthday)
VALUES (0, 'Jane Doe', '1998-02-14');
INSERT INTO friends (id, name, birthday)
VALUES (1, 'Jon Loo', '1998-09-24');
INSERT INTO friends (id, name, birthday)
VALUES (2, 'Anthony Gillio', '1997-12-25');
-- SELECT col FROM name for printing
SELECT * FROM friends;
-- UPDATE for changing existing data
UPDATE friends
SET name = 'Jane Smith'
WHERE id = 0;
SELECT * FROM friends;
-- ALTER to add new columns (for now)
ALTER TABLE friends
ADD COLUMN email TEXT;
UPDATE friends
SET email = 'jane@codeacademy.com'
WHERE id = 0;
UPDATE friends
SET email = 'jon@codeacademy.com'
WHERE id = 1;
UPDATE friends
SET email = 'anthony@codeacademy.com'
WHERE id = 2;
SELECT * FROM friends;
-- DELETE FROM table for removing rows (for now)
DELETE FROM friends
WHERE id = 0;
SELECT * FROM friends;