Chapter 2 – Entity, Type and Key

1.Entity
-By convert the relation, we have entities with attributes in each of entities
-In each entities, we can define a Primary Key (PK) for an entity
-A weak entity is an entity with a composite key. A weak entity is denoted by double rectangle box compare to single rectangle box of normal entity.

2. Type
-If an entity has many types, we can use the Generalization to denote the relation
Ex: Entity Equipment has type Laptop, Mobile.

3.Key
In database analysis and design, we have such of keys as:
3.1 Prinary Key (PK)
-A single column in a table is nominated as PK for the table. By nominated as PK, the value of this column is unique
Ex:
Student(id, name) with id is PK
We have a row as {1, Peter}. So, there is no more rows with id = ‘1’ is accepted

3.2 Foreign Key
-A Primary Key of a table, is put in another table to form a relationship
Ex:
Student (sid, name)
Enrollment (eid, sid, name) –> sid is PK in Student table, but in Enrollment table, sid is FK

3.3 Composite Key
-When PK of a table is not a single column, but in multiple of columns. It is called Composite Key or Composite Primary Key
Ex:
Shipment (date, vid, quantity) –> In this case, we have {date, vid} as composite key for table Shipment

3.4 Surrogate Key
-The composite key for a table will make the table slow in query, searching. Thus, we should nominate a new single column as a PK key for table, this column will be called as Surrogate Key
Ex:
Shipment (date, vid, quantity) –> In this case, we have {date, vid} as composite key for table Shipment
Shipment (shipid, date, vid, quantity) –> shipid will be unique for each of (date, vid)

Add Comment