-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial1.sql
More file actions
48 lines (36 loc) · 1.24 KB
/
tutorial1.sql
File metadata and controls
48 lines (36 loc) · 1.24 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
/*CREATE = create*/
/*ADD = insert*/
/*SHOW = select*/
/*UPDATE = update*/
/*ALTER = alter (like adding a column)*/
/*DELETE = delete*/
/*CREATE empty table*/
create table celebs (id integer, name text, age integer);
/*ADD one entry that fills these columns*/
insert into celebs (id, name, age) values (1, 'Justin Bieber', 21);
/*SHOW everything in table*/
select * from celebs;
/*add other entries*/
insert into celebs (id, name, age) values (2, 'Beyonce Knowles', 33);
insert into celebs (id, name, age) values (3, 'Jeremy Lin', 26);
insert into celebs (id, name, age) values (4, 'Taylor Swift', 26);
/*show all entries under this column in this table*/
select name from celebs;
/*UPDATE table by setting a value based on a condition*/
update celebs
set age = 22
where id = 1;
/*show everything in table*/
select * from celebs;
/*ALTER table by adding new column to table*/
alter table celebs add column twitter_handle text;
/*show everything in table*/
select * from celebs;
/*update table by setting a value based on a condition*/
update celebs
set twitter_handle = '@taylorswift13'
where id = 4;
/*DELETE all from table that fall under a condition*/
delete from celebs where twitter_handle is null;
/*show everything in table*/
select * from celebs;