You are on page 1of 32

CLASS XI

CHAPTER- 7

DATABASE CONCEPTS
1

PREPARED BY:
AMRESH TIWARI, PGT (CS)
JNV
DATABASE

 A database is a collection of interrelated data.

 It can serve multiple applications.

 It is computer based recordkeeping system.

 It not only allows to store but also allows us


modification of data as per requirements.

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

 A file can be understood as a container to store


data in a computer. Files can be stored on the
storage device of a computer system.
 Contents of a file can be texts, computer program
code, comma separated values (CSV), etc.
Likewise, pictures, audios/videos, web pages are
also files.
 Files stored on a computer can be accessed
directly and searched for desired data.
 But one has to write computer programs for
efficient access of data from files.
4
DBMS

 DBMS refers to Database Management System


 It is a software that can be used for creating,
storing, manipulating, maintaining and
retrieving data from database by users or
application programs.
 The DBMS serves as an interface between the
database and end users or application programs.
 Some examples of open source and commercial
DBMS include MySQL, Oracle, PostgreSQL,
SQL Server, Microsoft Access, MongoDB.
5
NEED OF DBMS
File system becomes difficult to handle when
number of files increases and volume of data also
grows.
Following are some of the advantages of database:-
 Database reduces redundancy
 Database controls inconsistency
 Database facilitates sharing of data
 Database ensures security
 Database maintains integrity
 Database enforces standard

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.

 Database controls inconsistency


Data inconsistency occurs when same data
maintained in different places do not match. By
controlling redundancy, the inconsistency is also
controlled.

 Database facilitates sharing of data


Data stored in the database can be shared among
several users.
7
NEED OF DBMS (CONT…)
 Database ensures security
Data are protected against accidental or
intentional disclosure to unauthorized person or
unauthorized modification.

 Database maintains integrity


It enforces certain integrity rules to ensure the
validity or correctness of data.

 Database enforces standard


Database is maintained in a standard format
which helps data interchange or migration of 8

data between two systems.


KEY CONCEPTS IN DBMS
 Database Schema
 Data Constraint
 Meta-data or Data Dictionary
 Database Instance
 Database Query
 Data Manipulation
 Database Engine

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

 In a relational database model, data is organized


into tables (i.e. rows and columns).
 These tables are also known as relations.
 A row in a table represents relationship among
a set of values.
 A column represents the field/attributes related
to relation under which information will be
stored.
 For example: If we want to store the details of
students then Roll_No, Class, Section etc. will be
the column/attributes and the collection of all 12
the column data will become a Row/Attribute.
COMPONENTS COMPRISING A
TABLE

 Data Item: smallest unit of named data. It


represent one type of information and often
referred to as a field or column information
 Attribute / Field : The columns of a relation are
the attributes which are also referred as fields.
 Tuple / Entity / Record: Collection of data items
which represent a complete unit of information.
Each row of data in a relation (table) is called a
tuple.

13
 Table: collection of all Rows and Columns.
COMMONLY USED TERMINOLOGIES IN
RELATIONAL DATA MODEL

The Relational Model was developed by E. F. Codd


of the IBM in 1970 and is the most widely used
Database 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…)

 No attribute can have many data values in one


tuple .
 All rows of a relation are distinct i.e. no two
identical rows are present in a relation.
 Ordering of rows or columns are immaterial.
 A special value “NULL” is used to represent
values that are unknown or non-applicable to
certain attributes.

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

Records Data Item 17


ASSESSMENT…
1. Repetition of data is called as ______________?
A) Data Dependency B) Data Redundancy
C) Data Inconsistency D) Data Isolation

2. A ____________ is an organized collection of data.


A) Information B) File C) Database D) DBMS

3. A ______________ is a software used to design and maintain databases.


A) Information B) File C) Database D) DBMS

4. Which of the following is a sketch of design of a planned data?


A) Instance B) Schema C) Metadata D) Relation

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

6. A relational database consists of a collection of ______________ ? 18


A) Tables B) Fields C) Records D) Keys
KEYS IN A RELATIONAL DATABASE

The tuples within a relation must be distinct. It


means no two tuples in a table should have same
value for all attributes.
That is, there should be at least one attribute in
which data are distinct (unique) and not NULL.
That way, we can uniquely distinguish each tuple
of a relation.

So, relational data model imposes some


restrictions or constraints on the values of the
attributes and how the contents of one relation be
referred through another relation. These
restrictions are specified through different types 19
of keys.
KEYS IN A RELATIONAL DATABASE
(CONT…)
� Primary Key
� Candidate Key
� Composite Primary Key
� Alternate Keys
� Foreign Key

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

 In the above given table Stud_ID, Roll_No, Email_ID


can uniquely identify a row in the table and hence
they are candidate keys.
23
KEYS IN A RELATIONAL DATABASE
(CONT…)
� 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.

CLASS SECTION TOT_STRENGTH


X A 32
XII A 30
XII B 28

 Here a composite Primary Key (CLASS, SECTION)


can be formed together as either of these column in
isolation cannot be used to uniquely identify each 24
row in the table.
KEYS IN A RELATIONAL DATABASE
(CONT…)
� Alternate Keys
 Only one of the Candidate keys is selected as the
primary key of a table. All other candidate keys
are called Alternate keys.
 A Candidate Key which is not a primary key is an
Alternate Key.
 Alternate Key(s) = Candidate Keys – Primary
Key.
 E.g. In the table STUDENT mentioned in Page
No. 18, if Stud_ID is selected as the Primary Key
then Roll_No and Email_ID will become the
Alternate Keys. 25
KEYS IN A RELATIONAL DATABASE
(CONT…)
� Foreign Key
 A foreign key is used to represent the relationship
between two tables.
 It is a non-key attribute whose value is derived
from the Primary key of another table.
 Foreign key column will check for the presence of
value in Primary key of another table, if present
then only entry will be allowed otherwise data will
be rejected.

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:-

▪ We cannot enter a value in Child Table which is


not present in Master Table’s Primary key column.
However, NULL values can be entered in foreign
key.
▪ We cannot delete a record from Master Table if
matching record exists in related table/Child
Table.
▪ We cannot modify or change the Primary Key
value in Master table if its matching record is
present in related table/Child Table. 31
ASSESSMENT…
1. A group of columns serving as a primary key are known as __________?
A) Candidate Key B) Alternate Key
C) Composite Key D) Foreign Key

2. Which of the following refers to the data about data?


A) Instance B) Schema C) Metadata D) Relation

3. The term attribute refers to a ______________ of a table.


A) Record B) Column C) Tuple D) Key

4. The term ______________ refers to a row of a table.


A) Record B) Column C) Attribute D) Key

5. The number of attributes in a relation is called as ____________ ?


A) size B) degree C) cardinality D) weight

6. The number of rows in a relation is called as ________?


A) size B) degree C) cardinality D) weigh

7. Can a relation have more than one primary key? (True/False)

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

You might also like