02_Database

06_데이터 수정(UPDATE)

chuu_travel 2025. 1. 29. 00:08
728x90
데이터 수정(UPDATE)
01. UPDATE문의 기본 문법

 

update 테이블이름 set 열1 = 값1, 열2 = 값2... where 조건;

 

 

city_popul 테이블의 도시 이름 중에서 'Seoul'을 '서울'로 변경하기

select * from city_popul where city_name = 'Seoul';

update city_popul set city_name = '서울' where city_name = 'Seoul';

 

select * from city_popul where city_name = '서울';

 

02. 한꺼번에 여러 열 변경하기

 

도시이름 New York을 뉴욕으로 바꾸면서 인구는 0으로 수정

update city_popul set city_name = '뉴욕', population = 0 where city_name = 'New York';

 

select * from city_popul where city_name = '뉴욕';

 

 

03. 주의점

 

update문에서 where절은 생략 가능하지만, where절을 생략하면 모든 행의 값이 바뀜

city_popul테이블의 인구를 10000명 단위로 변경하는 등의 특수한 경우가 아니라면 주의해야함

 

update city_popul set population = population / 10000;

select * from city_popul limit 5;

728x90

'02_Database' 카테고리의 다른 글

08_MySQL의 데이터 형식  (0) 2025.01.29
07_데이터 삭제(DELETE)  (3) 2025.01.29
05_데이터 입력(INSERT)  (1) 2025.01.29
04_데이터 조회(SELECT)  (1) 2025.01.21
03_DBeaver 실행 및 사용법  (0) 2025.01.21