0% found this document useful (0 votes)
26 views

Lecture - 7

Uploaded by

aryankrsingh7030
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lecture - 7

Uploaded by

aryankrsingh7030
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Mapping Cardinalities

Mapping cardinalities, or cardinality ratios, express the number of entities to which


another entity can be associated via a relationship set. Mapping cardinalities are most
useful in describing binary relationship sets, although they can contribute to the
description of relationship sets that involve more than two entity sets. In this section,
we shall concentrate on only binary relationship sets. For a binary relationship set R
between entity sets A and B, the mapping cardinality must be one of the following:
• One-to-one. An entity in A is associated with at most one entity in B, and an entity
in B is associated with at most one entity in A.

• One-to-many. An entity in A is associated with any number (zero or more) of entities


in B. An entity in B, however, can be associated with at most one entity in A.

• Many-to-one. An entity in A is associated with at most one entity in B. An entity in B,


however, can be associated with any number (zero or more) of entities in A.
• Many-to-many. An entity in A is associated with any number (zero or more) of
entities in B, and an entity in B is associated with any number (zero or more) of entities
in A.

As an illustration, consider the advisor relationship set. If, in a particular university, a


student can be advised by only one instructor, and an instructor can advise several
students, then the relationship set from instructor to student is one-to-many.
Participation Constraints
The participation of an entity set E in a relationship set R is said to be total if every
entity in E participates in at least one relationship in R. If only some entities in E
participate in relationships in R, the participation of entity set E in relationship R is said
to be partial.
For example, we expect every student entity to be related to at least one instructor
through the advisor relationship. Therefore, the participation of student in the
relationship set advisor is total. In contrast, an instructor need not advice any students.
Hence, it is possible that only some of the instructor entities are related to the student
entity set through the advisor relationship, and the participation of instructor in the
advisor relationship set is therefore partial.
Database Keys
We must have a way to specify how tuples within a given relation are distinguished.
This is expressed in terms of their attributes. That is, the values of the attribute values
of a tuple must be such that they can uniquely identify the tuple. In other words, no
two tuples in a relation are allowed to have exactly the same value for all attributes.
Here are some reasons for using key in the DBMS system.

• Keys help you to identify any row of data in a table. In a real-world application,
a table could contain thousands of records. Moreover, the records could be
duplicated. Keys in RDBMS ensure that you can uniquely identify a table
record despite these challenges.
• Allows you to establish a relationship between and identify the relation
between tables
• Help you to enforce identity and integrity in the relationship.
A SUPERKEY is a group of single or multiple keys which identifies rows in a table. A
Super key may have additional attributes that are not needed for unique identification.
There can be multiple super keys.
(EmpSSN), (EmpNum), (EmpSSN, EmpName), (EmpNum, EmpName), (EmpSSN,
EmpNum), (EmpSSN, EmpNum, EmpName) are possible superkeys from (EmpSSN,
EmpNum, EmpName).
CANDIDATE KEY in SQL is a set of attributes that uniquely identify tuples in a table.
Candidate Key is a super key with no repeated attributes. The Primary key should be
selected from the candidate keys. Every table must have at least a single candidate
key. A table can have multiple candidate keys but only a single primary key.

Properties of Candidate key:

• It must contain unique values


• Candidate key in SQL may have multiple attributes
• Must not contain null values
• It should contain minimum fields to ensure uniqueness
• Uniquely identify each record in a table

Candidate key Example: In the given table Stud ID, Roll No, and email are candidate
keys which help us to uniquely identify the student record in the table.

PRIMARY KEY in DBMS is a column or group of columns in a table that uniquely


identify every row in that table. The Primary Key can’t be a duplicate meaning the
same value can’t appear more than once in the table. A table cannot have more than
one primary key.
Rules for defining Primary key:

• Two rows can’t have the same primary key value


• It must for every row to have a primary key value.
• The primary key field cannot be null.
• The value in a primary key column can never be modified or updated if any
foreign key refers to that primary key.

StudID is primary key from (StudID, Roll No, First Name, LastName, Email)

ALTERNATE KEYS or secondary key is a column or group of columns in a table that


uniquely identify every row in that table. A table can have multiple choices for a primary
key but only one can be set as the primary key. All the keys which are not primary key
are called an Alternate Key. The alternate key may or may not exist. If there is only
one candidate key in a relation, it does not have an alternate key.

In this table, StudID, Roll No, Email is qualified to become a primary key. But since
StudID is the primary key, Roll No, Email becomes the alternative key.

FOREIGN KEY is a column that creates a relationship between two tables. The
purpose of foreign keys is to maintain data integrity and allow navigation between two
different instances of an entity. It acts as a cross-reference between two tables as it
references the primary key of another table.
(Deptcode, Deptname) and (Teacher_id, Lname, Fname)

In this key in dbms example, we have two table, teach and department in a school.
However, there is no way to see which teacher work in which department.

In this table, adding the foreign key in Deptcode to the Teacher name, we can create
a relationship between the two tables.

Whenever a primary key consists of more than one attribute, it is known as a


COMPOSITE KEY. This key is also known as Concatenated Key. The combination of
columns guarantees uniqueness, though individually uniqueness is not guaranteed.
Hence, they are combined to uniquely identify records in a table.

COMPOUND KEY is created when two or more primary keys from different tables are
present as foreign keys within an entity. The foreign keys are used together to uniquely
identify each record.

Student: (student_id), Enrolled: (student_id, course_id), course: (course_id).


Compound key: (student_id, course_id) in Enrolled

SURROGATE KEYS is an artificial key which aims to uniquely identify each record is
called a surrogate key. This kind of partial key in dbms is unique because it is created
when you don’t have any natural primary key. They do not lend any meaning to the
data in the table. Surrogate key in DBMS is usually an integer. A surrogate key is a
value generated right before the record is inserted into a table.

Surrogate keys are allowed when

• No property has the parameter of the primary key.


• In the table when the primary key is too big or complicated.

Adding of serial number when the table don’t have a primary key.

You might also like