The Relational Data Model and Relational Database constraints
Superkey, key, candidate key, primary key
foreign key
relational model 정의 방법
tuple
degree: tuple의 attributes
schema(스키마): 각 스키마에는 primary key가 존재해야함.
ER에서 relational model로 바꾸는 과정에서 entity가 두개에서 떼오는 거라 key가 2개가 될수도 있음.→ 복수개의 primary key가 됨.
- surogate key: artificial key(앞에 번호같은거)
- super key : combination of subset of values , attributes의 조합(한개 이상)으로 unique가 보장된다. ER모델에서는 weak entitiy가 있었지만 relation 모델에서는 없다. (모두 슈퍼키 가지고 있다.) =composite key
key is superkey: True
superkey is a key: Not always True
- redundancy가 없고 겹치는게 없으면 atomic key, minimal super key
- key 역시 여러개의 attributes를 가질 수 있다. ;; composite key(중복)
- 더 자주 사용하는 key를 primary key로 지정
- state: 데이터베이스의 현재 상태를 나타내는 단어
- valid state: 값이 올바르게 ↔ invalid state
Relational integrity Constraints
- key constraints :유니크한지
- redundancy가 없고 겹치는게 없으면 atomic key, minimal super key
- super key : combination of subset of values , attributes의 조합(한개 이상)으로 unique가 보장된다. ER모델에서는 weak entitiy가 있었지만 relation 모델에서는 없다. (모두 슈퍼키 가지고 있다.)
- key is superkey: True
- superkey is a key: Not always True
- surogate key: artificial key(앞에 번호같은거)
- 더 자주 사용하는 key를 primary key로 지정
- Entity integrity constraints: 지켜야할것들이 잘 지켜지고 있는지
Referential integrity constraints
foreign key: 다른 테이블과 연결되는 key
함부로 지우려할 때 처음에 reject됨, 하지만 cascade써서 강제할 수 있음.
update 할 때 업데이트 될 primary key가 유니크한지 체크
**Transaction**: database state를 change 가능한 명령어들( select, insert, delete, update)
domain constraints
attribute의 형식이 맞는지(String, digit integer 등을 나타냄.)
other types of constraints
- semantic integrity constraints
- transition constraints
ER to Relational Mapping
- preserve all information
- Maintain the constraints 1:N , N:M
- Minimize null values
- Foreign key(2 relations) approach: foreign key로 다른 테이블에 하나 이어주고 composite key를 만듬 (1:1, N:1 일 때)
- M:N의 경우에는 관계 마름모(마름모가 하나의 relation이 된다.)를 schema 형태로 새로 만들어준 이후 두개의 entitiy를 바탕으로 만든 schema에 각각 이어준다.
- ER에서의 Multivalue attribute 는 새로운 relation을 만들어줘야함
'Computer > Database' 카테고리의 다른 글
SQL injection protection in python (0) | 2021.06.06 |
---|---|
[MySQL] 하루, 일주일, 한달 기간 정하고 데이터 가져오는 query (0) | 2021.04.15 |