DBMS Unit 1
DBMS Unit 1
(KCS-501)
Instructor: Md shahid
Unit-01
Data Inconsistency:
Traditional File System:
Issue: Data inconsistency arises when redundant data in multiple files diverges due
to discrepancies in updates. For example, if customer addresses are updated in one
file but not in another, different files might contain conflicting information about
the same customer.
Impact: This inconsistency can lead to incorrect reporting, errors in decision-
making, and difficulties in maintaining accurate records.
Answer—
File System Database Approach (DBMS)
It is an integral part of the operating system It is a separate software application that
(OS). Examples include NTFS, FAT32, and ext4. provides an interface for users to interact with
databases. Examples include MySQL,
PostgreSQL, and Oracle.
It provides the foundational storage It builds on top of this foundation (provided by
capabilities. the file system) to offer comprehensive and
advanced data management solutions.
Limited data sharing is possible; data is Facilitates data sharing among multiple users.
scattered.
Provides minimal security; data is not well- Provides robust security measures to protect
protected. data.
Backup and recovery mechanisms are not Provides efficient and automated backup and
efficient. recovery mechanisms.
Does not handle concurrent access Manages concurrent access using transaction
effectively, leading to conflicts. management and locking mechanisms.
Three-Schema Architecture of DBMS
The three-schema architecture, also known as the ANSI/SPARC architecture, is a
framework for database management systems that separates the database system
into three distinct levels of abstraction: the internal schema, the conceptual
schema, and the external schema. This architecture aims to separate the user
applications and the physical database to provide data independence.
This schema represents how the data appears to the end users or applications
interacting with the database. It defines various user views or subsets of the
database tailored to specific user groups or applications. Each external
schema provides a simplified and customized view of the data, hiding
unnecessary details and complexity.
2. Conceptual Schema (Logical Schema):
The internal schema describes how the data is physically stored and organized
within the database system. It includes details such as data storage structures,
indexing mechanisms, and access methods. The internal schema is optimized
for efficient storage and retrieval of data, considering factors such as
performance, scalability, and resource utilization.
Note— The ANSI/SPARC DBMS Model, also known as the ANSI/SPARC three-
level architecture, is a conceptual framework proposed by the American
National Standards Institute (ANSI) and the Standards Planning and
Requirements Committee (SPARC) in the late 1970s. It provides a high-level
conceptual view of database systems and serves as a foundation for
understanding and designing modern database management systems
(DBMS).
Data Independence
It refers to the ability to modify the database schema at one level without
affecting the schema at higher levels. The three-schema architecture
promotes data independence by separating the external, conceptual, and
internal schemas:
1. Logical Data Independence:
Answer—
A database system can be divided into three main components: Query Processor,
Storage Manager, and Disk Storage. Each of these components plays a crucial role
in the overall functioning of the database system. Here’s a brief explanation of
each:
1. Query Processor: The query processor handles high-level database operations
and transforms user queries into a series of low-level instructions that can be
executed by the storage manager.
Components:
Compiler and Linker: Converts application programs into executable object
code.
DML Queries: Data Manipulation Language (DML) queries are used by
sophisticated users to retrieve and manipulate data.
DDL Interpreter: Interprets Data Definition Language (DDL) statements to
define and manage the database schema.
Application Program Object Code: Object code resulting from the
compilation of application programs, ready for execution.
DML Compiler and Organizer: Compiles DML queries into an executable form
and organizes them for efficient processing.
Query Evaluation Engine: Executes the compiled queries and interacts with
the storage manager to access or modify data.
2. Storage Manager: The storage manager is responsible for the efficient storage,
retrieval, and update of data in the database.
Components:
Buffer Manager: Manages memory buffers that temporarily store data
during processing to improve performance.
File Manager: Handles the storage, retrieval, and management of data files
on disk.
Authorization and Integrity Manager: Ensures that all database operations
comply with security and integrity constraints.
Transaction Manager: Manages transactions to ensure the ACID properties
(Atomicity, Consistency, Isolation, Durability) are maintained.
3. Disk Storage: Disk storage is where the actual data is stored. This includes not
only the data itself but also indices, metadata, and statistical data.
Components:
Data: The actual data stored in the database.
Indices: Data structures that improve the speed of data retrieval operations.
Data Dictionary: Metadata repository containing information about the
database schema, structure, and constraints.
Statistical Data: Statistical information used to optimize query processing
and execution plans.
For example
A database schema for the representation of students, courses, and their
enrollments in a relational database, tracking student information, course details,
and enrollment records within the university database system.
Student
Student_id (primary key) First_Name Last_Name DOB Email Ph.no
Course
Course_id (primary key) Course_name Department Credits
Enrollment
Enrollment_id Student_id (Foreign Course_id Enrollment_date Grade
(primary key) key referencing (Foreign key
Student table) referencing
Course table)
Database Instance— It is a snapshot of the data in the database at a given
instance of time.
Data Models
A data model is a collection of concepts and rules that are used to describe the
structure of a database, including the data types, relationships, and constraints
that apply to the data.
1. Relational Data Model— This model organizes data into tables (relations),
where each table consists of rows and columns. Relationships between
tables are established through keys. It's the most widely used in modern
database management systems (DBMS) and is based on relational algebra
and calculus.
Note— The network and hierarchical models are legacy data models that were
widely used in the past. These models played a significant role in the early
development of database systems but have largely been replaced by the more
flexible and powerful relational model.
Database Languages
DDL (Data Definition Language) and DML (Data Manipulation Language) are the
core languages provided by a database system. In practice, the DDL and DML are
not two separate languages; instead they simply form parts of a single database
language, such as the SQL language. Almost all RDBMS employ the SQL language.
We specify the storage structure and access methods used by the database system
by a set of statements in a special type of DDL called a data storage and definition
language (DSDL). These statements define the implementation details of the
database schemas, which are usually hidden from the users.
By using DDL, database administrators and developers can effectively manage the
structure and properties of the database, ensuring data consistency, integrity, and
usability.
Here are some common tasks accomplished using DDL:
Creating Views: Define virtual tables that present data from one or
more tables in a predefined manner.
Data Manipulation Language (DML)— DML provides users with the tools to
retrieve, insert, update, and delete data within a database, enabling them to
interact with the data stored according to the defined data model.
functions of DML:
Deleting Data: DML allows users to remove records or rows of data from
database tables. The DELETE statement is used to delete data from the
database.
Data Manipulation Languages (DMLs) can be broadly categorized into two types
based on their approach to specifying data manipulation operations:
DDL (Data Definition Language): SQL includes DDL commands for defining
and modifying the structure of the database schema. These commands allow
users to create, alter, and drop database objects such as tables, views,
indexes, and constraints.
Examples of DDL commands in SQL include CREATE TABLE, ALTER TABLE, and
DROP TABLE.
The ER model utilizes concepts from set theory to represent entities as sets,
attributes as sets of values, and relationships as sets of tuples.
Entity
Entity— It is an individual instance of a real-world object or concept that
has a distinct and independent existence.
Entity Set
An entity set is a collection of all individual entities of a particular entity type that
exist within the database at a given point in time. It is the actual data or instances
that correspond to the entity type; the entity set is usually referred to using the
same name as the entity type.
Name DateOfBirth
StudentID
Student
Fig: A Strong Entity Type “Student”
Fig: A table (relation) for Strong Entity Type “Student” containing 5 entities
Note— “Entity” is a broader term that can refer to both the general concept (entity
type) and specific instances depending on the context.
Attribute
It is a property that describes an entity. For example, employee_id, name, and
salary are attributes of entities such as "employee1" and "employee2." Attributes
are represented by ovals and are connected to an entity type and relationship type.
Sex
DOB
Emp_id
Emp_name
Employee
Key Attributes— key attributes refer to one or more attributes that together
uniquely identify each instance of an entity type. When an entity type has multiple
attributes that, when combined, uniquely identify an entity, they are collectively
known as a composite key or composite key attribute. For example, in an employee
database, the attribute employee_id can be a key attribute because it uniquely
identifies each employee in the database. Key attributes are represented by
underlining them in ER diagrams.
Name Address
Emp_id
oEmployee
Key attribute
Relationship Type
Relationship
A relationship refers to an actual instance or occurrence of a relationship type
between specific entities. It is the specific connection between particular instances
of the involved entity types. In ER diagrams, individual relationships are usually not
explicitly shown; rather, the focus is on the relationship type that defines the
general association. For example, If Employee1 works for the Marketing
department, this is an actual instance of the "Works For" relationship type.
e1 r1
e2 r2 d1
e3 r3 d2
e4 r4 d3
e5
The relationship instance r1 is associating e1, of entity type Employee, with d1 of
entity type Department.
A relationship instance in a relationship set R is an association of entities
where the association includes exactly one entry from each participating
entity type. This means that a relationship instance represents a specific
connection between one instance of each participating entity type in the
relationship.
Recursive Relationship— If the same entity type participates more than once in a
relationship type in different roles, it is called a recursive relationship. For example,
an employee supervises other employees within the same entity type.
Supervises
e1
Employee r1 role1 = supervisor (in black)
e2 r2 role2 = supervisee (in blue)
e3
r3
e4
e5
e
2. Binary (Degree 2): A relationship type involving two different entity types is
said to have degree 2. Binary relationships are the most common. For
example, The "Works For" relationship type between the Employee and
Department entity types.
3. Ternary (Degree 3): A relationship type involving three different entity types
is said to have degree 3.
For Example, A "Supplies" relationship type might involve the Supplier,
Product, and Store entity types, indicating that a supplier supplies products
to stores.
Cardinality and participation are two fundamental constraints that describe the
nature of a relationship between entities in an Entity-Relationship Diagram (ERD).
These constraints help define how entities are associated with each other within a
relationship. The participation constraint is often referred to as the minimum
cardinality of a relationship. The cardinality constraint is also referred to as the
cardinality ratio. Cardinality and participation are collectively referred to as the
structural constraints.
e1 r1
d1
e2 r2
d2
e3 r3
d3
e4 r4
d4
e5
1 1
Employee Department
Manages
2. 1: N (one to many)—
Constraints: Every employee works for a department, and a department can
have many employees. New departments need not have any employee.
Employee Works for Department
e1 r1
d1
e2 r2
d2
e3 r3
d3
e4 r4
Employee N 1
Works for Department
OR
Employee Department
Works for
Note— The cardinality ratio in an ERD is mentioned on the opposite side. For
example, for a 1: N relationship, 'N' is mentioned on the left side of the relation and
'1' is mentioned on the right side.
3. N: 1 (many to one)
In a one-to-many relationship, we look at it from the perspective of the
"one" side. In a many-to-one relationship, we look at it from the perspective
of the "many" side. Essentially, they describe the same relationship but from
different angles.
4. M: N (many to many)
Constraints: Every employee should work on at least one project,
and a project should have at least one employee.
E1
r1
E2 P1
r2
E3 p2
r3
E4 p3
r4
r5
r6
Fig: 5
Cardinality Ratio in ER diagram for Many -to-Many
Employee N M
Works on Project
OR
Employee Project
Works on
Participation Constraint
The participation of a binary relationship specifies the minimum number of
relationship instances that an entity can participate in, and it is determined by
examining the constraints mentioned in the requirements.
Types of Participation
1. Partial Participation: Only some instances of an entity type
participate in the relationship. A single line is used to indicate it.
2. Full Participation: All instances of an entity type participate in the
relationship. Double lines are used to indicate it.
Mapping Participation in ER diagram: From figure 5, we can observe that Employee
to Project and Project to Employee participations are full participation.
Employee Project
Works on
Identifying the “Entity Types” and “Attributes” from the
Requirements
Requirements:
The company is organized into departments. Each department has a unique name,
a unique number, and a particular employee who manages the department. We
keep track of the start date when that employee began managing the department.
A department may have several locations. A department controls a number of
projects, each of which has a unique name, a unique number, and a single location.
The database will store each employee’s name, Social Security number, address,
salary, gender, and birth date. An employee is assigned to one department, but
may work on several projects, which are not necessarily controlled by the same
department. It is required to keep track of the current number of hours per week
that an employee works on each project, as well as the direct supervisor of each
employee (who is another employee).
The database will keep track of the dependents of each employee for insurance
purposes, including each dependent’s first name, gender, birth date, and
relationship to the employee.
Answer—
The company is organized into departments. Each department has a unique name,
a unique number, and a particular employee who manages the department. We
keep track of the start date when that employee began managing the department.
A department may have several locations.
Manager Manager_Start_Date
Name Locations
Dept.number
Department
A department controls a number of projects, each of which has a unique name, a
unique number, and a single location.
Project
The database will store each employee’s name, Social Security number, address,
salary, gender, and birth date. An employee is assigned to one department, but
may work on several projects, which are not necessarily controlled by the same
department. It is required to keep track of the current number of hours per week
that an employee works on each project, as well as the direct supervisor of each
employee (who is another employee).
L_name
F_name
M_nam Supervisor Hours Project
e
Dept.
SSN
DOB Gende Salary
r Works
Works on
on
Name Salary
Address
Employee
The database will keep track of the dependents of each employee for insurance
purposes, including each dependent’s first name, gender, birth date, and
relationship to the employee.
Gender DOB
Depen_name
Employee
Relationship
Dependent
Works for
We can clearly observe that the attribute "Dept" of entity type "Employee" refers
to another entity type "Department", leading to a relationship type "Works for".
Therefore, we remove the attribute "Dept" from the "Employee" entity type and
represent this relationship explicitly.
Manages
We can clearly observe that the “manager” attribute of the entity type Department
refers to another entity type, Employee. Therefore, the manager attribute will be
converted into a relationship type, and the attribute will be deleted from the
Department entity type.
Attributes of a Relationship Type
Attributes from the entity type that are closely related to a relationship type
become attributes of the relationship type and are then deleted from the entity
type.
Manager_start_date
Q. Given the following constraints:
Every employee works for a department.
A department can have many employees.
New departments do not need to have any employees.
Determine the following:
A. The Relationship Type
B. The Cardinality Ratio
C. The Participation Constraints
Also represent cardinality and participation in an ERD
Answer—
e1 r1
d1
e2 r2
d2
e3 r3
d3
e4 r4
Employee Department
Works for
1, 1 0, N
Name
Employee
Tuples Employee
Name Age DOB SSN Salary
Domain— A domain is the data type that defines the type of values that can appear
in each column of a table. It specifies the permissible values for an attribute,
including constraints such as data type, format, and range. For every attribute, its
domain must be declared to ensure that the values stored in that attribute adhere
to the defined constraints. For example, for the name attribute, it is character
string.
Relation Schema— A relation schema R, denoted by R (A1, a2, ..., A n), is made up
of a relation name R and a list of attributes. The degree of a relation is the number
of attributes. For example, if we consider the above Employee relation then
relation schema will be:
Employee (Name, Age, DOB, SSN, Salary)
OR
Employee
Name Age DOB SSN Salary
Note— Database Schema: The logical structure and constraints of the entire
database, including multiple relations (tables) and their relationships.
Relation Schema: The logical structure and constraints of a single relation (table)
within the database.
Relation State (Relation Instance)— This refers to the actual data present in a
relation (or table) at a specific point in time. It consists of all the tuples (rows) that
are currently stored in the table.
Now, we are in a position to design a relational database schema from a given ER
diagram.
To understand it better, we are going to consider only the entity type 'Employee',
the relationship type 'works for', and the entity type 'Department' for converting
into a database schema. By doing it, we will also come to know how we can
translate many-to-one relationship into database schema.
An entity type represents a relation (table) in RDBMS.
Attributes of an entity type are represented as the columns in a relation.
Every attribute (column) in a table (relation) should be simple attribute
(atomic). It means composite and multivalued attributes are not allowed in
a table.
Employee
F_name M_name L_name DOB SSN Add Salary Sex
Department
D_name D_number Locations
As it is a multi-valued
attribute, it is not allowed to
become a column name, but
for now, we will consider it as
a simple attribute. Later, we
will learn how we can
convert it into relation
schema.
Now, we need to take care of “works for”, which is a relationship type. We already
know every relation in ERD is an attribute of another entity type; therefore, this
relation (WORKS FOR) is again converted into an attribute of the entity type
“Employee”.
Note— In a many-to-one (M:1) relationship, the relationship is effectively
represented in the entity that is on the "many" side of the relationship.
Employee
Department
D_name D_num Locations
Whenever the values of a key attribute (D_num from the Department table) are
represented into another table (D_num in Employee table), it means there exists a
relationship between these two tables, which is represented by an arrow from
referencing attribute to referenced attribute.
Now, we have designed a schema diagram for a small part of the original ER
diagram. Therefore, before converting the entire ERD into a database schema, we
will first see how we implement this small schema diagram using SQL, without
establishing the relation between the two tables.
INSERT INTO Employee(F_name, M_name, L_name, DOB, SSN, Address, Sex, Salary,
D_num) VALUES('MD', 'S', 'KHAN', TO_DATE('12-Nov-1989', 'DD-Mon-YYYY'),
'1234', 'MIET', 'M', 10000, 1);
One row is inserted into Employee table.
Department
D_name D_num Locations Mgr_SSN Mgr_start_date
Project
P_name P_num P_Location D_num
Note— For many-to-many relationship, kindly refer GATE problems given later
in this PDF.
Multivalued Attributes to Database Schema
When translating multivalued attributes from an Entity-Relationship (ER) diagram
into a relational database schema, the multivalued attribute is represented by
creating a separate table. This new table will store the values of the multivalued
attribute, with a foreign key linking back to the original entity.
We will consider the Department entity to illustrate this concept as it has a multi-
valued attribute named locations.
Department
D_name D_num Mgr_SSN Mgr_start_date
Dept_Location
D_name D_num
Note— This question is taken from Navathe’s book, Chapter Three, and has also
been asked in the AKTU exam.
Answer—
Step-01: Identify Entity Types
Based on the requirements provided, the following entity types can be identified
for the ER schema diagram:
A. Team
B. Game
C. Player
Step-02: Identify Relationship Types
Relationships connect entities and represent how these entities interact with each
other. In this case, we have three relationships: Team to Player ('has'), Team to
Game ('plays') and Player to Game ('participates in').
Team Game
Plays
Participates in
Has
Player
Cardinality Constraint
The 'has' and 'plays' relationships are one-to-many relationships, as a team has
many players and plays many games but each player and game belong to one team.
The 'participates in' relationship is many-to-many, as many players can participate
in many games.
Team M 1 Game
Plays
M M
Has 1 M Participates in
Player
Step-03: Identify Attributes for each Entity Type
A. Entity Type “Team”
Attributes: TeamID and TeamName
TeamID TeamName
Team
Step-03: If we draw all the entities (Team, Player, Game), their relationships ('has',
'participates in', 'plays') and attributes together, it will lead to the formation of the
complete ER diagram.
Q. Consider the following ER diagram and find out the minimum number of tables
needed to represent this ERD in the relational database.
M P R2
R2 NN
R1
M3 P1 P2
M1 N1 N2
M2
E2
E1
R2
R1E2
E1
R2
There are minimum three tables required.
Super Key
A super key is a set of one or more attributes that, taken collectively, can uniquely
identify a tuple (row) in a relation (table). This means that no two distinct tuples in
the relation can have the same values for the attributes in the super key.
Characteristics of a Super Key:
Uniqueness: A super key ensures that each tuple in the table is uniquely
identified by the combination of attributes.
Superset of Keys: Super keys are a superset of other keys (primary key,
candidate key and unique key) in a relational database.
NULL Values: A super key does not have a strict requirement that all its
attributes must be non-null. As long as the combination of values in the super
key uniquely identifies each tuple, NULL values can be present in some
attributes.
Extraneous Attributes: Super keys may contain extraneous attributes that
are not necessary for uniqueness. These attributes can be removed to form
a candidate key, which is a minimal super key.
Let’s try to under super keys with a suitable example.
Employee
Name Age DOB SSN Salary
Rahul 30 1990 660911228333 20,000
Rawat 30 1992 650911228333 40,000
Rahul 40 1990 640911228333 20,000
Conclusion:
Key Attribute: SSN is the key attribute because it uniquely identifies each
employee.
Not Key Attributes: Name, Age, DOB, and Salary cannot be used alone as keys since
they are not unique.
Since SSN is a unique identifier and minimal as well, any combination of attributes
that includes SSN will be a super key. Let’s identify all possible super keys:
List of all Possible Super Keys
Single Attribute Super Key:
1. {SSN}: As SSN is unique, it alone can uniquely identify each row.
Combination of SSN with Other Attributes:
2. {SSN, Name}
3. {SSN, Age}
4. {SSN, DOB}
5. {SSN, Salary}
6. {SSN, Name, Age}
7. {SSN, Name, DOB}
8. {SSN, Name, Salary}
9. {SSN, Age, DOB}
10. {SSN, Age, Salary}
11. {SSN, DOB, Salary}
12. {SSN, Name, Age, DOB}
13. {SSN, Name, Age, Salary}
14. {SSN, Name, DOB, Salary}
15. {SSN, Age, DOB, Salary}
16. {SSN, Name, Age, DOB, Salary}
Candidate Keys
A candidate key is a super key with no proper subset that can also be a key.
Employee
id name salary SSN email mob.
123 Rahul 10,000 4321 [email protected] 9910669313
321 Vivek 20,000 5432 [email protected] 9910669313
432 Rahul 10,000 3456 [email protected] 1910669310
Note— The values of the attribute 'name' alone are not unique, but when
combined with 'mob', they are unique.
Primary Key
A primary key is a candidate key chosen to uniquely identify each tuple (row) in a
table. It ensures that each record within the table is unique and non-null. A primary
key must have unique values and cannot contain NULL values for any tuple. Each
table can have only one primary key, which may consist of one or multiple
attributes (a composite key).
id name salary SSN email mob.
123 Rahul 10,000 4321 [email protected] 9910669313
321 Vivek 20,000 5432 [email protected] 9910669313
432 Rahul 10,000 3456 [email protected] 9910669310
Primary key: One among {id}, {SSN}, {email} and {name, mob}
Composite Key
A composite key is a combination of two or more attributes that together uniquely
identify a tuple (row) in a relation (table). None of the individual attributes can
uniquely identify the tuple on their own, but when combined, they ensure
uniqueness. Composite keys are used when a single attribute is not sufficient to
ensure the uniqueness of a record. For example, the key {name, mob} in the
Employee table is a composite key and can be used a primary key.
Alternate Keys
An alternate key is a candidate key that was not chosen as the primary key for a
table. It can uniquely identify tuples in the table, similar to the primary key.
However, it is not used as the primary key. A table may have multiple alternate
keys, each of which can potentially serve as a unique identifier for the records.
Employee
id name salary SSN email mob.
123 Rahul 10,000 4321 [email protected] 9910669313
321 Vivek 20,000 5432 [email protected] 9910669313
432 Rahul 10,000 3456 [email protected] 9910669310
A foreign key is an attribute (or set of attributes) in one table that establishes a link
to the primary key of another table. It is used to enforce referential integrity by
ensuring that the values in the foreign key column(s) correspond to valid values in
the primary key column(s) of the referenced table. Foreign keys can contain
duplicate values and NULLs. A table can contain multiple foreign keys, each
referencing a primary key in a different table or even in the same table (self-
referencing).
Foreign Key
Primary key Primary key
Employee Department
Name Gender SSN Salary D_num D_name D_number Location
If we attempt to insert a new row into the Employee table, for example, (Sahil, M,
111, 40000, 3), we cannot do so if D_num 3 does not exist in the Department table.
This is because the referential integrity constraint ensures that the D_num in the
Employee table must correspond to a valid D_number in the Department table.
Therefore, a row with a D_num that does not have a corresponding department in
the Department table cannot be inserted.
Implementation of Referential Integrity Constraint Using Foreign keys
Employee
Department
D_name D_num Locations
Create Table Employee (F_name varchar (20) NOT NULL, M_name varchar (10),
L_name varchar (15) NOT NULL, DOB date, SSN varchar (10) NOT NULL, Address
varchar (30), Sex varchar (1), Salary float, D_num int NOT NULL, PRIMARY KEY (SSN),
FOREIGN KEY(D_num) REFRENCES Department(D_num));
Actions upon Constraints Violation
1. Domain Constraints:
Actions upon Violation:
Error Message: The database system raises an error indicating that the value does
not conform to the domain constraints.
Operation Rejected: The operation (e.g., INSERT or UPDATE) is rejected until the
value is corrected to meet the domain constraints.
ON DELETE CASCADE: If the parent record is deleted, all related child records
are also deleted.
ON UPDATE CASCADE: If the parent record’s primary key is updated, all
related foreign keys in the child table are also updated.
Set Null: This action sets the foreign key in the child table to NULL if the
corresponding parent record is deleted or updated.
ON DELETE SET NULL: If the parent record is deleted, the foreign key in the
child table is set to NULL.
ON UPDATE SET NULL: If the parent record’s primary key is updated, the
foreign key in the child table is set to NULL.
Set Default: This action sets the foreign key to a default value if the
corresponding parent record is deleted or updated.
ON DELETE SET DEFAULT: Sets the foreign key in the child table to a default
value if the parent is deleted.
ON UPDATE SET DEFAULT: Sets the foreign key to a default value if the
parent record is updated.
Note— You will learn about the three actions associated with referential integrity
upon violation in the DBMS lab.
Q. The following table has two attributes A and C where A is the primary key and
C is the foreign key referencing A with on-delete cascade.
A C
-----
2 4
3 4
4 3
5 2
7 2
9 5
6 4
The set of all tuples that must be additionally deleted to preserve referential
integrity when the tuple (2,4) is deleted is?
Q1. Given a relation R (A1, A2, ..., An) with {A1} as the candidate key, determine the
number of super keys.
Answer— We know that the superset of a candidate key is also a super key. This
means that any set of attributes that contains a candidate key (or is equal to the
candidate key) can uniquely identify tuples in a relation, making it a super key.
With the three attributes, one being candidate key, we have 22 super keys. So,
the correct formula to find the number of super keys when there are “n”
attributes and one candidate key is 2(n-1).
Q2. Given a relation R (A1, A2, ..., An) with {A1A2A3} as the candidate key,
determine the number of super keys.
Answer—
(n-1)
2 + 2(n-1) - 2(n-2)
Q4. Given a relation R (A1, A2, ..., An) with {A1, A2} and {A3, A4} as the candidate
keys, determine the number of super keys.
Answer— 2(n-2) + 2(n-2) - 2(n-4)
Q5. Given a relation R (A1, A2, ..., An) with {A1, A2} and {A1, A3} as the candidate
keys, determine the number of super keys.
Answer— 2(n-2) + 2(n-2) - 2(n-3)
Q6. Given a relation R (A1, A2, ..., An) with {A1}, {A2} and {A3} as the candidate
keys, determine the number of super keys.
Answer— [ Use this ∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣B∩C∣−∣C∩A∣+∣A∩B∩C∣]
1. {A} 6. {A, B, D}
2. {A, B} 7. {A, C, D}
3. {A, C} 8. {A, B, C, D}
4. {A, D} 9. {B, C}
5. {A, B, C} 10. {B, C, D}