Lecture Note 2 (RDBMS and Keys)
Lecture Note 2 (RDBMS and Keys)
Data Model is the modelling of the data description, data semantics, and
consistency constraints of the data. It provides the conceptual tools for describing
the design of a database at each level of data abstraction. Therefore, there are
following four data models used for understanding the structure of the database.
Relational Data Model: This type of model designs the data in the form of rows
and columns within a table. Thus, a relational model uses tables for
representing data and in-between relationships. Tables are also called relations.
This model was initially described by Edgar F. Codd, in 1969. The relational
data model is the widely used model which is primarily used by commercial data
processing applications.
1|Page
Semi-structured Data Model: This type of data model is different from the other
three data models (explained above). The semi-structured data model allows the
data specifications at places where the individual data items of the same type
may have different attributes sets. The Extensible Markup Language, also known
as XML, is widely used for representing the semi
structured data. Although XML was initially designed for including the markup
information to the text document, it gains importance because of its application in
the exchange of data.
How it Works
2|Page
What is Table/Relation?
Everything in a relational database is stored in the form of relations. The RDBMS
database uses tables to store data. A table is a collection of related data entries
and contains rows and columns to store data. Each table represents some real-
world objects such as person, place, or event about which information is collected.
The organized collection of data into a relational table is known as the logical
view of the database.
Properties of a Relation
1 Ajeet 24 B.Tech
2 aryan 20 C.A
3 Mahesh 21 BCA
4 Ratan 22 MCA
5 Vimal 26 BSC
3|Page
Properties of a Row
1 Ajeet 24 B.Tech
What is a Column/Attribute?
A column is a vertical entity in the table which contains all information associated
with a specific field in a table. For example, "name" is a column in the above table
which contains all information about a student's name.
Properties of an Attribute
Ajeet
Aryan
Mahesh
4|Page
Ratan
Vimal
In the below example, the data item in the student table consists of Ajeet, 24 and
Btech, etc.
ID Name AGE COURSE
1 Ajeet 24 B.Tech
Degree
The total number of attributes that comprise a relation is known as the degree of
the table. For example, the student table has 4 attributes, and its degree is 4.
ID Name AGE COURSE
1 Ajeet 24 B.Tech
2 aryan 20 C.A
3 Mahesh 21 BCA
4 Ratan 22 MCA
5 Vimal 26 BSC
5|Page
Cardinality
The total number of tuples at any one time in a relation is known as the table's
cardinality. The relation whose cardinality is 0 is called an empty table.
For example, the student table has 5 rows, and its cardinality is 5.
ID Name AGE COURSE
1 Ajeet 24 B.Tech
2 aryan 20 C.A
3 Mahesh 21 BCA
4 Ratan 22 MCA
5 Vimal 26 BSC
Domain
The domain refers to the possible values each attribute can contain. It can be
specified using standard data types such as integers, floating numbers, etc. For
example, an attribute entitled Marital_Status may be limited to married or
unmarried values.
NULL Values
The NULL value of the table specifies that the field has been left blank during
record creation. It is different from the value filled with zero or a field that
contains space.
6|Page
Difference between DBMS and RDBMS
Although DBMS and RDBMS both are used to store information in physical
database but there are some remarkable differences between them.
No. DBMS RDBMS
4) DBMS does not apply any RDBMS defines the integrity constraint
security with regards to data for the purpose of ACID (Atomocity,
manipulation. Consistency, Isolation and Durability)
property.
5) DBMS uses file system to store in RDBMS, data values are stored in the
data, so there will be no relation form of tables, so a relationship between
between the tables. these data values will be stored in the
form of a table as well.
7|Page
8) DBMS is meant to be for small RDBMS is designed to handle large
organization and deal with small amount of data. It supports multiple
data. It supports single user. users.
After observing the differences between DBMS and RDBMS, you can say that
RDBMS is an extension of DBMS. There are many software products in the
market today who are compatible for both DBMS and RDBMS. This means,
today, a RDBMS application is DBMS application and vice-versa.
diagram shows the database objects and relationship with each other. • A
database schema is designed by the database designers to help
programmers whose software will interact with the database. The process of
database creation is called data modelling.
8|Page
Types of Schemas
The schema is pictorially represented as the following Figure. The different types
of schemas are as follows:
Physical Schema: It is a database design at the physical level. It is hidden below the
logical schema and can be changed easily without affecting the application
programs.
Logical Schema: It is a database design at the logical level. Programmers
construct applications using logical schema.
External: It is schema at view level. It is the highest level of a schema which
defines the views for end users.
9|Page
Data Independence
10 | P a g e
Physical Data Independence
DBMS Keys
• It is used to uniquely identify any record or row of data from the table. It
is also used to establish and identify relationships between tables.
For example, ID is used as a key in the Student table because it is unique for
each student. In the PERSON table, passport_number, license_number, SSN
are keys since they are unique for each person.
11 | P a g e
Primary Key
• It is the first key used to identify one and only one instance of an entity
uniquely.
• An entity can contain multiple keys, as we saw in the PERSON table. The
key which is most suitable from those lists becomes a primary key. • In the
EMPLOYEE table, ID can be the primary key since it is unique for each
employee. In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary keys since they are also unique. For each entity,
the primary key selection is based on requirements and developers.
Candidate Key
• A candidate key is an attribute or set of attributes that can uniquely identify a
tuple. Except for the primary key, the remaining attributes are
considered a candidate key. The candidate keys are as strong as the
primary key.
• For example: In the EMPLOYEE table, id is best suited for the primary key.
The rest of the attributes, like SSN, Passport_Number, License_Number,
etc., are considered a candidate key.
12 | P a g e
Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a
superset of a candidate key.
13 | P a g e
Foreign Key
• Foreign keys are the column of the table used to point to the primary key
of another table.
• Every employee works in a specific department in a company, and employee
and department are two different entities. So, we can't store the department's
information in the employee table. That's why we link these two tables
through the primary key of one table.
• We add the primary key of the DEPARTMENT table, Department_Id, as
a new attribute in the EMPLOYEE table. In the EMPLOYEE table,
Department_Id is the foreign key, and both the tables are related.
Alternate Key
• There may be one or more attributes or a combination of attributes that
uniquely identify each tuple in a relation. These attributes or combinations
of the attributes are called the candidate keys.
• One key is chosen as the primary key from these candidate keys, and the
For example, employee relation has two attributes, Employee_Id and PAN_No,
that act as candidate keys. In this relation, Employee_Id is chosen as the primary
key, so the other candidate key, PAN_No, acts as the Alternate key.
14 | P a g e
Composite Key
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.
Artificial Key
The key created using arbitrarily assigned data are known as artificial keys.
These keys are created when a primary key is large and complex and has no
relationship with many other relations. The data values of the artificial keys are
usually numbered in a serial order.
15 | P a g e
For example, the primary key, which is composed of Emp_ID, Emp_role, and
Proj_ID, is large in employee relations. So, it would be better to add a new
virtual attribute to identify each tuple in the relation uniquely.
16 | P a g e
Domain Integrity Constraints
For Example
• This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify
those rows.
• A table can contain a null value other than the primary key field.
For Example
17 | P a g e
Referential Integrity Constraints
For Example
Key Constraints
• Keys are the entity set that is used to identify an entity within its entity set
uniquely.
• An entity set can have multiple keys, but out of which one key will be the
primary key. A primary key can contain a unique value in the relational table.
For Example
18 | P a g e
Operations in Relational Model
Four basic operations are generally performed on relational database model.
These are: Insert, update, delete and select.
• Insert is used to insert data into the relation
Insert Operation
The insert operation gives values of the attribute for a new tuple which should
be inserted into a relation.
Update Operation
You can see that in the below-given relation table CustomerName= ‘Apple’ is
updated from Inactive to Active.
Delete Operation
To specify deletion, a condition on the attributes of the relation selects the
tuple to be deleted.
19 | P a g e
In the above-given example, CustomerName= “Apple” is deleted from the table.
The Delete operation could violate referential integrity if the tuple which is
deleted is referenced by foreign keys from other tuples in the same database.
Select Operation
rows and columns are quite natural and simple to understand • Query
capability: It makes possible for a high-level query language like SQL to avoid
complex database navigation.
20 | P a g e
• Data independence: The Structure of Relational database can be changed
without having to change any application.
• Scalable: Regarding a number of records, or rows, and the number of fields, a
database should be enlarged to enhance its usability.
21 | P a g e