Skip to main content

Concept of Keys

We can represent casee scenarios for our databases using models.

Candidate Key

An attribute or attributes that uniquely identifies each tuple in a relation

note

This means that a candidate key cannot be the same, and all of them can theoretically be used as primary keys.

Branch Relation: BranchNo, Address, TelNo

Primary Key

The Candidate Key chosen to uniquely identify each tuple.

  • Each relation has only ONE primary key

Branch Relation: BranchNo

Alternate Keys

Candidate keys that are not chosen as the Primary Key

Branch Relation: Address, TelNo

Foreign Key

Used in a relation to create relationship with another relation (or itself) in a database.

Publisher Relation: PublisherID (Primary Key), Name
Book Relation: ISBN (Primary Key), PublisherID (Foreign Key)

Composite Key

A key that consists of more than 1 attribute

RelationPrimary Key
StaffStaffID
BookCopyISBN & CopyNo
note

This means that every tuple in the BookCopy relation can only be identifed by its ISBN and CopyNo together. Neither ISBN nor CopyNo can uniquely identify each BookCopy tuple.

Concept of NULL

A NULL means that the value of attribute is unknown, not available, or not applicable.

Important

NULL is NOT equivalent to zero, empty string or spaces.