목차
MySQL의 CRUD
C : Create // 생성
R : Read // 읽기
U : Update // 수정
D : Delete // 삭제
SQL의 INSERT 구문
cmd 실행후 mysql 접속
use opentutorials;
show datatables;
show tables;
DESC topic; // table에 대한 속성 정보
생성
INSERT INTO topic (title, description, created, author, profile) VALUES('MySQL', 'MySQL is...', NOW(), 'egoing', 'developer');
입력 후 불러오기
SELECT * FROM topic;
출력화면
읽기
SELECT id, title, created, author FROM topic;
출력화면
topic의 id, title, created, author 값만 가져옴
SELECT id, title, created, author FROM topic WHERE author='egoing';
topic의 id, title, created, author 값중 author가 'egoing'인 값만 가져옴
SELECT id, title, created, author FROM topic WHERE author='egoing' ORDER BY id DESC;
topic의 id, title, created, author 값중 author가 'egoing'인 값을 큰 숫자부터 내림차순으로 가져옴
SELECT id, title, created, author FROM topic WHERE author='egoing' LIMIT 2;
topic의 id, title, created, author 값중 author가 'egoing'인 값 2개만 가져옴
수정
UPDATE topic SET description='Oracle is...', title='Oracle' WHERE id=1;
topic테이블에 id값이 1인 description을 'Oracle is...'으로 수정하고 title을 'Oracle'로 수정함
RENAME table topic TO topic-backup;
topic 테이블 명을 topic-backup 으로 이름을 변경
삭제
delete FROM topic WHERE id=1;
topic테이블중 id값이 1인 행을 삭제함
※ 여기서 WHERE를 빠져먹으면 인생이 바뀔수가 있음 (매우 중요함)
반응형
'database > Mysql' 카테고리의 다른 글
hombrew를 이용한 mysql 설치 (0) | 2023.10.08 |
---|---|
[mysql] 'Your password does not satisfy the current policy requirements' 오류 해결 방법 (0) | 2023.08.29 |
[mysql] 계정 생성, 비밀번호 변경, 권한 부여 (0) | 2023.08.29 |
MySQL 사용법1 (0) | 2020.05.30 |