Relational Model
용어 정리
relation == table
tuple == row == record
attribute == column
degree: attribute의 수 5
cardinality: 튜플의 수 4
degree는 1이상이어야한다
cardinality는 0 일 수 있다
null value
null은 0이 아니다
null != empty space or blank
characteristic of relatoin
같은 이름을 가진 relaiton은 존재할 수 없다
attribute도 마찬가지
key is an attribute
types of keys
super key
candidate key
primary key
alternate key
foreign key
super key: unique value를 포함한 set
candidate key: super key중에 가장 작은 set
primary key: candidate 중에 하나를 선택한 것
alternate key: candidate key 중 primary key가 아닌 것
이렇게 보면 이해가 안되니까 그림으로 보면
이런 형태이다
Foreign key
데이터베이스 사이의 연관관계 표시한 키
types of foreign key
1. 다른 테이블
2. 자기자신
3. composite(두개이상 열)
Integrity Constraints: 무결성 제약조건
Entity integrity constraint(primary key와 관련)
- 모든 테이블은 primary key가 있다
- primary key로 선택된 attribute는 unique한 값이여야 한다
- primary key는 null값을 가질 수 없다
Domain integrity constraint(attribute랑 관련)
domain==data type
1.attribute를 사용하려면 data type을 선언해야한다
2.각 튜플에는 하나의 attribute에 하나의 값만 가질 수 있다
3.한 attribute의 모든 값은 같은 data type이어야한다
Referential integrity constraint(foreign key와 관련)
- 다른 테이블 참조하는 foreign key는 다른 테이블에 쓸 수 있는 값이어야 한다
- indicate the followings: relaiton name, tuples, attributes, cardinality and degree
- For the same relation, show the followings: super keys, candidate keys, primary key and alternate key
1. ANSWER
relation name : The student
tuples: (1000, Tim, Computer, Male, tim@gmail.com)
(1001, Sonya, Art, Female, sonya@naver.com)
(1002, Brain, Social, Male, brain@yahoo.com)
(1003, Natasha, Math, Female, natsha@outlook.com)
attribute: ID, Name, Major, Grade, Email
cardinality: 4
degree: 5
2.ANSWER
super keys:
{ID},
{ID, Name}, {ID, Major}, {ID, Grade}, {ID, Email},
{ID, Name, Major}, {ID, Name, Grade}, {ID, Name, Email},
{ID, Major, Grade}, {ID, Major, Email}, {ID, Grade, Email},
{ID, Name, Major, Grade}, {ID, Name, Major, Email}, {ID, Major, Grade, Email},
{ID, Name, Major, Grade, Email},
{Email},
{Email, Grade}, {Email, Major}, {Email, Name},
{Email, Grade, Major}, {Email, Grade, Name}, {Email, Major, Name},
{Email, Grade, Major, Name}
candidate keys:
{ID}, {Email}
primary key: ID
alternate key: Email