진박사의 일상

[데베시] 5강 - Relational Data Model 본문

프로그래밍/공부

[데베시] 5강 - Relational Data Model

진박사. 2021. 10. 14. 20:32

Relational model concepts

Characteristics of Relations

Relational Model Constraints : key, relational DB schema, Integrity Constraints

 

Relational Model Concepts

- DB = relations(=tables) 의 집합

- Relation = tuples(=rows)의 집합

- Tuple = attributes의 집합 : real-world에서 Entity나 Relationship에 대응하는 Fact,

- Attribute : 특정 한 Tuple에 대응하는 object에 대한 특성을 정의

Example

table의 attribute들로 구성된 골격을 table schema라고 함

attribute value로 이루어진 row를 tuple이라고 함

 

Domain D

- atomic한 value의 집합 (특정 attribute의 domain은 해당 attribute가 가질 수 있는 attribute value의 집합)

 

Attribute Ai

- 특정 relation schema R에서 어떠한 domain D가 어떤 역할을 하는지에 대한 이름

- dom(Ai) =relation schema R에서 Ai의 도메인 ex) dom(Age) : 16~8, Age는 Attribute name

 

Relation schema R

- schema = 구조 <-> instance = 하나의 개체

- relation name R과 A1, A2, ... An 개의 Attribute 리스트로 구성

- R(A1, A2, ... An) 로 표기. ex) STUDENT(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA)

- Degree(= arity) of a relation = relation schema에 포함된 Attribute의 수 n ex) degree of Student = 7

 

Tuple t of raltion R

- n개의 attribute value로 구성된 리스트로 n-tuple이라고도 불림.

- t = <v1, v2, ... vn>으로 표기

- vi = dom(Ai)에 포함된 value 중 하나의 값. 특수 값으로 NULL이 있음.

 

Relation Instance r(R)

- tuples의 집합 : r(R) = {t1, t2, ..., tm}

- R을 정의하는 domain들의 Cartesian product의 Subset : r(R) ⊆ (dom(A1) X dom(A2) X ... X dom(An))

- 즉 모든 가능한 tuple의 집합의 부분 집합 (cartesian product : 가능한 모든 조합의 집합)

 

 

Relations의 Characteristics(특징)

- relation의 tuples의 순서(ordering) : 순서 의미 없다. 정의부터 set이므로 순서가 없고 중복이 없음.

- tuple의 attributes의 순서 : 순서 의미 있다. n-tuple은 ordered list of n values이므로. 그러나 실제로 그다지 중요하지는 않음

- values in tuples : 각각의 value는 atomic(쪼갤수x) -> (*중요) 그래서 ER 모델과는 다르게 Relation model에서는 Composite & multivalued attribute를 허용하지 않음. - First normal form

- Null : unknown or not applicable to a tuple value. (unkown : 입력 안해도 문제x, not applicable : 입력 안한 것이 의미 o)

 

Relational Model Notation(표기법)

t[Ai] : 특정 튜플에 포함된 Attribute Ai의 value vi

t[Au, Aw, ..., Az] : sub-tuple of values <vu, vw, ...., vz> 전체 tuple 중 일부 attribute의 리스트

 

Relational Model Constraints

- Contraints : relation schema의 실제 value에 가해지는 Restriction(제약조건)

- 모든 instance가 constraints에 따라야 함(DBMS에서 정할 수 있어야 함. DBMS는 이 제약을 따를 수 있도록 체크해야 함)

- DB가 실제로 나타내려는 mini-world의 rule에서 유추됨

중요한 constraints들 : Key Constarint, Entity Integrity Constraint, Referential Integrity Constraint

 

Key Constraint(키 제약조건)

 

R의 Superkey : R의 attributes의 집합인데 R의 relation instance인 r(R) 간에 같은 attribute values를  가지지 않는 attribute의 집합

 - for t1 & t2 in r(R) and t1 != t2 -> t1[SK] != t2[SK]

 - 다른 말로 Uniqueness Constraint

Cantidate key K(후보키) : R의 슈퍼키 중에서 최소한의 크기가 되는 키(해당 key에서 하나의 attribute만 제거해도 더이상 superkey 조건이 성립하지 않는 상태의 superkey)

- 하나의 relation schema에는 1개 이상의 Candidate key를 가질 수 있음.(최소 1개 이상)

ex)

Super key가 될 수 있는 경우 : 모든 속성의 set, {Engin_serial_number, Make} ...

Candidate key가 될 수 있는 경우 : License_number, Engine_serial_number

 

Primary Key(PK) : Candidate keys 중에 정해준 하나, underlined attribute, 가능하면 숫자 그리고 고정길이의 속성이 key가 되는 게 좋음.

 

Key Constraint : 하나의 relation은 반드시 후보키가 존재해야 한다.

 

Relational Database Schema

 - 같은 DB에 포함된 Relation Schemas의 집합으로 이루어짐. S = {R1, R2, ..., Rm}

 - Integrity Constriant IC의 set도 포함

 

Relational Database Schema 예시

 

Relational database instance

- 같은 DB 내의 relation instance의 set - {r1, r2, ..., rm}

- Ri의 인스턴스로 Integrity Constraint IC를 만족하는 인스턴스 = ri

 

Entity Integrity Constraints(개체 무결성 제약조건)

- 각 relation schema R의 Primary Key에 관한 Constraint

- primary key의 value는 NULL이 될 수 없다.(t[PK] != NULL) 해당 primary key로 각 tuple을 식별해야 하므로

 

Referential Integrity Constraints(참조 무결성 제약조건)

- Key constraints나 Entity integrity constraints와 달리 2개의 relations 사이에 정의된 제약조건

- 두개의 relation의 tuple간의 일관성을 유지하기 위해

- 하나의 relation에 속하는 tuple이 다른 relation에 속하는 존재하는 tuple을 참조해야 한다.

- ex) EMPLOYEE의 Dno(FK) 속성은 반드시 DEPARTMENT의 DNumber 속성의 존재하는 값을 참조해야 한다.

 

 Foreign Key (FK)

- FK attribute의 집합은 R1과 R2에 대해 다음의 룰을 만족.

  - R1의 FK 속성은 R2의 PK와 같은 도메인을 가진다.

  - r1(R1)의 인스턴스 중 t1이라는 튜플의 FK는 r2(R2)의 하나의 튜플의 PK의 값을 가지거나 NULL이어야 함.

- t1[FK] = t2[PK] (or NULL) ==> 't1 refers to t2'

- Referential Integrity Constraints는 Foreign key를 만족시키는 제약조건.

- R1의 FK가 R2의 PK로 화살표를 가리키는 형태로 표현

 

'프로그래밍 > 공부' 카테고리의 다른 글

[데베시] 6강  (0) 2021.10.18
[컴보] 6강 악성 소프트웨어  (0) 2021.10.17
[컴보] 5강 DB Security  (0) 2021.10.05
[데베시] 4강  (0) 2021.10.04
[컴보] 4강 - Access Control  (0) 2021.09.29