Relational Model이란?
Relational Model은 1970년 IBM 엔지니어였던 E.F.Codd의 논문에서 처음 소개되었고, Relational Algebra를 근간으로 하는 모델이다.
Entity and Relation
Entity (Set)
Relation
Functional Dependency
하나의 observation(row)에서 특정 attribute(s)가 다른 attribute(s)를 결정하는(specify) 관계인 경우에 함수적 종속이 있다고 함
Determinant
Keys
- A combination of one or more columns that is used to identify rows in a relation
Composite Key
Candidate Key
Primary Key
Surrogate Key
Foriegn Key
Database Integrity
Domain integrity constraint : 속성값의 종류는 동일
Entity integrity constraint : primary key : non-Null and unique value
Refential integrity constraint : about value limits of foreign keys
foreign key로 있는 테이블의 속성값 집합이 primary key로 있는 속성값 집합의 부분집합이어야 하는 개념
- A statement that limits the values of the foreign key to those already existing as primary key values in the corresponding relation
(Example) :
SKUDATA (SKU, SKUDescription, Department, Buyer)
ORDERITEM (OrderNumber, SKU, Quantity, Price)
Where ORDERITEM.SKU must exist in SKUDATA.SKU
Modfication Anomalies
Item Number | Equipment Type | Acquisition Cost | Repair Number | Repair Date | Repair Cost |
---|---|---|---|---|---|
100 | Drill Press | 3500 | 2000 | 05-05 | 375 |
200 | Lathe | 4750 | 2100 (deletion anomally) | 05-07 | 255 |
100 | Drill Press | 3500 | 2200 | 06-19 | 178 |
300 | Mill | 27300 | 2300 | 06-19 | 1975 |
100 | Drill Press | 3500 | 2400 | 07-05 | 0 |
100 | Drill Press | 3500 (update anomally) | 2500 | 08-17 | 275 |
Normal Form
어떤 modification anomalies 혹은 문제에 관련된 것인지를 기준으로 분류됨
Source of Anomally Normal Forms Design Principles Functional Dependencies 1NF, 2NF, 3NF, BCNF BCNF : every determinant is a candidate key Multivalued Dependencies 4NF Move each multivalued dependency to a table of its own Data constraints and oddities 5NF, DK/NF Make every constraint a logical consequence of candidate keys and domains
1NF : primary key의 존재 여부에 대해서는 다양한 의견이 존재하는 상황
2NF : 모든 nonkey 속성들이 모든 primary keys에 대해 dependent할 때
3NF : 2NF이고, non-key attributes가 another non-key attribues에 영향받지 않음
Boyce-Codd Normal Form
Multivalued Dependency
Occurs when a determinant is matched with a particular set of values:
Employee ->-> Degree
Employee ->-> Sibling
PartKit ->-> Part
Multivalued Dependencies Examples
언제 이러한 문제가 발생할 지 고민해보자.
지금 다루는 예제에서는 한 명의 관리자가 특정 속성의 여러 값들을 동시에 관리하는 등의 경우에 동일한 BuyerName에 대해 SKUmanaged와 CollegeMajor에 등장하는 값이 여러 개가 될 수 있는 점에서 출발한다.
BuyerName | SKUmanaged | CollegeMajor |
---|---|---|
Pete Hansen | 100100 | Buisiness Administration |
Pete Hansen | 100200 | Buisiness Administration |
Nancy Meyers | 101100 | Art |
Nancy Meyers | 101100 | Info Systems |
Nancy Meyers | 101200 | Art |
Nancy Meyers | 101200 | Info Systems |
Cindy Lo | 201000 | History |
Cindy Lo | 202000 | History |
Jenny Martin | 301000 | Buisiness Administration |
Jenny Martin | 301000 | English Literature |
Jenny Martin | 302000 | Buisiness Administration |
Jenny Martin | 302000 | English Literature |
위 테이블에서 Multivalued Dependencies를 없애보자.
그러기 위해서는 Multivalued Dependency로 나타난 변수끼리 테이블을 분리해주어야 한다.
Database Design Using Normalization
하나 혹은 이상의 데이터 테이블이 있을 때, 데이터를 받은 그대로 저장해야 할지 혹은 저장을 위해 형태를 변형해야 할지 판단해보자.
Table Structure를 평가하는 가이드라인
1) Count rows and examine columns
2) Examine data values and interview users to determine:
- Multivalued Dependencies
- Functional Dependencies
- Candidate Keys
- Primary Keys
- Foreign Keys
3) Assess validity of assumed referential integrity constraints
Counting Rows in a Table : 총 몇개의 행으로 되어 있는지 확인하기
SELECT COUNT(*) AS SKU_DATA_NumRows FROM SKU_DATA;
Examining the Columns : 상위 5개만 불러오기
SELECT * FROM SKU_DATA LIMIT 5;
Checking Validity of Assumed Referential Integrity Constraints
Given two tables with an assumed foreign key constraint:
SKU_DATA
(SKU,SKU_Description
, Buyer)
BUYER
(Buyer, Department)
Where SKU_DATA.Buyer must exist in BUYER.Buyer
"An empty set for the query result below indicates that no foreign key values violate the foreign key constraint"
SQL Query
SELECT Buyer FROM SKU_DATA WHERE Buyer NOT IN (SELECT SKU_DATA.Buyer FROM SKU_DATA, BUYER WHERE SKU_DATA.BUYER = BUYER.Buyer);
Type of Database
Updatable or Read-only? is updatable?
Updatable Database의 경우 Real-time database를 의미한다.
이 경우에 Boyce-Codd Normal Form의 Table로 바꾸어주어야 한다.
주로 기업의 Operational Databases에 해당하고, 예시로 Online Transaction Processing (OLTP) system이 있다.
이러한 유형의 DB를 구축하려면 modification anomalies와 inconsistent data를 고려해야 한다. 정규화 원칙 또한 고려해야 한다.
Read-only Database의 경우 BCNF table이 필요하지 않을 수 있다.
이 형태는 분석을 위해 정지시킨 DB로 바뀌지 않는 table이다. 또한 분석을 위해서는 여러 Table을 JOIN해야 하는데, BCNF를 만족시키기 위해 더 많은 Table을 만들 수록 JOIN이 복잡해져 쿼리 시간이 증가하는 테이블 수와 쿼리 시간 사이의 trade-off 관계도 고려가 필요하다. 이로 인해 애플리케이션의 속도가 느려질 수도 있다.