Dbms r23 Unit-i Notes
Dbms r23 Unit-i Notes
UNIT - I
Syllabus: Introduction: Database system, Characteristics (Database Vs File System), Database Users,
Advantages of Database systems, Database applications. Brief introduction of different Data Models; Concepts
of Schema, Instance and data independence; Three tier schema architecture for data independence; Database
system structure, environment, Centralized and Client Server architecture for the database.
Entity Relationship Model: Introduction, Representation of entities, attributes, entity set, relationship,
relationship set, constraints, sub classes, super class, inheritance, specialization, generalization using ER
Diagrams.
Introduction
1.1 Database System
Data: Data is the collection of raw facts. It can be in the form of numbers, text, images, or other types of data.
Information: Processed data is the information.
Database System: The database is the collection of data that is stored in the system. It can be thought of as a
container that holds the data.
Database systems are designed to manage large bodies of information. Management of data involves both
defining structures for storage of information and providing mechanisms for the manipulation of information.
In addition, the database system must ensure the safety of the information stored, despite system crashes or
attempts at unauthorized access. If data are to be shared among several users, the system must avoid possible
anomalous results.
Database Management System (DBMS): The DBMS is the software that manages the database. It provides a
interface between the user and the database, and allows users to create, modify, and query the database.
Or
A database-management system (DBMS) is a collection of interrelated data and a set of programs to access
those data.
1.2 Characteristics (Database Vs File System):
A shared collection of logically related data along with the description of the data that suits to the needs of
large enterprises.
This unit describes the basic differences between the traditional way of processing, also called as file processing,
and the database method of processing the data. Every operating system provides users to open, save, and close
a file. The users can store appropriate information in these files. Take a look at the Figure 1.1 which shows the
traditional file processing system that stores the program and data description in a file. The related information
of a particular application is stored in various files named as File1, File2, etc., and these files are manipulated
using Program1, Program2, etc. This is the method that was used in early days.
It means that without a DBMS, the data will simply be dumped into one or more files. For any updation, the
files need to be opened and manually search for the line or record, update and then save the file. Now you can
understand the difficulties involved in marinating this type of information storage.
With the advent of database systems, the file processing approach is no longer used. Now you can observe with
the Figure 1.2 that the database is in the disk which in turn is controlled by the DBMS. In this approach the
Application Program-1 along with its data semantics, Application Program-2 along with its data semantics, etc.,
interact with the database where the actual data and constraints are stored through the DBMS. The DBMS
provides the necessary control and manipulation software modules for these application programs to access the
data stored in the database.
Drawbacks of File Processing System
1.Catalog: In DBMS, the database structure is stored in a catalog and it also contains the storage details with
constraints.
The DBMS software must equally work with any number of database applications provided the catalog contains
the structure and other details of that application. In file processing the data definition is part of the application
program.
Example: Record declaration in Pascal. Class or structure declaration in C++.
2. Program-data independence: In file processing, if changes are done in the structure of the file, then we may
require changing the program design that accesses it. In DBMS the access programs are written independent of
any specific files. This is called as program-data independence.
The DBMS stores the data in such a way that the user need not be aware of these details. This concept is called
as data abstraction and it may also be called as conceptual representation
3. Views: A database may have many users and each one may be interested on a particular view of the
application. A view is conceptually a table, but the records of this table are not stored in the database.
Example: Consider the Student database in which we can think of two views:
View 1: Students Grade in various courses. To obtain this information the tables Course and Grade_Report are
to be joined and created as a view.
View 2: If we want to know the Prerequisite Courses that a student needs to study, three tables are to be joined.
These tables are nothing but Student, Section and Prerequisite.
4. Sharing and Transaction processing: A DBMS must provide control for various users trying to access the
database.
The importance of database systems can be judged in another way—today, database system vendors like
Oracle are among the largest software companies in the world, and database systems form an important part of
the product line of Microsoft and IBM.
1.6 Brief introduction of different Data Models
Underlying the structure of a database is the data model: a collection of conceptual tools for describing data,
data relationships, data semantics, and consistency constraints. A data model provides a way to describe the
design of a database at the physical, logical, and view levels.
There are a number of different data models that we shall cover in the text. The data models can be classified
into four different categories:
• Relational Model. The relational model uses a collection of tables to represent both data and the relationships
among those data. Each table has multiple columns, and each column has a unique name. Tables are also known
as relations. The relational model is an example of a record-based model. Record-based models are so named
because the database is structured in fixed-format records of several types. Each table contains records of a
particular type. Each record type defines a fixed number of fields, or attributes. The columns of the table
correspond to the attributes of the record type. The relational data model is the most widely used data model,
and a vast majority of current database systems are based on the relational model.
The entity-relationship (E-R) data model uses a collection 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.
Object-Based Data Model. Object-oriented programming (especiallyinJava, C++, or C#) has become the
dominant software-development methodology. This led to the development of an object-oriented data model
that can be seen as extending the E-R model with notions of encapsulation, methods (functions), and object
identity. The object-relational data model combines features of the object-oriented data model and relational
data model.
• Semistructured Data Model. The semi structured data model permits the specification of data where
individual data items of the same type may have different sets of attributes. This is in contrast to the data models
mentioned earlier, where every data item of a particular type must have the same set of attributes. The Extensible
Markup Language (XML) is widely used to represent semi structured data.
1.7 Concept of Schema
When we talk about a database, we must differentiate between the database schema, which is the logical design
of the database, and the database instance, which is a snapshot of the data in the database at a given instant in
time. The concept of a relation corresponds to the programming-language notion of a variable, while the concept
of a relation schema corresponds to the programming-language notion of type definition. In general, a relation
schema consists of a list of attributes and their corresponding domains.
In a two-tier architecture, the application resides at the client machine, where it invokes database system
functionality at the server machine through query language statements. Application program interface standards like
ODBC and JDBC are used for interaction between the client and the server.
In contrast, in a three-tier architecture, the client machine acts as merely a front end and does not contain any
direct database calls. Instead, the client end communicates with an application server, usually through a forms
interface. The application server in turn communicates with a database system to access data. The business logic
of the application, which says what actions to carry out under what conditions, is embedded in the application
server, instead of being distributed across multiple clients. Three-tier applications are more appropriate for large
applications, and for applications that run on the World Wide Web.
Entity Relationship Model
1.13 Introduction
The Entity-Relationship (ER) Model is a conceptual framework used to describe the structure of a
database in terms of entities, their attributes, and the relationships between them. It was introduced by
Peter Chen in 1976 and is commonly used in the design phase of database systems to visually represent
the data requirements and relationships before the actual database is created.
Advantages of the ER Model:
Easy to Understand: The ER model provides an intuitive and easy-to-understand view of data
relationships.
Comprehensive: It captures all essential aspects of the data model, including entities,
attributes, and relationships.
Flexible: The model can be adapted to describe complex relationships, including hierarchies and
weak entities.
Limitations:
Static Representation: The ER model captures data at a specific point in time and doesn't
represent changes or dynamics over time.
Not Suitable for Some Database Operations: Some database operations, like performance
optimization or indexing, are not covered in the ER model.
1.14 Representation of Entities
Entity: An entity is an object and it is represented by rectangle symbol.
Student College
For example: In the following ER diagram we have two entities Student and College and these two entities
have many to one relationship as many student’s study in a single college.
Student College
study
Types of Entities: An entity is classified into two types. 1. Weak Entity and 2. Strong Entity
1. Weak Entity: An entity that cannot be uniquely identified by its own attributes and relies on
the relationship with other entity is called weak entity. The weak entity is represented by a
double rectangle.
For example – a bank account cannot be uniquely identified without knowing the bank to
which the account belongs, so bank account is a weak entity.
1. Strong Entity: A strong entity is an entity that can exist independently and is uniquely
identifiable by its own attributes. It has a primary key that uniquely identifies each entity
instance.
Example: A "Student" entity in a college database, with StudentID as its primary key, is
a strong entity because it doesn’t rely on other entities for identification.
Student College
study
1.15 Attributes:
Attributes represent the properties or characteristics of an entity.
For example, for a "Student" entity, attributes might be Name, Student ID, Date of Birth, etc.
Each attribute is represented by an oval in an ER diagram, connected to its corresponding entity.
Types of attributes:
Simple Attribute (or) Key Attribute : Cannot be divided further (e.g., Age, ID).
For example, student roll number can uniquely identify
a student from a set of students. Key attribute is
represented by oval same as other attributes however
the text of key attribute is underlined.
Multi-valued Attribute: An attribute that can hold multiple values is known as multivalued
attribute. It is represented with double ovals in an ER Diagram. For example – A person can have
more than one phone numbers so the phone number attribute is multivalued. (e.g., Phone
Numbers for a person).
1.16 Entity Sets: An entity set is a group of entities that share the same properties and are used to
organize data in a database.
For example, a customer entity might have attributes like name, address, and phone number. A customer
entity set would be a group of customers with those same attributes.
Customer
name
Customer_id Customer phone
no
Customer
Relationship set:
In a Relational database, relationship sets are built
up by utilizing keys, such as primary and foreign
keys, to interface related records over distinctive
tables.
In the above ER Diagram, ‘Payment’ is the weak entity, ‘Loan Payment’ is the non-identifying
relationship and ‘Payment Number’ is the partial key. Primary Key of the Loan along with the partial key
would be used to identify the records.
Binary Relationship: A relationship among 2 entity sets. Example: A professor teaches a course
and a courseis taught by a professor.
Ternary Relationship: A relationship among 3 entity sets. Example: A professor teaches a course in so
and sosemester.
2. Cardinality: Cardinality defines the number of instances of one entity that can or must be associated
with instances of another entity in a relationship.
The main types of cardinality are:
One-to-One (1:1): Each instance of one entity is related to exactly one instance of another entity.
For example, a student has only
one identification card and an identification
card is given to one person.
One-to-Many (1:M): An instance of one entity can be related to multiple instances of
another entity. For example, a customer
can place many orders, but an order
cannot be placed by many customers.
Many-to-One (M:1): Many instances of one entity can be related to one instance of another entity.
For example, many students can involve only on one project.
For example, students have to opt for a single
course, but a course can have many students.
Many-to-Many (M:M): Instances of one entity can be related to many instances of another entity,
and vice versa. For example, students can enroll in multiple courses, and courses can have multiple
students.
For example, you can assign an employee to
many projects and a project can have many
employees.
1.16. Constraints: In Database Management Systems (DBMS), constraints are rules enforced on
the data in tables to ensure accuracy, integrity, and consistency. They define certain conditions that data
must meet when being inserted, updated, or deleted from a database. Constraints play a critical role in
maintaining data integrity across various operations in a database. Types of Constraints: There are various
types of constraints in DBMS. They are
1. Domain Integrity Constraints
2. Entity Integrity Constraints
3. Referential Integrity Constraints
4. Key Constraints
1. Domain Integrity Constraints: Domain constraints in DBMS are the set of rules which defines
what kind of data can be stored in an attribute. Domain Constraints help us to enter the data into
the table according to the particular data type. The domain constraints are
a) NOT NULL 2) CHECK.
a) NOT NULL: It is domain constraint that a column cannot have a NULL value.
Syntax: CREATE TABLE <table name> (Column1 data type NOT NULL,
Column2 data type NOT NULL,
...
Column n data type NOT NULL); Example: CREATE
TABLE customers ( ID number(6) NOT NULL,
NAME varchar2(20), NOT NULL,
AGE number(3) NOT NULL, ADDRESS
char(25),
SALARY number(10,2),
PRIMARY KEY (ID));
b) CHECK: Check is a domain constraint, it allows the data into the table only after checking the
condition.
Syntax: CREATE TABLE Table_Name(column_name data_type(size) CHECK(logical expression), ….);
Example: CREATE TABLE student(Rollno number(6) NOT NULL, Name
varchar2(20) NOT NULL, Age number(3) CHECK (Age>=18));
2. Entity Integrity Constraint: Entity integrity ensures that every table has a primary key, and that the
primary key values are unique and non-null. This ensures that every entity (record) in a table can be
uniquely identified.
Example: A table of students must have a not-null, unique StudentID for each record.
create table student(StudentID number(5) NOT NULL, name varchar2(20), marks number(3),
grade char(1), primary key(StudentID));
3. Referential Integrity Constraint: Referential integrity (Foreign Key Constraints) is maintained
using foreign key constraints, which enforce a link between two tables. A foreign key in one table
refers to a primary key in another table. This constraint ensures that records in a table cannot
reference non-existent records in another table, preventing invalid data entries.
Example: Table-1 Department and Table-2 Employee
CREATE TABLE Department (DeptID NUMBER(6) PRIMARY KEY, DeptName VARCHAR2(50) );
CREATE TABLE Employee (EmployeeID NUMBER(6) PRIMARY KEY, Name VARCHAR2(50), DeptID
NUMBER(2), FOREIGN KEY (DeptID) REFERENCES
Department(DeptID) );
4. Key Constraints: Key constraints in Database Management Systems (DBMS) ensure that data
within a table is uniquely identifiable and that the integrity of the data is maintained. Key constraints
are rules that are applied to keys, which are attributes (columns) used to identify rows (records) in a
table.
There are several types of key constraints in DBMS, and each has a specific role in maintaining data
integrity and preventing redundancy. The most common key constraints are Primary Key, Unique
Key, Foreign Key, and Composite Key.
a. Primary Key: A primary key is used in table that uniquely identifies each row/record. This
is also one type of Integrity Constraint. Primary keys must have distinct values. Null values
are not allowed in a primary key column. A table can
only have one primary key, which can be made up of one or more fields. It creates a
composite key when several fields are used as a primary key.
Syntax: Create table table_name (Column_name1 datatype NOT NULL, Column_name2 datatype,
..... Column_name n datatype, PRIMARY KEY (column_name1) ) .
Example: create table student(id number(6) not null, name varchar2(20), marks number(3),
grade varchar2(5), primary key(id));
b. Foreign key: A foreign key is used to define a column or group of columns in a relational
database table that provides a link between data in two tables. It acts as a cross-reference
between tables because it references the primary key of another table, thereby establishing a
link between them. It means, the foreign key constraint ensures that values in the foreign key
column(s) match values in the referenced primary key column(s).
Syntax:CREATE TABLE Table_Name ( col_name type(size) FOREIGN KEY(col_name)
REFERENCES table_name);
customers table
CustomerID FirstName LastName Email
orders table
c. Unique Constraint:
A unique constraint ensures that all values in a column or a set of columns are unique.
Unlike the primary key, a unique constraint allows NULL values.
Syntax
CREATE TABLE Table_name (
Column_Name1 DataType NOT NULL UNIQUE,
Column_Name2 DataType NOT NULL, Column_Name3
DataType,
.......
Column_Name N DataType);
Example:
CREATE TABLE Student_DB (S_ID number NOT NULL UNIQUE, L_Name
varchar2(255) NOT NULL, F_Name varchar2(255), Age number);
1.18. Inheritance: It refers to the ability of a subclass (or specialized entity) to inherit attributes and
relationships from a superclass (or general entity). This allows for more efficient and logical modeling of
hierarchical relationships within a database.
Superclass and Subclass:
A superclass is a general entity that holds attributes and relationships common to multiple
entities.
A subclass is a specialized entity that inherits all the attributes and relationships of the
superclass but may have additional attributes or relationships specific to itself.
Attributes Inheritance:
A subclass inherits all the attributes of the superclass, meaning the subclass automatically
includes the attributes of the superclass without redefining them.
Relationships Inheritance:
A subclass also inherits the relationships that the superclass participates in. For example, if the
superclass has a relationship with another entity, the subclass will also have the same relationship.
Types of Inheritance in DBMS: 1. Generalization and 2. Specialization.
1. Generalization: Generalization is a bottom-up approach in which two lower level entities
combine to form a higher-level entity. In generalization, the higher-level entity can also
combine with other lower level entity to make further higher-level entity.
For example, if both Car and Truck share common attributes like VehicleID, Make, and Model,
these attributes can be abstracted into a Vehicle superclass, from which both Car and Truck will
inherit.
Specialization: Specialization is the opposite of generalization. It is the process of creating a more specific
entity (subclass) from a more general one (superclass). The specialized subclass inherits the common attributes
and relationships of the superclass but can also have its own unique attributes. For example, the entity Person
can be specialized into Student and Teacher. In the diagram, the higher-level entity called Product, which
represents all products. Then, there are specialized entities for specific product categories, such as Electronics,
Clothing, and Books, with each having their own specialized attributes.