티스토리 뷰

그외

[DB] Relational Database 개념

체봄 2021. 11. 7. 23:40

 

용어

Relation: table을 의미

Tuple: row를 의미

Attribute: column을 의미

Schema: Relation명(Attribute명1, Attribute명2, ...) 으로 나타내는데, 보통은 Schema diagram을 일컫는 듯하다

Key: Tuple에 유니크한 정체성을 부여하는 Attribute

      (말이 좀 어려운데 예를 들어 STUDENT Relation에서 SSN(학번) Attribute가 Key이다)

Domain: Attribute가 가질 수 있는 값들(을 의미하는 듯)

 

특징

- Relational Database는 table 형태로 데이터를 저장한다.

- Relation은 Tuple들의 집합이므로 중복된 행(Tuple)이 없어야 한다.

 

 

 

Relational Constraints

 

1. Key constraints

Superkey: Tuple에 정체성을 부여할 수 있는 Attribute의 집합

             Attribute는 하나일수도 있고 여러개일수도 있음, ex: {이름, 학번}

Key: minimal한 Superkey

       ex: {학번}

- Key는 Superkey에 속하지만, Superkey는 Key에 속하지 않는다

- candidate key가 여러 개 있으면 그 중 임의로 primary key를 선택한다

- schema diagram을 그릴 때 primary key에 밑줄을 긋는다

 

2. Entity Integrity constraints

: PK는 null일 수 없다.

  ex: STUDENT Relation에서 SSN이 없는 학생이 있으면 안된다

 

3. Referential Integrity constraints

: FK가 갖는 값은 Referenced Relation의 PK 값 or null 이어야 한다.

- FK는 null 값을 가질 수 있으므로 NOT NULL constraint를 가질 수 없다

 

 

 

Relational Update Operations

: INSERT, DELETE, UPDATE

 

- Referenced Relation을 DELETE하면 Referential Integrity constraints가 위반된다.

  그래서 option을 줄 수 있다. (option: RESTRICT / CASCADE / SET NULL)

      RESTRICT: 지우려는 Relation을 참조하는 Relation이 있으므로 못 지우게 함

      CASCADE: Referenced Relation과 Referencing Relation을 모두 지워버림

      SET NULL: Referenced Relation을 지웠으므로 FK값을 NULL로 설정

- Referenced Relation의 PK를 UPDATE하면 Referential Integrity constraints가 위반된다.

  Referenced Relation의 PK값과 FK값이 달라지기 때문

  그래서 option을 줄 수 있다.

      CASCADE: 변경된 PK값을 FK에도 업데이트함

반응형

'그외' 카테고리의 다른 글

PostgreSQL 사용법에 관한 기록  (0) 2021.12.06
[Git] PR시 발생한 Conflict 해결하기  (0) 2021.11.15
AWS(Amazon Web Service) 사용하기  (0) 2021.09.14
AWS S3 버킷 사용하기  (0) 2021.09.14
AWS에서 GitHub SSH key 등록하기  (0) 2021.09.14

댓글