-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#498] SQL์ DDL, DML, DCL, TCL
- Loading branch information
Showing
1 changed file
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# SQL์ DDL, DML, DCL, TCL | ||
|
||
## ์๋ก | ||
|
||
- SQL(Structured Query Language)๋ ๊ตฌ์กฐ์ ์ง์ ์ธ์ด๋ผ๋ ์๋ฏธ๋ก ์ง์ ์ธ์ด๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ ์ด, ๊ด๋ฆฌ ํ ์ ์๋ค. | ||
- SQL์ DDL, DML, DCL๋ก ๋๋ ์ ์์ต๋๋ค. | ||
- ๊ฐ ์ธ์ด์ ํน์ง์ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. | ||
- ํด๋น ๋ชจ๋ ํ ์คํธ๋ MySQL 8.0.17 ํ๊ฒฝ์์ ์งํํฉ๋๋ค. | ||
|
||
## DDL(Data Definition Language) - ๋ฐ์ดํฐ ์ ์ ์ธ์ด | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ ์ํ๋ ์ธ์ด๋ก ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑ, ์์ , ์ญ์ ๋ฑ์ ์ญํ ์ ํ๋ ์ธ์ด | ||
|
||
### CREATE | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค, ํ ์ด๋ธ์ ๋ง๋๋ ์ญํ | ||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์์ฑ | ||
|
||
```sql | ||
CREATE database test | ||
``` | ||
|
||
![sql_purpose_kinds-1](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-1.png?raw=true) | ||
|
||
- ํ ์ด๋ธ ์์ฑ | ||
|
||
```sql | ||
CREATE table user ( | ||
user_id int not null, | ||
name char(16) not null, | ||
email char(16) not null, | ||
primary key(user_id) | ||
); | ||
``` | ||
|
||
![sql_purpose_kinds-2](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-2.png?raw=true) | ||
|
||
### ALTER | ||
|
||
- ํ ์ด๋ธ์ ์์ ํ๋ ์ญํ | ||
- ํ ์ด๋ธ์ ์ปฌ๋ผ์ ์ถ๊ฐํ๋ SQL | ||
|
||
```sql | ||
ALTER TABLE user ADD age int; | ||
``` | ||
|
||
![sql_purpose_kinds-3](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-3.png?raw=true) | ||
|
||
### DROP | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค, ํ ์ด๋ธ์ ์ญ์ ํ๋ ์ญํ | ||
- ํ ์ด๋ธ ์ญ์ ํ๋ SQL | ||
|
||
```sql | ||
DROP TABLE user; | ||
``` | ||
|
||
![sql_purpose_kinds-4](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-4.png?raw=true) | ||
|
||
### TRUNCATE | ||
|
||
- ํ ์ด๋ธ์ ์ด๊ธฐํํ๋ ์ญํ | ||
|
||
## DML(Data Manipulation Language) - ๋ฐ์ดํฐ ์กฐ์ ์ธ์ด | ||
|
||
- ์ ์๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๋ ฅ๋ ๋ ์ฝ๋๋ฅผ ์ฝ์ ,์กฐํ,์์ ,์ญ์ ๋ฅผ ํ๋ ์ธ์ด | ||
|
||
### SELECT | ||
|
||
- ๋ ์ฝ๋๋ฅผ ์กฐํํ๋ ์ญํ | ||
- ๋ ์ฝ๋ ์ ์ฒด ์กฐํ SQL | ||
|
||
```sql | ||
SELECT * FROM user | ||
``` | ||
|
||
![sql_purpose_kinds-2](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-2.png?raw=true) | ||
|
||
### INSERT | ||
|
||
- ๋ ์ฝ๋๋ฅผ ์ฝ์ ํ๋ ์ญํ | ||
- ํ๊ฐ์ ๋ ์ฝ๋๋ฅผ ์ฝ์ ํ๋ SQL | ||
|
||
```sql | ||
INSERT INTO user(user_id, name, email) VALUES (1, 'rutgo', '[email protected]'); | ||
``` | ||
|
||
![sql_purpose_kinds-5](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-5.png?raw=true) | ||
|
||
### UPDATE | ||
|
||
- ๋ ์ฝ๋๋ฅผ ์์ ํ๋ ์ญํ | ||
- email์ ๋ณ๊ฒฝํ๋ SQL | ||
|
||
```sql | ||
UPDATE user | ||
SET email='[email protected]' | ||
WHERE user_id = 1; | ||
``` | ||
|
||
![sql_purpose_kinds-6](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-6.png?raw=true) | ||
|
||
### DELETE | ||
|
||
- ๋ ์ฝ๋๋ฅผ ์ญ์ ํ๋ ์ญํ | ||
|
||
```sql | ||
DELETE FROM user | ||
WHERE user_id = 1; | ||
``` | ||
|
||
![sql_purpose_kinds-7](https://github.com/ksy90101/TIL/blob/master/database/image/sql_purpose_kinds-7.png?raw=true) | ||
|
||
## DCL(Data Control Language) - ๋ฐ์ดํฐ ์ ์ด ์ธ์ด | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ทผํ๊ฑฐ๋ ๊ฐ์ฒด์ ๊ถํ์ ์ฃผ๋ ์ญํ ์ ํ๋ ์ธ์ด | ||
|
||
### GRANT | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฌ์ฉ์์๊ฒ ๊ถํ์ ์ฃผ๋ ์ญํ | ||
|
||
### REVOKE | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฌ์ฉ์์๊ฒ ๊ถํ์ ๋ฐํํ๋ ์ญํ | ||
|
||
### COMMIT | ||
|
||
- ํธ๋์ญ์ ์ ์์ ์ด ์ ์์ ์ด๋ผ๋ฉด ๋ฐ์ํ๋ ์ญํ | ||
|
||
### ROLLBACK | ||
|
||
- ํธ๋์ญ์ ์์ ์ด ๋น์ ์์ ์ด๋ผ๋ฉด ๋ค์ ๋๋๋ฆฌ๋ ์ญํ | ||
|
||
### SET TRANSACTION | ||
|
||
- ํธ๋์ญ์ ๋ชจ๋ ์ค์ ํ๋ ์ญํ | ||
- ์๋ฅผ๋ค๋ฉด ํธ๋์ญ์ ๊ฒฉ๋ฆฌ ์์ค๋ฑ์ ์ค์ ํ๋ค | ||
|
||
### BEGIN | ||
|
||
- ํธ๋์ญ์ ์์ญ | ||
|
||
### SAVEPOINT | ||
|
||
- ์ ์ฅ ์ง์ ์ ์ค์ ํ๋ ๊ฒ์ผ๋ก ์์ ์ ์ฅ์ด๋ผ๊ณ ์๊ฐํ๋ฉด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค. | ||
|
||
### LOCK | ||
|
||
- ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฆฌ์์ค ์ ๊ทผ ์ ํ์ ํ๊ธฐ ์ํ ๋ช ๋ น์ด | ||
|
||
## TCL(Transaction Control Language) | ||
|
||
- DCL์์ COMMIT๊ณผ ROLLBACK, SAVEPONT์ ์ง์นญํ๋ค. | ||
- ์ฆ, ํธ๋์ญ์ ์ ์ ์ดํ๋ ์ธ์ด์ด๋ค. | ||
|
||
## ๊ฒฐ๋ก | ||
|
||
- DDL์ ํตํด ๋ฐ์ดํฐ๋ฒ ์ด์ค, ํ ์ด๋ธ์ ์์ฑ,๋ณ๊ฒฝ,์ ๊ฑฐ๋ฅผ ํ๊ณ | ||
- DML์ ํตํด ๋ ์ฝ๋๋ฅผ ์์ฑ,๋ณ๊ฒฝ,์กฐํ,์ ๊ฑฐ๋ฅผ ํ๊ณ | ||
- DCL์ ํตํด ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ทผ ๊ถํ์ด๋ ์์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์, ๋ฆฌ์ ์ ์งํํ๋ค. |