Keys in DBMS

Individual entities are distinct and the difference among them is expressed through attributes. The values of the attributes should be such that it uniquely identifies the values of the entities. In other words, no two entities are allowed to have same value for all the attributes. Hence a Key is used to identify a set of attributes, relationships, and thus distinguish entities and relationships from each other.

1. Entity Set

A superkey is a set of one or more attributes that allows us to uniquely identify an entity in entity set. For example, the customer_id attribute of entity set customer distinguishes one customer from another. Hence, customer_id is a superkey. The customer_name attribute of entity customer cannot be superkey because, two customers can have same name. Another example, the combination of customer_id and customer_name is also a superkey for entity customer.

The superkey which does not have any subset is known as candidate key (or primary key). For example, the combination of customer_name and customer_address is used to distinguish the members of the entity set customer. Then, both {customer_id} and {customer_name, customer_address} are candidate keys.

2. Relationship Set

Let R be a relationship having entity sets E1, E2, …, En. Let Ei be the primary-key to denote the set of attributes for entity set Ei. The composition of primary key depends on the set of attributes associated with relationship set R.

If the relationship set R has no attributes associated with it, then the set of attributes describes an individual relationship in set R.

primary-key(E1) primary-key(E2) · · · primary-key(En)

If the relationship set R has the attributes a1, a2, …, am associated with it, then the set of attributes describes an individual relationship in set R.

primary-key(E1) primary-key(E2) · · · primary-key(En) ∪ {a1, a2, …, am}

In both the above examples, the set of attributes forms a superkey for the relationship set.

primary-key(E1) primary-key(E2) · · · primary-key(En)

Comments

Popular posts from this blog

A university registrar’s office maintains data about the following entities: (a) courses, including number, title, credits, syllabus, and prerequisites; (b) course offerings, including course number, year, semester, section number, instructor(s), timings, and classroom; (c) students, including student-id, name, and program; and (d) instructors, including identification number, name, department, and title. Further, the enrolment of students in courses and grades awarded to students in each course they are enrolled for must be appropriately modelled. Construct an E-R diagram for the registrar’s office. Document all assumptions that you make about the mapping constraints.

Consider a database used to record the marks that students get in different exams of different course offerings.