Chapter 8: Database Concepts
File System
A File System is a way of organizing files into groups and folders and then
storing them in a storage device. It provides the media that stores data as
well as enables users to perform procedures such as reading, writing, and
even deleting. Files stored on a computer can be accessed directly and
searched for desired data. But to access data of a file software is required.
Limitations of File system.
(A) Difficulty in Access
it is difficult to access data in the required format and one has to
write application program to access data.
(B) Data Redundancy
Redundancy means same data are duplicated in different places
(files).
(C) Data Inconsistency
Data inconsistency occurs when same data maintained in different
places do not match.
(D) Data Isolation
There is no link or mapping between the Data present in files.
(E) Data Dependence
Data are stored in a specific format or structure in a file. If the
structure or format itself is changed, all the existing application
programs accessing that file also need to be changed. Otherwise,
the programs may not work correctly.
(F) Controlled Data Sharing
It is very difficult to enforce this kind of access control in a file
system while accessing files through application programs
[Link] Page 1
Data Base Management System(DBMS).
It is application software that can be used to create and manage
database efficiently.
It enables user or application to create, store, update, delete and
retrieve data from database itself.
It allow search and retrieve specific records from database.
It checks and ensure that only valid and accurate data is stored in
database.
Examples for DBMS software are MySQL, Oracle, SQL Server, Microsoft
Access, PostgreSQL, MongoDB.
Use of Database in Real-life Applications
[Link] Page 2
Key Concepts in DBMS
1. Database Schema: Database Schema is the design of a database. we
can also say that it is a skeleton of the database that is used to represent
the structure, types of data will be stored in the rows and columns,
constraints, relationships between the tables.
2. Data Constraints: In a database, sometimes we put some restrictions
on the table on what type of data can be stored in one or more columns of
the table, it can be done by using constraints. Constraints are defined while
we are creating a table.
3. Data dictionary or Metadata: Metadata is known as the data about the
data or we can say that the database schema along with different types of
constraints on the data is stored by DBMS in the dictionary is known as
metadata.
4. Database instance: In a database, a database instance is used to define
the complete database environment and its components or we can say that
it is a set of memory structures and background processes that are used to
access the database files.
5. Query: In a database, a query is used to access data from the database.
So users have to write queries to retrieve or manipulate data from the
database.
6. Data manipulation: In a database, we can easily manipulate data using
the three main operations that is Insertion, Deletion, and updation.
7. Data Engine: It is an underlying component that is used to create and
manage various database queries.
[Link] Page 3
Relational Data Model
A data model describes the structure of the database, including how data are
defined and represented, relationships among data, and the constraints. The
most commonly used data model is Relational Data Model.
Other types of data models are object-oriented data model, entity-
relationship data model, document model and hierarchical data model.
In relational model, tables are called relations that store data for different
columns. Each table can have multiple columns where each column name
should be unique.
Let us now understand the commonly used terminologies in relational data
model for the below STUDENT table.
1. Attribute: Attributes are the properties that define an entity. The
columns of a relation are the attributes which are also referred as fields.
Example: Regno, name, DOB, Gender are the attributes of STUDENT Table.
2. Tuple: A Tuple represents a row in a relation(table). Each tuple contains
a set of attribute values that describe a particular entity.
Example: (101, Rama, 2000-12-24, F) is a tuple in the STUDENT table
3. Degree: The number of attributes in the relation is known as the degree
of the relation.
Example: The STUDENT relation has a degree of 4, as it has 4 attributes.
[Link] Page 4
4. Cardinality: The number of tuples in a relation is known as cardinality.
Example: The STUDENT relation defined above has cardinality 6.
5. Domain: A domain is a unique set of values permitted for an attribute in
a table. The term domain refers to the current set of values found under an
attribute name.
A data type is used to specify domain for an attribute.
For example, in STUDENT relation, the attribute Regno takes integer values
and hence its domain is a set of integer values.
Three Important Properties of a Relation
In relational data model, following three properties are observed with
respect to a relation which makes a relation different from a data file or a
simple table.
Property 1: imposes following rules on an attribute of the relation.
• Each attribute in a relation has a unique name.
• Sequence of attributes in a relation is immaterial.
Property 2: governs following rules on a tuple of a relation.
• Each tuple in a relation is distinct. Each tuple of a relation must be
uniquely identified by its contents.
• Sequence of tuples in a relation is immaterial.
The tuples are not considered to be ordered, even though they appear
to be in tabular form.
[Link] Page 5
Property 3: imposes following rules on the state of a relation.
• All data values in an attribute must be from the same domain (same data
type).
• Each data value associated with an attribute must be atomic (cannot be
further divisible into meaningful subparts).
• No attribute can have many data values in one tuple.
• A special value “NULL” is used to represent values that are unknown or
non-applicable to certain attributes.
Keys in a Relational Database
The restrictions are specified to the table at the time of defining the
database through different types of keys as given below:
1. Candidate Key
A relation can have one or more attributes that takes distinct values. Any of
these attributes can be used to uniquely identify the tuples in the relation.
Such attributes are called candidate keys as each of them are candidates for
the primary key.
2. Primary Key
Uniquely identified row in a table is called Out of one or more candidate
keys, the attribute chosen by the database designer to uniquely identify the
tuples in a relation is called the primary key of that relation.
The remaining attributes in the list of candidate keys are called the alternate
keys.
3. Composite Primary Key
If no single attribute in a relation is able to uniquely distinguish the tuples,
then more than one attribute are taken together as primary key. Such
primary key consisting of more than one attribute is called Composite
Primary key.
[Link] Page 6
4. Foreign Key
A foreign key is used to represent the relationship between two relations. A
foreign key is an attribute whose value is derived from the primary key of
another relation. This means that any attribute of a relation (referencing),
which is used to refer contents from another (referenced) relation, becomes
foreign key if it refers to the primary key of referenced relation. The
referencing relation is called Foreign Relation. In some cases, foreign key
can take NULL value if it is not the part of primary key of the foreign table.
The relation in which the referenced primary key is defined is called primary
relation or master relation.
Note:
The below diagram show Primary Key and Foreign Key relationship.
*****
[Link] Page 7