본문 바로가기

TOOL/MySQL

MySQL - UPDATE

반응형
UPDATE

 

 

 

기존 데이터의 값을 변경하는 SQL

 

 

 

insert into cats
(name,breed,age)
values
('Ringo','Tabby',4),
('Cindy','Maine Coon',10),
('Dumbledore','Maine Coon',11),
('Egg','Persian',4),
('Misty','Tabby',13),
('George Michael','Ragdoll',9),
('Jackson','Sphynx',7);

select * from cats;

 

 

 

 

breed가 Tabby인 고양이의 종을, Shorthair로 변경

( set은 변경될 값을 적어주고, where는 조건문이라고 이해하면 쉽다. )

 

update cats
set breed = 'Shorthair'
where breed = 'Tabby';

 

 

 

 

고양이 이름이 Misty인 고양이의 나이를 14로 변경

 

 

update cats
set age = 14
where name = 'Misty';

 

 

 

 

이름이 'Jackson'인 고양이의 이름을 Jack으로 변경

update cats
set name = 'Jack'
where name = 'Jackson';

 

반응형