Professional Documents
Culture Documents
CHAPTER- 7
DATABASE CONCEPTS
1
PREPARED BY:
AMRESH TIWARI, PGT (CS)
JNV
DATABASE
OR
A database is an organized collection of data
stored in a computer system and usually controlled
by a database management system (DBMS - a
software used to manage data.). 2
TYPES OF DATABASE
� Flat-file Database (Single Table - suitable for
less amount of data)
Eg. MS. Excel, OpenOffice Base, etc.
� Relational Database (Multiple Tables and the
tables are linked using a common field. -
suitable for medium to large amount of data)
Eg. MySQL, Oracle, PostgreSQL, SQL
Server, Microsoft Access, MongoDB.
3
FILE SYSTEM
6
NEED OF DBMS (CONT…)
Database reduces redundancy
Redundancy means same data are duplicated in
different places (files). It removes redundancy as the
data are stored at one place and all the application
refers to the centrally maintained database.
9
KEY CONCEPTS IN DBMS (CONT…)
Database Schema
▪ Database Schema is the design of a database.
▪ Database schema is also called the visual or logical
architecture as it tells us how the data are organised
in a database.
Data Constraint
▪ It is certain restrictions or limitations on data to
ensure its validity and consistency.
Meta-data or Data Dictionary
▪ The database schema along with various constraints
on the data is stored by DBMS in a database
catalogue or dictionary, called meta-data. 10
▪ A meta-data is data about the data.
KEY CONCEPTS IN DBMS (CONT…)
Database Instance
The state or snapshot of the database at any given
time is the database instance
Database Query
A query is a request to a database for obtaining
information in a desired way.
Data Manipulation
▪ Modification of database
▪ It consists of three operations viz. Insertion, Deletion
or Updating.
Database Engine
▪ Database engine is the underlying component or set
of programs used by a DBMS 11
RELATIONAL DATA MODEL
13
Table: collection of all Rows and Columns.
COMMONLY USED TERMINOLOGIES IN
RELATIONAL DATA MODEL
� Relation / Table
A Relation/Table is a tabular structure arranged in
rows and columns. It has the following properties:
All items in a column are homogeneous i.e. they are
of the same data type
Each column is assigned a unique name and has an
atomic(indivisible) value. 14
COMMONLY USED TERMINOLOGIES IN
RELATIONAL DATA MODEL (CONT…)
15
COMMONLY USED TERMINOLOGIES IN
RELATIONAL DATA MODEL (CONT…)
Domain
It is a set of values from which
an attribute can take a value in
each row. Usually, a data type is
used to specify domain for an
attribute.
Degree
The number of attributes in a
relation is called the Degree of
the relation
Cardinality
The number of tuples in a
relation is called the Cardinality
of the relation
16
DATABASE TABLE / RELATION
STUDENT Table/Relation
Name
Columns / Attributes
Relation
Table /
ROLL NAME CLASS
101 AMIT 10
102 SUMIT 11
Tuples
Rows /
103 RUMIT 12
5. Which of the following represents a set of rules that define valid data?
A) Constraint B) Data Dictionary C) Query D) All of the above
20
KEYS IN A RELATIONAL DATABASE
(CONT…)
� Primary Key (Unique + Not NULL)
A set of one or more attribute(s) that can
uniquely identify a record in the relation is
called Primary Key.
There can be only one primary key in a table.
A primary key accepts only distinct (non-
duplicate) values and cannot be left blank.
E.g. Student ID No, Student Admission No,
Aadhar Card No etc. qualifies as Primary Key as
the values of all these are unique.
21
KEYS IN A RELATIONAL DATABASE
(CONT…)
� Candidate Key
A table 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.
A Primary Key is one of the candidate keys.
A table may have more than one candidate keys
but definitely has one and only one primary key.
22
KEYS IN A RELATIONAL DATABASE
(CONT…)
� Candidate Key
Candidate Keys
STUDENT
Stud_ID Roll_No Name Stream Email_ID
200601 01 Nikitha Science nk@gmail.com
200607 03 Srinidhi Commerce ss@gmail.com
200647 18 Sahana Science sk@gmail.com
26
KEYS IN A RELATIONAL DATABASE
(CONT…)
In some cases, foreign key can take NULL value if
it is not the part of primary key of the foreign
table.
The table containing the foreign key is called the
child table, and the table containing the
candidate key is called the referenced or parent
table.
27
KEYS IN A RELATIONAL DATABASE
(CONT…)
ORDERS
ORDER_ID ORDER_NO CUST_ID Child
1 1255 3 Table
2 1690 3
3 1810 2
4 2210 1
CUSTOMER
Parent
CUST_ID NAME ADDRESS
Table
1 AMAR GUNTUR
2 NIKHIL VIJAYWADA
3 SHEKHAR KRISHNA
▪ From the above given tables we can observe that the CUST_ID
column of ORDERS table is deriving its value from CUST_ID of
CUSTOMER table. So we can say that the CUST_ID of ORDERS
table is a foreign key whose value is dependent upon the Primary key 28
column CUST_ID of table CUSTOMER.
29
REFERENTIAL INTEGRITY
(CONT…)
� The property of a relational database which ensures
that no entry in a foreign key column of a table can be
made unless it matches a primary key value in the
corresponding column of the related table is called
referential integrity.
� It also ensures that the user don’t accidentally delete
or change the related data.
� Referential integrity can be applied when:
▪ The master table’s column is a Primary Key or has a
unique index.
▪ The related fields have the same data type.
▪ Both tables must belong to the same database. 30
REFERENTIAL INTEGRITY
(CONT…)
The following rules must be followed if the
referential integrity is enforced using Foreign Key:-
8. All Candidate Keys are Primary Keys but all Primary Keys are not Candidate
Keys. Illustrate the statement with the help of an example. 32