💽 DataBase

SQL 데이터 추가 수정 삭제

테이블 생성

notion image

데이터 추가

notion image
  • Table 정의시 사용했던 Attribute의 이름 순서대로
notion image

PK 중복

notion image
notion image

연봉 제약 조건 실패

notion image
notion image

제약 조건 확인(MySQL)

notion image

FK 제약 조건 실패

notion image
notion image

연봉 정보를 넣지 않아도 성공

notion image
notion image

기본 값이 들어감

notion image

정리

notion image
notion image

데이터 수정

notion image

Update Statement

  • Employee ID가 1인 Messi는 개발팀 소속이다.
  • 개발팀 ID는 1003이다.
  • Messi의 소속팀 정보를 업데이트 해주자.
notion image
notion image

확인

notion image
 
notion image

Update Statement

  • 개발팀 연봉을 두배로 인상
  • 개발팀 ID는 1003
notion image

Update Statement

  • 프로젝트 ID 2003에 참여한 임직원의 연봉을 두배로 인상
notion image

더 직관적으로 구분

notion image

Update Statement

  • 모든 구성원의 연봉을 두배로
notion image

정리

notion image

데이터 삭제

Delete Statement

  • John이 퇴사
  • Employee Table에서 John 정보를 삭제해야함
  • John의 Employee ID는 8
  • 현재 John은 Project 2001에 참여하고 있다.

WORKS_ON Table 만들 때, FK로 참조했기 때문에 같이 지워짐

notion image
notion image

Delete Statement

  • Jane이 휴직하면서 현재 진행 중인 프로젝트에서 중도 하차
  • Jane의 ID는 2
notion image
  • empl_id가 2인 것이 전부 삭제됨

Delete Statement

  • 현재 Dingyo가 두 개의 프로젝트에 참여중인데
  • 프로젝트 2001에 선택과 집중을 위해 프로젝트 2002에서 하차
  • Dingyo의 ID는 5
notion image
 
notion image
  • proj_id 2001을 제외한 나머지를 지우라는 뜻

Delete Statement

  • 회사에 큰 문제가 생겨서 진행중인 모든 프로젝트 중단
notion image
  • where 절 없이 사용은 특히 조심

정리

notion image

출처