Relation
- 기본적으로 수학의 개념에서 파생되었다
Relation Data model
- Domain(=Set)
- Atomic한 Value들의 집합
- ex) students_ids, human_names, university_grades 등등
- Attribute
- Domain에서 맡은 역할에 따라 세부화
- ex) 테이블에서 연락처를 phone_num, emr_phone_num로 나눠서 세부화 할 수 있음
- ex) id, name, grade, major 등등
- Tuple
- Attribute들의 집합체(List)
- Relation
- 위의 Tuple(Instance)들의 집합
- 쉽게 말해 Table
[아래 그림 참조]
Relation Schema
- relation의 구조를 나타낸다.
- relation 이름과 attributes 리스트로 표기된다.
- ex)STUDENT(id, name, grade, major, phone_num, emer_phone_num)
- attributes와 관련된 constraints도 포함한다.
Degree of a relation
- relation schema에서 attributes의 수
- ex)STUDENT(id, name, grade, major, phone_num, emer_phone_num) → degree 6
Relation(Or Relation State)
- 위의 그림자체로 Table을 의미할 수도 있지만, 문맥에 따라서는현재 Table이 갖고 있는 Set of Tuples를 의미할 수도 있음.
Relational Database
- relational data model에 기반하여 구조화된 database
- relational database는 여러 개의 relations로 구성된다.
Relation의 특징
- relation은 중복된 tuple을 가질 수 없다.
- relation의 tuple을 식별하기 위해 attribute의 부분 집합을 key로 설정한다.
- relation에서 tuple의 순서는 중요하지 않다.
- 하나의 relation에서 attribute의 이름은 중복되면 안된다.
- 하나의 tuple에서 attribute의 순서는 중요하지 않다.
- attribute는 atomic 해야 한다. ex) 제1 정규화
Super Key
- relation에서 tuples를 unique하게 식별할 수 있는 attributes set
Primary Key
- relation에서 tuples를 unique하게 식별하기 위해 선택된 candidate key
Unique Key
- primary key가 아닌 candidate keys
- alternate key
- ex)PLAYER(id, name, team_id, back_number,birth_date)에서 PK가 Id였다면 unique key는 (team_id, back_number)
Foreign Key
- 다른 relation의 PK를 참조하는 attributes set
- ex) PLAYER(id, name, team_id, back_number,birth_date), TEAM(id, name, manager)가있고 연관관계가 있을 때, PLAYER의 FK는 TEAM의 id가 될 수 있다.
Constraints
- relational database의 relations들이 언제나 항상 지켜줘야 하는 제약 사항
- implicit constraints
- relational data model 자체가 가지는 constraints
- relation은 중복되는 tuple을 가질 수 없다.
- relation 내에서는 같은 이름의 attribute를 가질 수 없다.
- schema-based constraints
- 주로 DDL을 통해 schema에 직접 명시할 수 있는 constraints
- explicit constraints
- domain constraints
- attribute value는 항상 도메인 그 자체에 속해야함
- key constraints
- 서로 다른 Tuples는 같은 value의 Key를 가질 수 없다.
- Null value constraint
- NOT NULL
- Entity integrity constraint
- PK는 Value에 null을 가질 수 없다.
- 즉 PK는 Null을 가지면 안된다.
- Referential integrity constraint
- FK와 PK와 도메인이 같아야 하고 PK에 없는 values를 FK가 값으로 가질 수 없다.
- FK에 있을 수 있는 값은 FK가 참조하는 PK의 존재하는 값을 참조해야한다.
- 즉 없는 값을 참조하면 안된다.
'DB' 카테고리의 다른 글
[DB] 트랜잭션(Transaction)매니저 & 프록시 & 트랜잭션 AOP (0) | 2024.08.11 |
---|---|
[DB] 트랜잭션(Transaction) 개념 및 동작원리 (0) | 2024.08.10 |
[DB] 데이터베이스 기본개념 용어 정리 (0) | 2024.07.29 |
[DB] Connection Pool 과 DataSource (2) | 2024.07.23 |
[DB] JDBC란? (0) | 2024.07.20 |