Komal DBMS
Komal DBMS
ON
“Database Management System”
(Subject Code: - KCA-252)
(Sign :-___________)
I am also grateful for his cooperation in providing me with all the required resources.
I would like to extend special thanks to all my colleagues for their help and constant
support.
This work cannot be completed without the help of above mentioned person.
-With gratitude
INTRODUCTION:
A Database Management System (DBMS) is a software system that isdesigned to
manage and organize data in a structured manner. It allows users to create, modify,
and query a database, as well as manage the security and access controls for that
database.
Page 1 of 48
KOMAL SINGH| Roll No. 2204340140035
❖ DDL is the short name for Data Definition Language, which deals with database
schemas and descriptions, of how the data should reside in the database.
• CREATE: to create a database and its objects like (table, index, views, store
procedure, function, and triggers)
• ALTER: alters the structure of the existing database
• DROP: delete objects from the database
• TRUNCATE: remove all records from a table, including all spaces allocated for the
records are removed
• COMMENT: add comments to the data dictionary
• RENAME: rename an object.
❖ DML is the short name for Data Manipulation Language which deals with data
manipulation and includes most common SQL statements such SELECT, INSERT,
UPDATE, DELETE, etc., and it is used to store, modify, retrieve, delete and update
data in a database.
• SELECT: retrieve data from a database
• INSERT: insert data into a table
• UPDATE: updates existing data within a table
Page 2 of 48
KOMAL SINGH| Roll No. 2204340140035
❖ DCL is short for Data Control Language which acts as an access specifier to the
database.(basically to grant and revoke permissions to users in the database
• GRANT: grant permissions to the user for running DML(SELECT, INSERT, DELETE,…)
commands on the table
• REVOKE: revoke permissions to the user for running DML(SELECT, INSERT,
DELETE,…) command on the specified table.
❖ TCL is short for Transactional Control Language which acts as an manager for all types
of transactional data and all transactions.Some of the command of TCL are
• Roll Back: Used to cancel or Undo changes made in the database .
• Commit: It is used to apply or save changes in the database.
• Save Point: It is used to save the data on the temporary basis in the database.
Database Management System: The software which is used to manage databases is
called Database Management System (DBMS). For Example, MySQL, Oracle, etc. are
popular commercial DBMS used in different applications. DBMS allows users the
following tasks:
Data Definition: It helps in the creation, modification, and removal of definitions that
define the organization of data in the database.
Data Updation: It helps in the insertion, modification, and deletion of the actual data
in the database.
Data Retrieval: It helps in the retrieval of data from the database which can be used
by applications for various purposes.
Page 3 of 48
KOMAL SINGH| Roll No. 2204340140035
File System manages data using files on a hard disk. Users are allowed to create,
delete, and update the files according to their requirements. Let us consider the
example of file-based University Management System. Data of students is available to
their respective Departments, Academics Section, Result Section, Accounts Section,
Hostel Office, etc. Some of the data is common for all sections like Roll No, Name,
Father Name, Address, and Phone number of students but some data is available to a
particular section only like Hostel allotment number which is a part of the hostel
office. Let us discuss the issues with this system:
Page 4 of 48
KOMAL SINGH| Roll No. 2204340140035
5. No Concurrent Access: The access of the same data by multiple users at the
same time is known as concurrency. The file system does not allow
concurrency as data can be accessed by only one user at a time.
6. No Backup and Recovery: The file system does not incorporate any backup and
recovery of data if a file is lost or corrupted.
ADVANTAGES OR DISADVANTAGES:
Advantages of using a DBMS:
• Data organization: A DBMS allows for the organization and storage of data in a
structured manner, making it easy to retrieve and query the data as needed.
• Data integrity: A DBMS provides mechanisms for enforcing data integrity
constraints, such as constraints on the values of data and access controls that
restrict who can access the data.
• Concurrent access: A DBMS provides mechanisms for controlling concurrent
access to the database, to ensure that multiple users can access the data without
conflicting with each other.
• Data security: A DBMS provides tools for managing the security of the data, such
as controlling access to the data and encrypting sensitive data.
• Backup and recovery: A DBMS provides mechanisms for backing up and recovering
the data in the event of a system failure.
• Data sharing: A DBMS allows multiple users to access and share the same data,
which can be useful in a collaborative work environment.
Disadvantages of using a DBMS:
• Complexity: DBMS can be complex to set up and maintain, requiring specialized
knowledge and skills.
• Performance overhead: The use of a DBMS can add overhead to the performance
of an application, especially in cases where high levels of concurrency are required.
• Scalability: The use of a DBMS can limit the scalability of an application, since it
requires the use of locking and other synchronization mechanisms to ensure data
consistency.
Page 5 of 48
KOMAL SINGH| Roll No. 2204340140035
• Cost: The cost of purchasing, maintaining and upgrading a DBMS can be high,
especially for large or complex systems.
• Limited use cases: Not all use cases are suitable for a DBMS, some solutions don’t
need high reliability, consistency or security and may be better served by other
types of data storage.
These are the main reasons which made a shift from file system to DBMS.
Page 6 of 48
KOMAL SINGH| Roll No. 2204340140035
2. Create a simple table structure for a student database, including the necessary
attributes and data types.
Query-
CREATE TABLE students (
S_ID INT PRIMARY KEY,
Name VARCHAR(10),
Class VARCHAR(15),
Age int(11),
DOB date,
address VARCHAR(15)
);
OUTPUT:
Page 7 of 48
KOMAL SINGH| Roll No. 2204340140035
A relation is in 2NF only if it is in 1NF also as all the non-key attributes in the tables are
addicted to the table’s primary key. this type applies to those relations that are
Page 8 of 48
KOMAL SINGH| Roll No. 2204340140035
connected using composite keys. The relation of the tables is coupled with a key that
is composed of over one attribute.
A relation is in 3NF if and only if it’s in 2NF and there’s no transition dependency.
The main use of normalization is to utilize in order to remove anomalies that are
caused because of the transitive dependency. Normalization is to minimize the
redundancy and remove Insert, Update and Delete Anomaly. It divides larger tables
into smaller tables and links them using relationships.
Advantages:
There are many benefits to normalizing a database. Some of the main advantages are:
1) By using normalization redundancy of database or data duplication can be
resolved.
2) We can minimize null values by using normalization.
3) Results in a more compact database (due to less data redundancy/zero).
4) Minimize/avoid data modification problems.
5) It simplifies the query.is
6) The database structure is clearer and easier to understand.
7) The database can be expanded without affecting existing data.
8) Finding, sorting, and indexing can be faster because the table is small and more
rows can be accommodated on the data page.
Page 9 of 48
KOMAL SINGH| Roll No. 2204340140035
Page 10 of 48
KOMAL SINGH| Roll No. 2204340140035
Page 11 of 48
KOMAL SINGH| Roll No. 2204340140035
5. Explain the concept of primary keys and foreign keys in a relational database.
In a relational database, keys are the most important elements to maintain the
relationship between two tables or to uniquely identify the data from a table. Primary
key is used to identify data uniquely therefore two rows can't have the same primary
key. It can't be null. On the other hand, foreign key is used to maintain relationship
between two tables.
The primary key of a table acts as the foreign key in another table. The Foreign key in a
table helps enforce Referential Integrity constraint. Read this tutorial to find out more
about Primary and Foreign keys and how they are different from each other.
Primary Key -
A primary key is a column (or set of columns) in a table that uniquely identifies each
row in the table. It cannot contain null values and must be unique across all rows in the
table. Only one primary key is allowed in a table.
A primary key is basically a combination of the 'UNIQUE' and 'Not Null' constraints.
Thus, it cannot be a NULL value. Another important point to be noted about primary
key is that its value cannot be deleted from the parent table.
Foreign Key -
A foreign key is a column (or set of columns) in a table that refers to the primary key in
another table. It is used to establish a link between the two tables and is used to enforce
referential integrity in the database. Foreign key is basically the field/column in a table
that is analogous to the primary key of other table.
Unlike a primary key, a table can have more than one foreign key. Also, the foreign key
can contain duplicate and null values in a relational database. The value of a foreign key
can be deleted from the child table.
The following table highlights all the important differences between primary key and
foreign key –
Primary keys and foreign keys are important concepts in database design as they help
to establish relationships between tables and help ensure data integrity. A primary key
uniquely identifies a row in a table, while a foreign key is used to link two tables
together by referencing the primary key of the related table. The most important
difference that you should note here is that a primary key cannot have a NULL value,
whereas a foreign key can accept NULL values.
Page 12 of 48
KOMAL SINGH| Roll No. 2204340140035
Two or more rows can't have same It can carry duplicate value for a
Duplicate
primary key. foreign key attribute.
Page 13 of 48
KOMAL SINGH| Roll No. 2204340140035
b) Retrieve records using different types of joins: inner join, left join, and right join.
• Inner join-
SELECT *
FROM students
INNER JOIN courses ON students.student_id = courses.student_id;
Structure-
• Left join-
SELECT *
FROM students
LEFT JOIN courses ON students.student_id = courses.student_id;
Page 14 of 48
KOMAL SINGH| Roll No. 2204340140035
Structure-
• Right Join-
SELECT *
FROM students
RIGHT JOIN courses ON students.student_id = courses.student_id;
Structure-
• Full Join-
SELECT *
FROM students
LEFT JOIN courses ON students.student_id = courses.student_id
UNION ALL
SELECT *
FROM students
RIGHT JOIN courses ON students.student_id = courses.student_id
WHERE students.student_id IS NULL;
Page 15 of 48
KOMAL SINGH| Roll No. 2204340140035
Structure-
Min -
Select e_name,salary from emp where salary = (select min (salary )from emp);
OUTPUT:
Max-
Select e_name ,salary from emp where salary =(select max (salary ) from emp);
Page 16 of 48
KOMAL SINGH| Roll No. 2204340140035
OUTPUT:
Count-
Select count (salary) from emp;
OUTPUT:
Sum-
Select sum(salary) from emp;
OUTPUT:
Average –
select avg(salary) from emp;
OUTPUT:
Page 17 of 48
KOMAL SINGH| Roll No. 2204340140035
Transaction
A transaction is a single logical unit of work formed by a set of operations. the
operations which are between the beginning and the end of the transaction are
counted as a single logical unit. The database is inconsistent during the transaction.
It goes into a consistent state only when the transaction has occurred successfully.
It is very important to have a successful transaction.
For example , if you are sending $100 from your account to your friend's account,
then the money deducted from your account should be reflected to your friend's
account.
States Of Transaction
A transaction goes through any different states throughout its lifecycle. These
states also known as transaction state are as follows:
1. Active State: This is the first state of the transaction and any transaction which is
being executed is in this state. The changes made are stored in the buffer in the
main memory.
2. Partially Committed: After the last operation is executed the transaction enters
into the partially committed state. This is said partially committed because the
changes made are still in the buffer in the main memory.
3. Failed State: A transaction enters into the failed state if some checks fail in the
active state, some error occurs in the active or partially committed state and the
transaction cannot be executed further.
4. Aborted State: If any transaction has reached the failed state then the recovery
manager rollback the database to its original state from where the execution had
started.
5. Committed State: A transaction from the partially committed state enters into the
committed state if all the operations are executed successfully. It is not possible to
rollback from this state and it is a new consistent state.
Page 18 of 48
KOMAL SINGH| Roll No. 2204340140035
ACID Properties
For maintaining the integrity of data in the database the certain properties are
followed by all the transactions that take place in the database. These properties are
popularly known as ACID properties where A is for Atomicity, C for Consistency, I
for Isolation and D for Durability.
❖ Atomicity-
This property states that the transaction should either occur completely or doesn't
occur at all. The transaction should not occur partially. Each transaction is treated
as a unit and the execution is completed else the transaction is aborted. If any
transaction is aborted all the changes made are reversed back. If the transaction
occurs completely then only it is committed.
Example: Suppose there are two accounts A and B having a balance of Rs 1000 and
Rs 500 respectively. Now, if you have to transfer Rs 200 from Account A to Account
B then this transaction involves two operations . First, debiting Rs 200 from
Account A and second, crediting Rs 200 to Account B.
Now, let's consider a situation where the first operation has occurred successfully
i.e. Rs 200 was debited from Account A and the balance in Account A is now Rs 800.
But, the second transaction failed . So, the Rs 200 was not added to Account B. This
can lead to inconsistency in the database. So, either the transaction should fail or
both the operations should occur if the transaction has to be successful. The
atomicity thus helps in ensuring the correctness of the database.
Page 19 of 48
KOMAL SINGH| Roll No. 2204340140035
❖ Consistency-
This property ensures that the integrity of the database is maintained before and
after the transaction. It ensures that when any transaction is executed then the
database should move from one consistent state to another consistent state.
Example: In the above example, Account A and Account B have Rs 1000 and Rs 500
respectively. So, the total amount is Rs 1000+ Rs 500 i.e. Rs 1500 before the
transaction. When any transaction is executed then the total amount should also be
Rs 1500. If the transaction occurs then Rs 200 will be deducted from Account A and
added to Account B. So, the total amount after the transaction will Rs 800 + Rs 700
i.e. Rs 1500 . So, this property ensures the consistency of the database. If any
operation in the transaction fails it will produce inconsistency in the data.
❖ Isolation-
This property tells that each transaction is executed in the system such that it is the
only transaction in the system. If more than one transaction is taking place in
parallel, then the occurrence of one transaction will not affect the other transaction.
If any transaction is using a data item then it can’t be used by other transactions
until the first transaction ends.
Now, consider a situation where T1 has been executed until Read(Y) and then T2
starts. Due to this, the transaction T2 reads the incorrect value of Y . It reads the
Page 20 of 48
KOMAL SINGH| Roll No. 2204340140035
value as 20 and the operations which it should have been performed by taking the
value as 10, T2 will perform by taking the value as 20. This leads to inconsistent
results. The output of the transaction T2 should have been X*Y i.e. 90*10(=900) but
it will produce the output as 90*20 i.e. 1800 as T2 has read the incorrect value of Y.
This problem happened because of the transaction result of T1 was made available
for T2. So to avoid any such problem the transactions take place in isolation.
❖ Durability -
This property ensures that once the changes are made in the database these
changes persist in the database even if any system failure occurs. These changes are
saved permanently in the non-volatile memory. It is the responsibility of the
recovery manager to ensure the durability in the database.
Page 21 of 48
KOMAL SINGH| Roll No. 2204340140035
8. Describe the different types of database constraints (e.g., unique, foreign key)
and their purposes.
Constraints are rules and regulations that are enforced on the data. They are used to
validate data. It specifies conditions that the data must satisfy.
SQL constraints are used to specify rules for the data in a table. They are used to
limit the type of data that can be stored in a particular column of a table. Constraints
ensure that the data stored is valid. This ensures the accuracy and reliability of the
data in the database.
Constraints could be either at the column level or at the table level. Column level
constraints are applied only to one column, whereas table level constraints are
applied to the entire table.
By default, a column can hold NULL values. If we don't enter any value in a particular
column, it will store NULL if the default value has not been specified. The NULL value
is omitted in various operations in a database. To ensure that a column does not
contain a NULL value, NOT NULL constraint is used.
NOT NULL constraint applied to a column ensures that the particular column always
contains a value, i.e., we cannot insert a new record, or update a record without
providing a value for that field.
A NULL is not the same as no data, blank, or a zero-length character string such as ‘ ’,
rather, it represents unknown data or that no data entry has been made.
For example:
CREATE TABLE E1(
Id INT NOT NULL,
Name VARCHAR(10),
Gender VARCHAR(10)
);
Page 22 of 48
KOMAL SINGH| Roll No. 2204340140035
OUTPUT:
This query will create a table Employees with fields Id, Name, and Gender. Id is
specified with NOT NULL constraint that means they cannot contain NULL value
while Name and Gender may contain NULL value.
If E1 table has already been created, then to add a NOT NULL constraint to the Id
and Name column use following syntax:
ALTER TABLE E1 MODIFY Id INT(3) NOT NULL;
OR
ALTER TABLE E1 ADD [CONSTRAINT notNullE11] NOT NULL(Id);
• UNIQUE Constraint
UNIQUE constraint ensures that all the values stored in a column are different from
each other. The UNIQUE Constraint prevents two records from having identical
values in a column, i.e., the values must not be repeated.
We can use UNIQUE constraint in a single column or multiple columns.
UNIQUE constraint allows columns to have NULL values.
For example:
CREATE TABLE E5(
Id INT,
Page 23 of 48
KOMAL SINGH| Roll No. 2204340140035
Name VARCHAR(10),
E_MAIL VARCHAR(10) UNIQUE
);
OUTPUT:
This query will create a table E5(Id, Name and E_Mail). The Id has a UNIQUE
constraint thus each row of Id field will have a different value.
If the E5 table has already been created, then to add a UNIQUE constraint to the Id
column:
ALTER TABLE E5 MODIFY Id INT(3) UNIQUE;
OR
ALTER TABLE E5 ADD [CONSTRAINT myUniqueConstraint] UNIQUE(Id);
For example:
CREATE TABLE E7(
Roll INT(3) PRIMARY KEY,
Name VARCHAR(30),
Page 24 of 48
KOMAL SINGH| Roll No. 2204340140035
AGE INT
);
OUTPUT:
This query will create a table E7(Roll, Name and Age) with Roll field as PRIMARY KEY
constraint.
To create a PRIMARY KEY constraint on the “Roll” column when E7 table already
exists, use the following SQL syntax:
ALTER TABLE E7 MODIFY Roll INT(3) PRIMARY KEY;
OR
ALTER TABLE E7 ADD [CONSTRAINT PK_Roll] PRIMARY KEY(Roll);
Foreign Key Constraint is used to link two tables. It is used to establish a relationship
between the data in two tables.
A Foreign Key is a column or a combination of columns whose values match a
Primary Key in a different table. The table containing the FOREIGN KEY is called the
child table, and the table containing the candidate key is called the parent table.
FOREIGN KEY is used to enforce referential integrity. It is used to prevent actions
that would destroy links between tables. It also prevents invalid data from being
inserted into the foreign key column, because it has to be one of the values
contained in the table it points to.
For example:
CREATE TABLE E7(
Roll INT(3) PRIMARY KEY,
Page 25 of 48
KOMAL SINGH| Roll No. 2204340140035
Name VARCHAR(30),
AGE int
);
OUTPUT:
This query creates a table E7(Roll, Name and Mail) with Mail as FOREIGN KEY which
links Employees table to Department table.
To create a FOREIGN KEY constraint on the “Mail” column when Employees table
already exists, use the following SQL syntax:
• CHECK Constraint
CHECK constraint is used to limit the value range that can be placed in a column.
Using check constraint, we can specify conditions for a field, which will be evaluated
at the time of entering the data to a column. If the condition evaluates to false, the
record violates the constraints and it will not be entered in the table.
If we define a CHECK constraint on a single column it allows only certain values for
this column.
If we define a CHECK constraint on a table it can limit the values in certain columns
based on values in other columns in the row.
For example:
CREATE TABLE F5(
ROLL INT(3) PRIMARY KEY,
Name VARCHAR(30),
AGE INT CHECK(Age >18)
);
Page 26 of 48
KOMAL SINGH| Roll No. 2204340140035
OUTPUT:
This query will create a table F5(Roll,Name and Age).CHECK Constraint has been
applied on Age field, thus at the time of entering data into the table, this constraint
will be evaluated,if it return false the data will not be entered.
To create a CHECK constraint on the Salary column when Employees table already
exists, use the following SQL syntax:
ALTER TABLE F5 ADD [CONSTRAINT CHK_Age] CHECK(Age >18);
• DEFAULT Constraint-
DEFAULT constraint is used to provide a default value for the fields of a table. That
is, if at the time of entering new records in the table if the user does not specify any
value for these fields then the default value will be assigned to them. The user needs
to define these default values.
For example:
CREATE TABLE F8(
ROLL INT(3) PRIMARY KEY,
Name VARCHAR(30),
AGE INT DEFAULT 18
);
OUTPUT:
Page 27 of 48
KOMAL SINGH| Roll No. 2204340140035
This query will create a table F8(Roll, Name, Age) with DEFAULT Constraint applied
to Age field, thus if no value is entered into Salary field, it will automatically store
the default value i.e. 18.
To create a DEFAULT constraint on the Age column when F8 table already exists, use
the following SQL syntax:
ALTER TABLE F8 ADD CONSTRAINT CHK_Age DEFAULT 18 FOR Age;
OR
ALTER TABLE F8 ALTER Age SET DEFAULT 18;
Page 28 of 48
KOMAL SINGH| Roll No. 2204340140035
What is an ER Diagram?
The following diagram showcases two entities - Student and Course, and their
relationship. The relationship described between student and course is many-to-
Page 29 of 48
KOMAL SINGH| Roll No. 2204340140035
many, as a course can be opted by several students, and a student can opt for more
than one course. Student entity possesses attributes - Stu_Id, Stu_Name & Stu_Age.
The course entity has attributes such as Cou_ID & Cou_Name.
What is an ER Model?
An Entity-Relationship Model represents the structure of the database with the help
of a diagram. ER Modelling is a systematic process to design a database as it would
require you to analyze all data requirements before implementing your database.
• ER Diagram helps you conceptualize the database and lets you know which
fields need to be embedded for a particular entity
• Lines: It links attributes to entity types and entity types with other
relationship types
Page 30 of 48
KOMAL SINGH| Roll No. 2204340140035
Components of ER Diagram
You base an ER Diagram on three basic concepts:
• Entities
• Weak Entity
• Attributes
• Key Attribute
• Composite Attribute
• Multivalued Attribute
• Derived Attribute
• Relationships
• One-to-One Relationships
• One-to-Many Relationships
• Many-to-One Relationships
• Many-to-Many Relationships
Entities
Page 31 of 48
KOMAL SINGH| Roll No. 2204340140035
Weak Entity
An entity that makes reliance over another entity is called a weak entity
You showcase the weak entity as a double rectangle in ER Diagram.
In the example below, school is a strong entity because it has a primary key attribute
- school number. Unlike school, the classroom is a weak entity because it does not
have any primary key and the room number here acts only as a discriminator.
Attribute
An attribute exhibits the properties of an entity.
You can illustrate an attribute with an oval shape in an ER diagram.
Page 32 of 48
KOMAL SINGH| Roll No. 2204340140035
Key Attribute
Composite Attribute
Multivalued Attribute
Some attributes can possess over one value, those attributes are called multivalued
attributes.
The double oval shape is used to represent a multivalued attribute.
Page 33 of 48
KOMAL SINGH| Roll No. 2204340140035
Derived Attribute
An attribute that can be derived from other attributes of the entity is known as a
derived attribute.
In the ER diagram, the dashed oval represents the derived attribute.
Relationship
Page 34 of 48
KOMAL SINGH| Roll No. 2204340140035
One-to-One Relationship
One-to-Many Relationship
When a single element of an entity is associated with more than one element of
another entity, it is called a one-to-many relationship
For example, a customer can place many orders, but an order cannot be placed by
many customers.
Many-to-One Relationship
When more than one element of an entity is related to a single element of another
entity, then it is called a many-to-one relationship.
For example, students have to opt for a single course, but a course can have many
students.
Page 35 of 48
KOMAL SINGH| Roll No. 2204340140035
Many-to-Many Relationship
When more than one element of an entity is associated with more than one element
of another entity, this is called a many-to-many relationship.
For example, you can assign an employee to many projects and a project can have
many employees.
Page 36 of 48
KOMAL SINGH| Roll No. 2204340140035
11 Aakash Mishra
22 Hritik Singh
33 Rishabh Pandey
1. Super Key
2. Primary Key
3. Candidate Key
4. Alternate Key
5. Foreign Key
Page 37 of 48
KOMAL SINGH| Roll No. 2204340140035
6. Compound Key
7. Composite Key
8. Surrogate Key
• Super Key – A super key is a group of single or multiple keys which identifies
rows in a table.
• Primary Key – is a column or group of columns in a table that uniquely identify
every row in that table.
• Candidate Key – is a set of attributes that uniquely identify tuples in a table.
Candidate Key is a super key with no repeated attributes.
• Alternate Key – is a column or group of columns in a table that uniquely
identify every row in that table.
• 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.
• Compound Key – has two or more attributes that allow you to uniquely
recognize a specific record. It is possible that each column may not be unique
by itself within the database.
• Composite Key – is a combination of two or more columns that uniquely
identify rows in a table. The combination of columns guarantees uniqueness,
though individual uniqueness is not guaranteed.
• Surrogate Key – An artificial key which aims to uniquely identify each record is
called a surrogate key. These kind of key are unique because they are created
when you don’t have any natural primary key.
Example:
Page 38 of 48
KOMAL SINGH| Roll No. 2204340140035
Example:
In this table, StudID, Roll No, Email are qualified to become a primary key. But since
StudID is the primary key, Roll No, Email becomes the alternative key.
Page 39 of 48
KOMAL SINGH| Roll No. 2204340140035
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.
Page 40 of 48
KOMAL SINGH| Roll No. 2204340140035
Example:
DeptCode DeptName
001 Science
002 English
005 Computer
In this key in dbms example, we have two table, teach and department in a school.
However, there is no way to see which search 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.
COMPOUND KEY has two or more attributes that allow you to uniquely recognize a
specific record. It is possible that each column may not be unique by itself within the
database. However, when combined with the other column or columns the
combination of composite keys become unique. The purpose of the compound key in
database is to uniquely identify each record in the table.
Example:
Page 41 of 48
KOMAL SINGH| Roll No. 2204340140035
Page 42 of 48
KOMAL SINGH| Roll No. 2204340140035
o Primary Key never accept null o A foreign key may accept multiple null
values. values.
o You can have the single Primary o You can have multiple foreign keys in a
key in a table. table.
Page 43 of 48
KOMAL SINGH| Roll No. 2204340140035
Example:
It suggests that if two tables are separate, and the PK is the same,
• Union
you should consider putting them. together
Page 44 of 48
KOMAL SINGH| Roll No. 2204340140035
• Multivalued Dependency
• Trivial Functional Dependency
• Non-Trivial Functional Dependency
• Transitive Dependency
Example:
Car_model Maf_year Color
Page 45 of 48
KOMAL SINGH| Roll No. 2204340140035
car_model-> colour
For example:
Emp_id Emp_name
AS555 Hritik
AS811 Rishabh
AS999 Elvish
Consider this table of with two columns Emp_id and Emp_name.
Company CEO
Page 46 of 48
KOMAL SINGH| Roll No. 2204340140035
Example:
Company CEO
Alibaba Jack Ma
{Company} -> {CEO} (if we know the compay, we know its CEO’s name)
{ Company} -> {Age} should hold, that makes sense because if we know the company
name, we can know his age.
Note: You need to remember that transitive dependency can only occur in a relation
of three or more attributes.
What is Normalization?
Normalization is a method of organizing the data in the database which helps you to
avoid data redundancy, insertion, update & deletion anomaly. It is a process of
analyzing the relation schemas based on their different functional dependencies and
primary key.
Page 47 of 48
KOMAL SINGH| Roll No. 2204340140035
Page 48 of 48