๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ”ฌweb application/- Database

[SQL๋ฌธ ๊ธฐ์ดˆ] DML ๋ฐ์ดํ„ฐ ์กฐ์ž‘์–ด :: INSERT, UPDATE, DELETE

by Wonit 2020. 7. 7.

DML

Data Management Language ์˜ ์•ฝ์ž์ธ DML์€ ์•ž์„œ ๋ฐฐ์šด DDL์œผ๋กœ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค๊ณ  ๋‚˜์„œ ๊ธฐ์กด์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฝ์ž…, ํ˜น์€ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋ช…๋ น์–ด์˜ ์ง‘ํ•ฉ๋‹ˆ๋‹ค.

๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ :: INSERT

INSERT๋ฌธ์€ ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์˜ ๋กœ์šฐ๋งŒ INTO ๋‹ค์Œ์— ๋ช…์‹œํ•˜๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ํ…Œ์ด๋ธ”์— ์‚ฝ์ž…ํ•œ๋‹ค.

INSERT INTO table_name
(column_name, ..)
VALUES(column_vale, ...);

VALUES์— ๋“ค์–ด๊ฐ€๋Š” ๋ฐ์ดํ„ฐ ๊ฐ’๋“ค์€, CREATEํ•  ๋•Œ ์ง€์ •๋œ ์นผ๋Ÿผ๊ณผ ์ผ์น˜ํ•˜๋„๋ก ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ๋กœ ์ธ์‚ฌ๋ถ€์˜ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด๋ณด์ž

INSERT INTO dept
(deptno, loc, dname)
VALUES(20, '์ธ์ฒœ', '์ธ์‚ฌ๋ถ€')

๋ฐ์ดํ„ฐ ์ˆ˜์ • :: UPDATE

UPDATE๋ฌธ์€ ์นผ๋Ÿผ์˜ ๊ฐ’์„ ์ˆ˜์ •ํ•  ๋•Œ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด๋‹ค. WHERE์ ˆ๋กœ ํŠน์ • ์นผ๋Ÿผ์„ ํฌ์ธํŒ… ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๋งŒ์•ฝ ์ด๋ฅผ ์ƒ๋žตํ•˜๋ฉด ๋ชจ๋“  ์นผ๋Ÿผ์ด ์ˆ˜์ •๋œ๋‹ค.

UPDATE table_name
SET column_name1=value1, ...
[WHERE conditions];

๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ๋กœ ์‚ฌ์›๋ฒˆํ˜ธ 10๋ฒˆ์ธ ์‚ฌ์›์˜ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ด๋ณด์ž

UPDATE dept
SET dname='์˜์—…๋ถ€'
WHERE deptno=10;

๋ฐ์ดํ„ฐ ์‚ญ์ œ :: DELETE

DELETE๋ฌธ์€ ์นผ๋Ÿผ์„ ์‚ญ์ œํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. UPDATE์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ WHERE์ ˆ์„ ์ƒ๋žตํ•˜๋ฉด ๋ชจ๋“  ๋กœ์šฐ๊ฐ€ ์‚ญ์ œ๋œ๋‹ค.

DELETE table_name
WHERE conditions'

๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ๋กœ ํ…Œ์ด๋ธ” ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•ด๋ณด์ž

DELETE dept;

๋Œ“๊ธ€