-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL1
66 lines (52 loc) · 1.23 KB
/
SQL1
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
DROP TABLE t_student;
CREATE TABLE t_student (
pk INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nm VARCHAR(5) NOT NULL,
ph CHAR(13) NULL,
addr VARCHAR(40),
gender CHAR(1) NOT NULL DEFAULT('남') CHECK(gender IN ('남', '여')),
rdt DATETIME DEFAULT NOW()
);
INSERT INTO t_student
(nm, ph, gender)
VALUES
('가', '010-2222-3333', '여');
SELECT * FROM t_student;
SELECT * FROM t_student;
DROP TABLE t_student;
-- W3C
-- SQL RDB 표준어
-- CRUD, DML
/*
C: Create - insert
R: Read - select
U: Update - update
D: Delete - delete
*/
INSERT INTO t_student
(ph)
VALUES
('010-4567-0987');
INSERT INTO t_student
(nm, ph, addr)
VALUES
('가', '010-0000-0000', '상인동');
-- transaction (트랜잭션) commit, rollback
INSERT INTO t_student
(nm, ph, addr)
VALUES
('나', '010-0000-0001', '대명동'),
('다', '010-0000-0002', '범어동'),
('라', '010-0000-0003', '산격동');
SELECT * FROM t_student;
SELECT nm FROM t_student;
SELECT nm, ph FROM t_student;
SELECT nm, ph, addr FROM t_student
WHERE nm = '가' OR addr = '산격동';
SELECT nm, ph, addr FROM t_student
WHERE nm = '가' AND addr = '상인동';
UPDATE t_student
SET addr = '범어동'
, ph = '010-2222-3333'
WHERE nm = '다';
DELETE FROM t_student WHERE nm = '가';