DBMS
DBMS
DBMS
INTRODUCTION
Data
raw facts and figures
Data Processing
performing operations on the input data to generate output.
Data are logically organized into:
1. Bits (characters)
2. Fields
3. Records
4. Files
5. Databases
What is Database?
In the early days, database applications were built directly on top of file
systems
Purpose of Database Systems
• Drawbacks of using file systems to store data:
• Data redundancy (repetition of information)
• Data Inconsistency (Multiple copies of same data not updated)
• Difficulty in accessing data
• We should know the physical details of the file before accessing (like
Location, Name, Permissions, File Format, etc.)
• Data isolation — multiple files and schema
• Integrity problems are there in traditional file system.
• Searching is difficult – No Index to the records.
Purpose of Database Systems (Cont.)
• Drawbacks of using file systems (cont.)
• Concurrent access by multiple users
• Concurrent accessed needed for performance.
• Uncontrolled concurrent accesses can lead to inconsistencies
• Example: Two people reading a balance and updating it at the same time.
• Security problems
• Hard to provide user access to some, but not all, data.
• Database systems offer solutions to all the above problems
Components of DBMS
• The DBMS software is partitioned into several modules. Each module or
component is assigned a specific operation to perform.
• Some of the functions of the DBMS are supported by operating systems (OS) to
provide basic services.
• The physical data and system catalog are stored on a physical disk. Access to the
disk is controlled primarily by OS.
• The major software modules or components of DBMS are as follows:
• Query processor
• Run time database manager
• Data Manager
Query Processor
• It is used to interpret the online user query and converts into a form capable of
being send to the data manager for execution.
• The query processor use the data dictionary to find the structure of a database.
• It is a program module that provides the interface between the database and the
application programs/queries.
• The Query Processor Components include –
• Data Definition Language(DDL) Compiler(Create, Alter[Add, Drop, Modify], Drop, Describe)
• Data Manipulation Language (DML) compiler(Insert, Update, Select)
• Query evaluation engine
Data Dictionary
• A data dictionary is a reserved space within a database which is used to store
information about the database itself.
• A data dictionary is a set of table and views which can only be read and never
altered.
• The data dictionary also defines how much space has been allocated for and / or
currently in used by all the schema objects.
• A data dictionary is used when finding information about users, objects, schema
and storage structures.
• Every time a data definition language (DDL) statement is issued, the data
dictionary becomes modified.
Data Dictionary
• A data dictionary may contain information such as:
• It provides recovery to the system which that system should be able to recover
the data after some failure.
• The buffer manager is responsible for the transfer of data between the
main memory and secondary storage (such as disk or tape). It is also referred as
the cache manger.
INSTANCE & SCHEMA
• Databases change over time as information is inserted and deleted.
• The collection of information stored in the database at a particular
moment is called an instance of the database.
• The overall design of the database is called the database schema.
• Database systems have several schemas, partitioned according to the
levels of abstraction.
• The physical schema describes the database design at the physical
level, while the logical schema describes the database design at the
logical level.
THREE LEVEL DATABASE
ARCHITECTURE
• Data are actually stored as bits, or numbers and strings, but
it is difficult to work with data at this level.
A database model defines the logical design of data. The model also
describes the relationships between different parts of the data. In the
history of database design, three models have been in use: the
hierarchical model, the network model and the relational model.
Data Models
• A model is a representation of reality, ‘real world’ objects and
events and their associations.
• A model is a collection of tools for describing
• Data
• Data relationships
• Data semantics
• Data constraints
• Various models falls into three different categories:
• Object-based data models
• Record Based Data Models
• Physical Data Models
Object Based Data Models
• Use the concept of entities, attributes and relationships.
• Used to describe data at the logical and view level.
• It provides flexible structuring capabilities.
• The most widely known ones are:
• The Entity-Relationship Model
• The Object-Oriented Model.
Entity-Relationship Model
• It consists of basic objects called “Entities”, and “Relationships” among
these objects.
• An entity is a thing or object in the real world that is distinguishable
from other objects.
• Entities are described by set of attributes.
• Entities are the principal data object about which info is to be collected.
• A relationship is association among several entities.
Entity-Relationship Model
• Basic constructs of ER Model
• Entities
• Entity set (Set of entities of same type that share the same properties)
• Relationships
• Attributes (Describe the properties of entity)
• Simple Attribute
• Compound/Composite Attribute
• Derived Attribute
• Multivalued Attribute
• Degree of relationship
• No. of entities associated with the relationship (n-ary)
• Cardinality (Mapping)
Entity-Relationship Model (Cardinality)
• One to one cardinality (One student has one Address/Contact No.)
• One to many cardinality (One student registered in many courses)
(A department has many employees)
• Many to one cardinality (Many employees are working in one dept.)
• Many to Many cardinality (Employees can be assigned to more than
two projects at a time)
Entity-Relationship Model
Object Oriented Data Model
• Objects that contains the same types of values and the same methods
are grouped together into classes.
• Relational data model is the primary data model, which is used widely
around the world for data storage and processing.
• It stores data in the form of tables.
• This concept was proposed by E.F. Codd, a researcher of IBM in year
1960s.
• It uses a collection of tables to represent both data and relationship among
the data.
• Each table has multiple columns and each column has unique name.
Relational Model
Basic Terminology used in Relational
Model
• Tuple of a relation (Each row is called a tuple)
• Cardinality of a relation (No. of tuples in a relation)
• Degree of a relation (No. of attributes in a relation)
• Domain (Set of all possible values that an attribute my validly contain)
Hierarchical database model
• Disadvantages
• System complexity (Pointers)
• Operational Anomalies (Change in any record require large number of pointers
adjustments)
• Absence of structural independence.
Relational database model
In the relational model, data is organized in two-dimensional tables
called relations.
Database Languages
• DDL
• DML
• DCL
Database Constraint
Introduction
• Constraints are the rules enforced on data columns on table.
These are used to limit the type of data that can go into a
table. This ensures the accuracy and reliability of the data in
the database.
• Constraints could be column level or table level.
• Column level constraints are applied only to one column,
whereas table level constraints are applied to the whole
table.
Types of Constraints
• Following are commonly used constraints available in SQL:
• NOT NULL Constraint: Ensures that a column cannot have NULL value.
• DEFAULT Constraint: Provides a default value for a column when none is specified.
• UNIQUE Constraint: Ensures that all values in a column are different. It can be a
NULLL.
• PRIMARY Key: Uniquely identified each rows/records in a database table.
• FOREIGN Key: Uniquely identified a rows/records in any another database table.
• CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy
certain conditions.
NULL Value Constraint
• By default, a column can hold NULL values. If you do not want a column to have a
NULL value, then you need to define such constraint on this column specifying
that NULL is now not allowed for that column.
• A NULL is not the same as no data, rather, it represents unknown data.
DEFAULT constraint
• The DEFAULT constraint provides a default value to a column when
the INSERT INTO statement does not provide a specific value.
UNIQUE constraint
The UNIQUE Constraint prevents two records from having identical values in
a particular column. In the CUSTOMERS table, for example, you might want
to prevent two or more people from having identical age.
If CUSTOMERS table has already been created, then to add a UNIQUE constraint to AGE
column, you would write a statement similar to the following:
ALTER TABLE CUSTOMERS MODIFY AGE INT NOT NULL UNIQUE;
PRIMARY Constraints
• A primary key is a field in a table which uniquely identifies each row/record in a database table.
Primary keys must contain unique values. A primary key column cannot have NULL values.
• A table can have only one primary key, which may consist of single or multiple fields. When
multiple fields are used as a primary key, they are called a composite key.
• If a table has a primary key defined on any field(s), then you can not have two records having the
same value of that field(s).
Foreign Key Constraint
• A foreign key is a key used to link two tables together. This is sometimes called a
referencing key.
• Foreign Key is a column or a combination of columns whose values match a
Primary Key in a different table.
• The relationship between 2 tables matches the Primary Key in one of the tables
with a Foreign Key in the second table.
Foreign Key Constraint
CHECK Constraint
• The CHECK Constraint enables a condition to check the value being entered into a
record. If the condition evaluates to false, the record violates the constraint and
isn't entered into the table.