데이터 베이스(Database) - Introduction to Relational Model

1. Structure of Relational Database

- The Instructor relation (= The Instructor table)

- 용어 정리

Relation : table

Tuble (= record = row) : table에서 각 row를 가리키는 말.

Attribute (= column) : table에서 각 column을 가리키는 말.

- Attribute Types

attribute가 가질 수 있는 값의 범위domain이라 한다.

attribute값은 atomic해야 한다. (더 이상 쪼갤 수 없어야 한다)

null값은 모든 domain에 속해있다.

null값은 operation의 정의에 있어서 복잡성을 일으킬 수 있다.

 

2. Database Schema

* database는 몇개의 relation(= table)로 구성되어 있다.

- Database schema

Logical design of the database

- Database instance

A snapshot of the data in the database at a given instant in time.

- Relation schema

Logical design of a table

- Relation instance

A snapshot of the data in a table at a given instant in time.

- attribute는 A1,A2,A3,… 로 나타낸다

- relation schema는 R = (A1, A2, …, An)으로 나타낸다.
    ex) instructor = (ID, name, dept_name, salary)

- domain D1, D2, D3, …, Dn이 주어졌을 때 relation r은 D1 x D2 x … x Dn의 subset이다.
   즉, relation은 ai ∈ Di인 n-tuble(a1,a2,…,an)의 집합이다.

 

3. Keys

- Super key : table에서 tuple들을 unique하게 구분해 낼 수 있는 attribute들의 집합.

- Candidate key : 어떠한 subset도 super key가 되지 않는 가장 작은 super key.

- Primary key : candidate key중에서 DB디자이너가 임의로 고른 key.

- Foreign key : 다른 table에 반드시 다시 나타나는 key.
                       (Constaint : 반드시 다른 table에 있어야 한다.)
                       * Referencing relation : foreign key가 있는 table이 다른 table에 다시 나타나는
                                                          key를 참조하는 관계 
                       * Referenced relation : 반대로 참조되는 관계

※ {ID}, {ID,name}, {ID,name,dept_name}, … 모두 super key이지만 {ID}만 candidate key이다.

 

4. Schema Diagram


-> 밑줄 친 것들이 primary key
-> 화살표의 출발점에 있는것이 foreign key

5. Relational operation

- Selection (∂)

ex) ∂A=B and D>5 (r) : select tuples with A=B and D>5

- Project (∏)

ex) ∏A,C (r) : select attributes of A and C, 중복제거

- Union (∪)

ex) r ∪ s : relation r과 relation s를 합집합해라.

- Difference (-)

ex) r - s : relation r에서 relation s와 공통된 부분을 빼라.

- Intersection (∩)

ex) r ∩ s : relation r과 relation s의 공통된 부분

- Cartesian Product (x)

ex) r x s : relation r과 s의 각각의 tuple들을 합친것의 모든 경우를 다 나타내라.

- Natural Join

두 table에서 공통으로 갖고있는 attribute가 같은 값을 갖는 것들로만 table을 만드는 것.

 

Posted by Hello_World_2016
,


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24