Under your assumptions, answer the following questions:
(1) Find (all) keys.
(2) Specify primary keys.
(3) Find (all) super keys
Good Primary Keys
Stable : Do not change over the life of the database
Definitive : Values always exist
Numeric : ID ‘12345’ is better than name ‘michael Jordan’
Minimal : Fewest attributes as possible ( 3 or fewer)
Short : Are not too long length (bytes)
Security : No sensitive information hidden
(Relational) Integrity Constraints
Integrity Constraints are conditions that must be satisfied by all relations; There are three main types of constrains;
Key Integrity
Entity Integrity
Referential Integrity
Key Integrity
Given any key K, for any two tuples t1 and t2 in a relation R, t1[K] $neq$ t2[K].
Entity Integrity
Primary key in a relation R must not contain null values in any tuple in R; That means; t[PK] $neq$ null for any tuple t
Key/Entity Integrity
다음 각 연산에서 key integrity, entity integrity의 위반 유무를 판단하라. (단, Primary Key = {SSN})
Insert a student with <papa jones, 489-22-1100, 290-7118, . . >
Insert a student with <papa jones, null, 29-0-7118, null, . . . >
Insert a student with <mama jones, 123-45-678, null, null, null, . . >
Update Charles Cooper’s SSN by 533-69-1238.
Delete students with GPA = 3.25.
Referential Integrity
This is used to specify a relationship among tuples in relations.
When referencing relation R1 wants to relate the referenced relation R2, you must include a common attribute(s).
The common attribute in referenced relation R2 is Primary Key (PK).
The common attribute in referencing relation R1 is called Foreign Key (FK).
Tuples in referencing relation R1 have FK that reference the PK of referenced relation R2.
다음 ER Diagram을 relation 구조로 표현하라.
The value in FK of referencing relation R1 must be either:
(1) an existing value of the corresponding primary key PK in the referenced relation R2, (In case (1), every FK values in referencing relation R1 must exist in PK in the referenced relation R2)
(2) a null value (In case (2), the FK in R1 should not be a part of its own primary key.)
Referencing and referenced relation is the same.
한 relation의 FK가 자기 자신의 relation의 PK를 참조함.
What is PK?
What is FK?
Violating Referential Integrity
Referential integrity could be violated by following cases;
Case 1 : DELETE or UPDATE tuples from referenced relation
Case 2 : INSERT tuple into referencing relation
If integrity violated, several optional actions can be taken:
(1) Reject the operation, and explain user why;
(2) Perform the operation, but ask user to correct it;
(3) Trigger additional actions, and ask system to correct it;
댓글남기기