DBMS

Created by
BBorhan
Last edited time
Tag

Resources:

ER Diagram : Entity Relationship Diagram

Entity

Example:

Discriminator/Partial Key: The discriminator of a weak entity set is a set of attributes that allows the distinguish to be made. For an example, we may have same course_id multiple times in “section” table, but how could we uniquely identify each of them ? We can find them out by sec_id, semester, year, so they are discriminator for this weak entity. sec_id, semester, year can be same for each of “course_id”, but a “course_id” must not have same sec_id, semester, year for multiple times.

Strong Entity Set Weak Entity Set
Strong entity set always has a primary key.It does not have enough attributes to build a primary key.
It is represented by a rectangle symbol. It is represented by a double rectangle symbol.
It contains a Primary key represented by the underline symbol.It contains a Partial Key which is represented by a dashed underline symbol.
The member of a strong entity set is called as dominant entity set.The member of a weak entity set called as a subordinate entity set.
In the ER diagram the relationship between two strong entity set shown by using a diamond symbolThe relationship between one strong and a weak entity set shown by using the double diamond symbol.
The connecting line of the strong entity set with the relationship is single.The line connecting the weak entity set for identifying relationship is double.

Attributes

Attributes are the properties which define the entity type. Example: Roll_No, Name, DOB, Age.

Types of Attributes:

TypeDescription
Simple Attribute/
Atomic Attribute
- Can’t be sub-divided further into any other components.
- Example : Roll, reg_no
Composite Attribute- Can further sub-divided into different components
- combination of other attributes
- Example: name →{ first_name, last_name}
Single-valued - Consists of a single value for each entity.
- Cannot store more than one value.
Example : Roll_no, DOB, reg;
Not: Phone number, because each might have more than one phone number
Multi-valued - Can store more than one value
- Represented by double ellipse/ ovals
Example : Phone, email
Derived- Can be derived from the values of other attributes
- Represented by dashed ellipse/oval
Example : Age. We can find out the age from DOB.
Key- can uniquely identify an entity from an entity set
- identify each tuple according to this key
- represented by underlining
Example : Roll, ID
Stored- fixed value, that won’t be changed in future
Example : DOB

Relationship and Mapping Cardinality

Relationships are association between or among entities.

Mapping Cardinality represents the number of entities to which another entity can be associated via a relationship set.

Types of Relationship:

(As a rule of thumb, you should add a foreign key on the child table referencing the parent table) [Ref]

(Here, the Person table has a PersonID column that’s referenced by the PersonID column in the Passport table. The diagram shows a one-to-one relationship by having a 1 against each column reference. From : Database Guide)

(In this example the primary key field in the Customers table, Customer ID, is designed to contain unique values. The foreign key field in the Orders table, Customer ID, is designed to allow multiple instances of the same value.) [Ref]

(The primary key Student ID uniquely identifies each student in the Students table. The primary key Class ID uniquely identifies each class in the Classes table. The Enrollments table contains the foreign keys Student ID and Class ID.) [Ref]

Degree of Relationships

It represents the number of entity types that associate in a relationship.

Types:

  1. Unary : when both the participating entity type are the same, degree: 1
  1. Binary : when exactly two entity type participates, degree: 2
  1. Ternary: when exactly three entity type participates, degree: 3
  1. N-ary: when exactly n entity type participates, degree: n

Participation Constraints

Participation constraints define the least number of relationship instances in which an entity must compulsorily participate.

Types:

  1. Total/Mandatory Participation: each entity in the entity set must compulsorily participate in at least one relationship instance. It represents by double lines, minimum cardinality 1.
  1. Partial participation: each entity in the entity set may or may not participate in the relationship instance in that relationship set. It represents by single line, cardinality 0.

Relational Model

Integrity Constraints

Integrity constraints are a set of rules defined in a database to maintain data accuracy, consistency and reliability.

Types of Integrity Constraints

Normalization

Anomaly

Anomalies in the relational model refer to inconsistencies or errors that can arise when working with relational databases.


Types of Anomalies:

[ The table has four columns: e_id (employee's id), e_name (employee's name), e_address (employee's address), and e_dept (employee's department). Suppose the table has not been normalized and has redundant data. ]

  1. Insert Anomaly:
    1. Insert anomalies occur when certain attributes cannot be inserted into the database due to missing additional data.
    1. For example, if a new employee is not assigned a department, their data cannot be inserted into the table if the department field does not allow null values.
  1. Update Anomaly:
    1. Update anomaly is something when we are trying to update some records in table, and that update is causing data inconsistency.
    1. For example, if an employee's address changes and the update is made in one row but not in others, the database will contain inconsistent data
  1. Delete anomaly
    1. Delete anomaly is something when we delete some data from the table, and due to that delete operation we loss some other useful data.
    1. For example, if a department is shut down and all rows containing that department are deleted, the data of employees working solely in that department will also be deleted.

Prerequisite for Normal forms:

Normal forms

Normal forms are series of guidelines that help to ensure that the design of a database is efficient, organized and free from data anomalies.

  1. First Normal Form:
    1. The value of each attribute is atomic.
    1. Each record needs to be unique
    1. Each column must have a unique name
    1. Attribute domain should be same

Not in First normal form

In First normal form

[Ref]

FD=ABC,CDFD = {AB \rightarrow C, C \rightarrow D}

CK=ABCK = AB

PA=A,BNPA=C,DPA = A, B \\ NPA = C, D

This is in 2nd NF. Hence, CD,C \rightarrow D,  is NPANPANPA \rightarrow NPA so there is transitive dependency. It is not in 3rd NF.

FD=ABCD,DACK=ABPA=A,BNPA=C,DFD = {AB \rightarrow CD, D \rightarrow A} \\ CK = AB \\ PA = A, B\\ NPA = C, D

This is in 2nd NF . Hence, there is no NPANPA,NPA \rightarrow NPA,  = No transitive dependency. So, it is in 3rd NF.

Here sid and course are dependent but the Course and Skill are independent. The multivalued dependency is denoted as :

sid→ Course

sid→ Skill

Convert it to 4 NF:

(5)

(c)

(6)

(a) A weak entity set can always be made into a strong entity set by adding to its attributes the primary-key attributes of its identifying entity set. Outline what sort of redundancy will result if we do so.

The redundancy resulting from this conversion leads to the unnecessary duplication of primary key attributes in both the weak entity set and the relationship set.

The primary key of a weak entity set can be inferred from its relationship with the strong entity set. If we add primary key attributes to the weak entity set, they will be present in both the entity set and the relationship set and they have to be the same. Hence there will be redundancy.

(b) What are the different steps involved in normalizing a database? Why do you need to use functional dependencies while normalizing databases?

Normalization is a database design technique which organizes tables in a manner that reduces redundancy and dependency of data.

Step:

  1. Unnormalized Form
  1. 1NF
  1. 2NF
  1. 3NF
  1. BCNF
  1. 4NF
  1. 5NF
  1. 6NF

Why do we need to use functional dependency

(c)