Skip to content

Latest commit

 

History

History
108 lines (79 loc) · 1.67 KB

MySQL_02.md

File metadata and controls

108 lines (79 loc) · 1.67 KB

MySQL 02 - CRUD

지식 공유자 - Opentutorials의 egoing님

CRUD

  • Create

    • 생성
  • Read

    • 조회
  • Update

    • 수정
  • Delete

    • 삭제
  • Create, Read는 데이터베이스라면 반드시 가지고 있어야 하는 개념이다.(input, output)

  • Update, Delete는 분야에 따라 없을 수도 있다. 예를 들면, 역사의 이야기, 회계에서 거래내역을 다루는 경우

Insert

  • 테이블의 컬럼 확인
DESCRIBE topic;
DESC topic;
  • insert
INSERT INTO topic (title, description, created, author, profile)
VALUES ('MySQL', 'MySQL is ...', NOW(), 'namjune', 'developer');
  • 확인
SELECT * FROM topic;

Select

  • 테이블의 모든 row 조회
SELECT * FROM topic;
  • 일부 column만 조회
SELECT id, title, created, author FROM topic;
  • 작성자가 namjune인 row 조회
SELECT id, title, created, author FROM topic WHERE author = 'namjune';
  • id를 오름차순으로 정렬해서 조회
SELECT
  id,
  title,
  created,
  author
FROM topic
WHERE author = 'namjune'
ORDER BY id DESC;
  • LIMIT 키워드를 사용해서 조회하는 row의 수 제한
SELECT
  id,
  title,
  created,
  author
FROM topic
WHERE author = 'namjune'
ORDER BY id DESC
LIMIT 3;

Update

  • row의 특정 컬럼 값 update
    • WHERE절을 생략하면 엄청난 재앙이 찾아올 수 있다. 유의해야 한다.
UPDATE topic
SET author = 'admin', profile = 'admin'
WHERE title = 'Oracle';

Delete

  • 특정 row delete
    • 마찬가지로 WHERE절을 삭제하면 모든 row가 삭제 된다.
DELETE FROM topic
WHERE title = 'MongoDB';