incastle의 콩나물

Database Concepts Chapter 2. The Relational Model 본문

19-1 대학 수업/데이터베이스 이론 및 실습

Database Concepts Chapter 2. The Relational Model

incastle 2019. 4. 21. 14:07

데이터베이스 이론 및 실습 정재윤 교수님 수업 (19-1)

 

Entity(독립체)

-database에 나타나는 어떠한 유저에게 중요한 정보

 

Relation

- 특정한 성질을 띄고 있는 2차원 table

- 하나의 table에 하나의 topic을 갖고 있다. 각 table은 key를 갖고 있어 must be joined back 할 수 있다.

- normalization을 통해 table 분리

 

Relation의 성질

- row는 entity에 대한 정보를 포함한다.(?)

- Columns은 entity의 attribute에 대한 정보를 포함한다. 

- table의 cell은 single value이다.  (표 한 칸에 두 개의 정보를 넣을 수 없다)

- 하나의 Column안에 있는 정보는 같은 종류이며, 각 칼럼은 unique 한 이름을 갖는다. 

- Column의 순서는 중요하지 않다. 

- Row의 순서는 중요하지 않다. 

- The set of data values in each row must be unique

 

Unique Key & Nonunique Key

- nonunique key가 unique key가 되기 위해서는 2~3개의 attribute를 같이 사용할 때가 있다. 

- 이를 composite primary key라고 한다. 

 

Composite key

- 예시 : Family member을 identify 한다.

>> FamilyID, FirstName, Sufiix가 composite key

- 세 가지를 모두 가져야 composite key를 완성!

- composite key가 항상 unique는 아니다.

 

Candidate key & Primary key

-  primary key을 알면 해당 table의 row를 unique 하게 뽑을 수 있다. 

- Candidate key 중에서 하나를 뽑아서 primary key(candidate key도 unique key라는 것)로 사용

- table 하나에서 identify를 하기 위함 뿐만 아니라, relationship을 나타내기 위해서도 사용된다.

- DMBS product는 primary key를 사용하여 Relation을 위한 storage를 구성한다.

 

Surrogate keys

- Primary key로 사용하려고 만든 일렬 번호

- 이상적인 primary key는 짧고, 숫자고 변하지 않는다.

- 따라서 composite primary key가 귀찮아서 사용되기도 함

- never change

 

Foreign key

- table의 관계를 형성하고 관계를 기준으로 table을 찢을 때 연결 다리를 해주는 key

- 이를 Foreign key라고 함

- 한 table에서 foregin key면 다른 테이블에서 그 값은 primary key이다. 

 

Referential Integrity(참조 무결성)

- The primary key value MUST EXIST before the foreign key value is entered

- A 테이블에 foreign key로 존재하는 값 => 다른 테이블에서 Primary key

- foreign key로는 데이터가 있는데 Primary key로 존재하지 않으면 절대 안 됨! 

- 반대로 primary key로는 존재하지만, foreign key로는 그 value가 없을 수 있음

 

The Null Value

- Null Value는 데이터가 안 들어갔다는 것이다.

- 0과 공백 하고는 다른 의미

       1) 아직 결정 x

       2) 적절하지 않다.

       3) unknown

 

Functional Dependency

- 특정 attribute의 조합을 알면 다른 어떤 값이 자동으로 결정되는 관계

- 따라서 candidate key와 primary key는 determinant가 되겠지.

- starting point로 사용되는 것을 determinant라 부름

- BoxPrice is functionally dependent on CookiePrice, Qty

- determinant가 composite key이면 이를 surrogate key로 바꿔서 사용하기도 함

 

Normalization

- relaiton 단위로 table을 쪼개는 과정

- Normalization는 relation이 잘 형성되었는지 확인하기 위해 분석하는 프로세스

- 하나의 table에 하나의 topic이 담기도록!

- well-formed relation을 만드는 것

  1 ) 모든 determinant는 candidate key이다.

  2 ) not well formed는 well-formed relation으로 쪼갠다. 

 

Normalization Process

1) 모든 candidate key를 찾는다.

2) 모든 functional dependencies relation을 찾는다.

3) determinant 중에 candidate key가 아닌 것이 있냐? 없으면 well-formed! 있으면 작업 시작!

 >> 기존  table에서 funtional dependency를 찢어서 새로운 table 만든다.

 >> determinant를 새로운 table의 primary key로 설정

 >> determinant를 기존 table의 foreign key로 설정

 >> 두 table 사이에 참조 무결성(referential integrity)을 유지하는지 확인

4) 모든 determinant가 candidate key가 되도록 이 과정을 반복한다. 

 

 

Comments