Unit 1 - DBMS (Kca 204)
Unit 1 - DBMS (Kca 204)
Unit 1 - DBMS (Kca 204)
UNIT-1
Data: - Data is raw, unorganized facts that need to be processed. Data we mean
known facts that can be recorded. Data can be represented in alphabets, digits and
special characters. Data can be defined as a representation of facts, concepts, or
instructions in a formalized manner, which should be suitable for communication,
interpretation, or processing, by human or electronic machine.
Data is represented with the help of characters such as alphabets (A-Z, a-z), digits
(0-9) or special characters (+,-,/,*,<,>,= etc.)
Information: - Information is organized or classified data, which has some
meaningful values for the receiver. Information is the processed data on which
decisions and actions are based.
Database:-The collection of data, usually referred to as the database, contains
information relevant to an enterprise. A database is an organized collection of data,
generally stored and accessed electronically from a computer system.
DBMS (Database Management System)
A database is a collection of interrelated data and a set of programs to access those
data. The primary goal of a DBMS is to provide a way to store and retrieve
database information that is both convenient and efficient. A database is a
collection of related information stored ,so that it available to many users for
different purposes.
A DBMS is a software system that allows access to data contained in the database.
It objective is to provide a convenient and effective method of defining , storing
and retrieving the information contained in the database. The DBMS interfaces
with application programs so that data contained in the database can be used by
multiple application and users.
By data, we mean known facts that can be recorded and that have implicit
meaning. A database management system (DBMS) is a collection of programs that
enables users to create and maintain a database. The DBMS is a general-purpose
software system that facilitates the processes of defining, constructing,
manipulating, and sharing databases among various users and applications
Components of DBMS
The database management system can be divided into five major components, they
are:
1. Hardware
2. Software
3. Data
4. Procedures
Let's have a simple diagram to see how they all fit together to form a database
management system.
DBMS Components:
1.Hardware
When we say Hardware, we mean computer, hard disks, I/O channels for data, and
any other physical component involved before any data is successfully stored into
the memory.
When we run Oracle or MySQL on our personal computer, then our computer's
Hard Disk, our Keyboard using which we type in all the commands, our computer's
RAM, ROM all become a part of the DBMS hardware.
2. Software
This is the main component, as this is the program which controls everything. The
DBMS software is more like a wrapper around the physical database, which
provides us with an easy-to-use interface to store, access and update data.
Data is that resource, for which DBMS was designed. The motive behind the
creation of DBMS was to store and utilise data.
For example: When I store my Name in a database, the DBMS will store when
the name was stored in the database, what is the size of the name, is it stored as
related data to some other data, or is it independent, all this information is
metadata.
4. Procedures
A user can write commands in the Database Access Language and submit it to the
DBMS for execution, which is then translated and executed by the DBMS.
User can create new databases, tables, insert data, fetch stored data, update data
and delete the data using the access language.
6.Users
Database-System Applications
Databases are widely used. Here are some representative applications:
Enterprise Information
◦ Sales: For customer, product, and purchase information.
◦Accounting: For payments, receipts, account balances, assets and other accounting
information.
◦ Human resources: For information about employees, salaries, payroll taxes, and
benefits, and for generation of paychecks.
◦Manufacturing: For management of the supply chain and for tracking production
of items in factories, inventories of items in warehouses and stores, and orders for
items.
◦Online retailers: For sales data noted above plus online order tracking, generation
of recommendation lists, and maintenance of online product evaluations.
Banking and Finance
◦Banking: For customer information, accounts, loans, and banking transactions.
◦ Credit card transactions: For purchases on credit cards and generation of monthly
statements.
◦ Finance: For storing information about holdings, sales, and purchases of financial
instruments such as stocks and bonds; also for storing real-time market data to
enable online trading by customers and automated trading by the firm.
Universities: For student information, course registrations, and grades (in addition
to standard enterprise information such as human resources and accounting).
Airlines: For reservations and schedule information. Airlines were among the first
to use databases in a geographically distributed manner.
Telecommunication: For keeping records of calls made, generating monthly bills,
maintaining balances on prepaid calling cards, and storing information about the
communication networks.
Advantages of DBMS:-
1. Controlling Redundancy
In file systems each application program has its own private files. In this case, the
duplicated copies of the same data are created in many places. In DBMS, all data
of an organization is integrated into a single database file. The data is recorded in
only one place in the database and it is not duplicated.
2. Sharing of Data
In DBMS, data can be shared by authorized users of the organization. The database
administrator manages the data and gives rights to users to access the data. Many
users can be authorized to access the same piece of information simultaneously.
The remote users can also share same data. Similarly, the data of same database
can be shared between different application programs.
3. Reduction in Data Consistency
By controlling the data redundancy, the data consistency is obtained. If a data item
appears only once, any update to its value has to be performed only once and the
updated value is immediately available to all users. If the DBMS has controlled
redundancy, the database system enforces consistency.
4. Maintenance of Integration of Data
In Database management system, data in database is stored in tables. A single
database contains multiple tables and relationships can be created between tables
(or associated data entities). This makes easy to retrieve and update data.
5. Enforcement of Standards
Integrity constraints or consistency rules can be applied to database so that the
correct data can be entered into database. The constraints may be applied to data
item within a single record or the may be applied to relationships between records.
6. Improvement of Data Security
DBMS makes it easier to enforce security restriction since the data is stored
centrally. DBMS provides security tools as username and password.
Disadvantages of DBMS:-
Problems associated with centralization:-Centralization means that data is
accessible from single source. Centralized data can be accessed by each user, so
here is no security of data from unauthorized access and data can be damaged or
lost.
Cost of Hardware and Software
A processor with high speed of data processing and memory of large size is
required to run the DBMS software. It means that you have to upgrade the
hardware used for file-based system. Similarly, DBMS software is also very costly.
network network
application server
Three-Schema Architecture
OR
Types of Schemas
The goal of the three-schema architecture is to separate the user applications from
the physical database. In this architecture, schemas can be defined at
the following three levels:
1. Internal level or physical level- The internal level has an internal
schema, which describes the physical storage structure of the database. The
internal schema uses a physical data model and describes the complete
details of data storage and access paths for the database.
2. Conceptual level - The conceptual level has a conceptual schema, which
describes the structure of the whole database for a community of users. The
conceptual schema hides the details of physical storage structures and
concentrates on describing entities, data types, relationships, user operations,
and constraints. Usually, a representational data model is used to describe
the conceptual schema when a database system is implemented. This
implementation conceptual schema is often based on a conceptual schema
design in a high-level data model.
3. External level or View level -The external or view level includes a
number of external schemas or user views. Each external schema describes
the part of the database that a particular user group is interested in and hides
the rest of the database from that user group. As in the previous level, each
external schema is typically implemented using a representational data
model, possibly based on an external schema design in a high-level data
model.
Data independence
Data independence can be defined as the capacity to change the schema at one
level of a database system without having to change the schema at the next
higher level. We can define two types of data independence:
1. Logical data independence - Logical data independence is the
capacity to change the conceptual schema without having to change
external schemas or application programs. We may change the
conceptual schema to expand the database (by adding a record type or
data item), to change constraints, or to reduce the database(by removing a
record type or data item).In the last case, external schemas that refer only
to the remaining data should not be affected. Only the view definition
and the mappings need to be changed in a DBMS that supports logical
data independence.
2. Physical data independence - Physical data independence is the
capacity to change the internal schema without having to change the
conceptual schema. Hence, the external schemas need not be changed as
well. Changes to the internal schema may be needed because some
physical files were reorganized—for example, by creating additional
access structures—to improve the performance of retrieval or update. If
the same data as before remains in the database, we should not have to
change the conceptual schema.
Logica Data Independence Physical Data Independence
Logical Data Independence is mainly concerned Mainly concerned with the storage of the data.
with the structure or changing the data
definition.
You need to make changes in the Application A change in the physical level usually does not
program if new fields are added or deleted from need change at the Application program level.
the database.
Modification at the logical levels is significant Modifications made at the internal levels may
whenever the logical structures of the database or may not be needed to improve the
are changed. performance of the structure.
Database Languages
A database system provides a data definition language, which specifies the
database schema, and a data manipulation language, which expresses database
queries and updates.
1. Data-Definition Language (DDL): DDL is used to define the conceptual
schema of the database. It is a set of SQL command used to create, modify and
delete database structures but not data. These commands are normally not used
by a general user, who should be accessing the database via an application.
They are generally used by the DBA.
A data dictionary contains metadata i.e. data about data. The schema of table is
an example of metadata. A database system consults the data dictionary before
reading or modifying actual data.
2. Data-Manipulation Language (DML): Data manipulation includes retrieval
of data stored in database, insertion of new data into the database, deletion of
data from the database and modification of data stored in the database.
Data manipulation language enables users to access or manipulate data as
organized by different data model.
DMLs are of two types:
Procedural DML: It requires a user to specify what data are needed and how
to get those data.
Nonprocedural DML: It requires a user to specify what data are needed
without specifying how to get those data.
3. Data Control Language
o DCL stands for Data Control Language. It is used to retrieve the stored or
saved data. Grant and Revoke
TCL is used to run the changes made by the DML statement. TCL can be grouped
into a logical transaction.
Entity
• An entity is an object that exists and is distinguishable from other
objects. Anything about which we store information is called an
entity.
• An entity has a set of properties, and the values for some set of
properties may uniquely identify an entity.
• It includes all those things about which data is collected. An entity
may be tangible object such as student, place etc
It may be non-tangible object such as event, job title or customer
account. For instance, a person may have a person id property
whose value uniquely identifies that person
Entity Set
• It is a set of entities of the same type that share the same
properties, or attributes.
For example, a Students set may contain all the students of a
college; set of persons who are customers at given bank
Types of Entities:-
• Strong Entity Set: A strong entity is one that has a complete
identifier whose values may be used to identify its instances
uniquely.
• An entity set that has a primary key is termed a strong entity set.
• For example- The employee has an identifier EmployeeId. The
attribute name is not its full identifier because there are two
employees which have the same name.
• The Strong Entity is the one whose existence does not depend on
the existence of any other entity in a schema.
• It is denoted by a single rectangle.
• A strong entity always has the primary key in the set of attributes
that describes the strong entity.
• For Example à Loan Entity, Student Entity . These entities have
contains an attribute that has primary key.
Attributes
Entities are represented by means of their properties, called attributes. All
attributes have values. Attributes are units that describe the properties of entities.
For example, a student entity may have name, class, and age as attributes.
There exists a domain or range of values that can be assigned to attributes. For
example, a student's name cannot be a numeric value. It has to be alphabetic. A
student's age cannot be negative, etc.
Types of Attribute
Simple Attribute: Simple attributes are atomic values, which cannot be
divided further. For example, a student's phone number is an atomic value of
10 digits.
Composite Attribute: Composite attribute which can be divided into sub
parts. Composite attributes are made of more than one simple attribute. For
example, a student's complete name may have first_name and last_name.
Derived Attribute: The value for this type of attribute can be derived from
the values of other related attributes or entities. For example, age can be
derived from birth date and current date.
Thus, age is derived attribute and birth date is base attribute or stored
attribute.
Stored Attribute: The stored attribute are such attribute which are already
stored in the database. For example birth date.
Derived Attribute
Single-Value Attribute: Single-value attributes contain single value. For
example − Age, Roll_no
Multi-Valued Attribute: Multi-value attributes may contain more than one
value. For example, a person can have more than zero, one or several mobile
number, email address, etc.
Multi valued attributes are depicted by double ellipse.
Multi valued Attribute
Relationship
The association among two or more entities is called a relationship. For example,
an employee works_at a department, a student enrolls in a course. Here,
Works_at and Enrolls are called relationship. It is represented by diamond
symbol.
Mapping cardinalities express the number of entities to which another entity can
be associated via a relationship set.It may be one to one (1:1), one-to-many (1:
M), many-to-many (M: M), many-to-one (M: 1).
Relationship Set
A relationship set is a set of relationships of the same type. Like entities, a
relationship too can have attributes. These attributes are called descriptive
attributes.
Degree of Relationship
• The number of participating entities in a relationship defines the degree of
the relationship.
• Binary = degree 2
• Ternary = degree 3
• n-ary = degree
Notation for ER Diagram
Mapping Cardinality Constraints
• Express the number of entities to which another entity can be associated via
a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mapping cardinality must be one of the
following types:
• One to one
• One to many
• Many to one
• Many to many
One-to-One (1:1):-
• One-to-One (1:1):- One entity E1 is related with almost one entity E2 and
E2 is related to E1.
• For example, a person has only one passport and a passport is given to one
person.
Many-to-one:
• An entity in A is associated with at most one entity in B. An entity in B,
however, can be associated with any number (zero or more) of entities in A.
• For example – many students can study in a single college but a student
cannot study in many colleges at the same time.
Many-to-many
• An entity in A is associated with any number (zero or more) of entities in B,
and an entity in B is associated with any number (zero or more) of entities
in A.
• For example, a can be assigned to many projects and a project can be
assigned to many students.
Keys
• It is used to uniquely identify any record or row of data from the table. It is
also used to establish and identify relationships between tables.
• For example: In Student table, ID is used as a key because it is unique for
each student.
Database supports the following types of keys.
• Primary Key
• Super Key
• Candidate Key
• Alternate Key
• Composite Key
• Foreign Key
Super Key:-
• Super key is a set of one or more than one keys that can be used to uniquely
identify the record in table. A Super key for an entity is a set of one or more
attributes whose combined value uniquely identifies the entity in the entity
set. Super Key is superset of candidate key. If anyone adds additional
attributes to primary key the resulting would still identify the entity.
• Example:-
Candidate Key
• Candidate Key − A minimal super key is called a candidate key. An entity
set may have more than one candidate key.
• A Candidate key is an attribute or set of attributes that uniquely identifies a
record in a table.
• Among the set of candidate, one candidate key is chosen as Primary Key.
So a table can have multiple candidate keys but each table can have
maximum one primary key. For Example Roll_No & Student_name are
candidate keys and Roll_No is also candidate key.
• Example of Candidate key:-
Primary Key
• Primary Key − A primary key is one of the candidate keys chosen by the
database designer to uniquely identify the entity set.
• Primary key is a set of one or more fields (columns) of a table that uniquely
identify a record in table. It cannot contain Null value and duplicate value.
• A table can have only one primary key and one candidate key can select as a
primary key.
• The primary key should be chosen such that its attributes are never or rarely
changed, for example,
Alternate Key:-
• Alternate Key or Secondary Key is the key that has not been selected to be
the primary key, but are candidate keys. However, it is considered a
candidate key for the primary key.
• Alternate keys are candidate keys that are not selected as primary key.
Alternate key is also called “Secondary Key.
Example:
Composite Key:-
Composite key is a combination of more than one attributes that can be used to
uniquely identity each record. It is also known as “Compound” key. A composite
key may be a candidate or primary key.
Example:
Foreign key
• Foreign keys are the column of the table which is used to point to the
primary key of another table.
• In a company, every employee works in a specific department, and
employee and department are two different entities. So we can't store the
information of the department in the employee table. That's why we link
these two tables through the primary key of one table.
• We add the primary key of the DEPARTMENT table, Department_Id as a
new attribute in the EMPLOYEE table.
• Now in the EMPLOYEE table, Department_Id is the foreign key, and both
the tables are related.
The EER Model includes all modeling concept of ER Model and the concepts of
specialization, generalization, higher- and lower-level entity sets, attribute
inheritance, and aggregation. EER is a high-level data model that incorporates the
extensions to the ER model. Enhanced entity-relationship models, also known as
extended entity-relationship models. Enhanced ER Model is high-level models that
represent the requirements and complexities of complex databases.
Super Class
Super class is an entity type that has a relationship with one or more
subtypes.
The general entity (super class) can be sub divide into several entities
(subclass).
For example: Shape super class is having sub groups as Square, Circle, and
Triangle.
Higher- and lower-level entity sets also may be designated by the terms
super class and subclass, respectively.
2. Sub Class
Sub class is a group of entities with unique attributes. It is member of super
class.
Sub class inherits properties and attributes from its super class.
For example: Square, Circle, Triangle are the sub class of Shape super
class.
Generalization
Generalization is like a bottom-up approach in which two or more entities of
lower level combine to form a higher level entity if they have some
attributes in common.
In generalization, an entity of a higher level can also combine with the
entities of the lower level to form a further higher level entity.
Generalization is more like subclass and super class system, but the only
difference is the approach. Generalization uses the bottom-up approach.
In generalization, entities are combined to form a more generalized entity,
i.e., subclasses are combined to make a super class.
Generalization is a simple inversion of specialization.
For example, Employee and Student entities can be generalized and create a
higher level entity Person.
person
ID
name address
employee student
Generalization
salary tot_credit
instructor Secretary
rank hours_per_week
Generalization
Specialization
Specialization is a top-down approach, and it is opposite to Generalization.
In specialization, one higher level entity can be broken down into two lower
level entities.
Specialization is used to identify the subset of an entity set that shares some
distinguishing characteristics.
Normally, the super class is defined first, the subclass and its related
attributes are defined next, and relationship set are then added.
The process of designating sub groupings within an entity set is called
specialization.
Specialization
Attribute Inheritance
Inheritance is an important feature of Generalization and Specialization. It
allows lower-level entities to inherit the attributes of higher-level entities.
A lower-level entity set inherits all the attributes and relationship participation of
the higher-level entity set to which it is linked.
Aggregation
In aggregation, the relation between two entities is treated as a single entity. In
aggregation, relationship with its corresponding entities is aggregated into a higher
level entity. Aggregation is an abstraction through which relationships are treated
as higher-level entities.
• The degree of relationship can be defined as the number of occurrences in one entity that is
associated with the number of occurrences in another entity.
• There is the three degree of relationship:
One-to-one (1:1) One-to-many (1:M) Many-to-many (M:N)
1. One-to-one
• In a one-to-one relationship, one occurrence of an entity relates to only one occurrence in
another entity.
• A one-to-one relationship rarely exists in practice.
• For example: if an employee is allocated a company car then that car can only be driven by that
employee.
One-to-many
• In a one-to-many relationship, one occurrence in an entity relates to many occurrences in
another entity.
• For example: An employee works in one department, but a department has many employees.
• Therefore, department and employee have a one-to-many relationship.
Many-to-many
• In a many-to-many relationship, many occurrences in an entity relate to many occurrences in
another entity.
• Same as a one-to-one relationship, the many-to-many relationship rarely exists in practice.
• For example: At the same time, an employee can work on several projects, and a project has a
team of many employees.
• Therefore, employee and project have a many-to-many relationship.
Degree of Relationship: It is the number of entities associated in relationship.
Unary or Recursive Relationship: - It is the relationship type is between
entities in a single entity. For Example:-
Q2. Design an E-R diagram for keeping track of exploits of your favorite sports
team. You should store the matches played, the scores in each match, the players in
each match, and individual player statistics for each match. Summary statistics
should be modeled as derived attributes.
Answer:
Q3 A university registrar’s office maintains data about the following entities: (a)
courses, including number, title, credits, syllabus, and prerequisites; (b) course
offerings, including course number, year, semester, section number, instructor(s),
timings, and classroom; (c) students, including student-id, name, and program;
and (d) instructors, including identification number, name, department, and title.
Further, the enrollment of students in courses and grades awarded to students in
each course they are enrolled for must be appropriately modeled. Construct an E-
R diagram for the registrar’s office. Document all assumptions that you make
about the mapping constraints.
Solution:-
Q4. Consider a database used to record the marks that students get in different
exams of different course offerings.
a. Construct an E-R diagram that models exams as entities, and uses a ternary
relationship, for the above database.
b. Construct an alternative E-R diagram that uses only a binary relationship
between students and course-offerings. Make sure that only one relationship exists
between a particular student and course-offering pair, yet you can represent the
marks that a student gets in different exams of a course offering.
Ans 4A)
Ans: 4B)
Q5. Construct an E-R diagram for a hospital with a set of patients and a set of
medical doctors. Associate with each patient a log of the various tests and
examinations conducted.
Q6. Construct E R Diagram for ONLINE Book Store