DBMS Unit 1 Notes Full
DBMS Unit 1 Notes Full
The Entity-Relation data model allows us to describe the data involved in a real-
world enterprise in terms of objects and their relationships and is widely used to
(levelop an initial databa.'3e design. It provides useful concepts that allow us to
move from an informal description of what users want 1'rorn their database to a
more detailed, precise description that can be implemented in a DBMS.
The database design process can be divided into six steps. The ER model is most
relevant to the first three steps.
1. Requirements Analysis:
In other words, we must find out what the users want from the
database. This is usually an informal process that involves discussions with
user groups.
Several methodologies have been proposed for organizing and presenting the
information gathered in this step, and some automated tools have been
developed to support this process.
4. Schema Refinement:
The fourth step ill databa')e design is to analyze the collection of relations
in our relational database schema to identify potential problems, and to
refine it.
Any software project that involves a DBMS must consider aspects of the
application that go beyond the database itself. Design methodologies like
UML try to address the complete software design and development cycle.
Briefly, we must identify the entities (e.g., users, user groups, departments)
and processes involved in the application. We must describe the role of
each entity in every process that is reflected in some application task, as
part of a complete workflow for that task.
Note that entity sets need not be disjoint; the collection of toy department
employees and the collection of appliance department employees may both
contain employee John (who happens to work in both departments).
An entity is described using a set of attributes. All entities in a given entity set
have the same attributes.
For example, the Employees entity set could use name, social security number
(ssn), and parking lot (lot) as attributes. In this case we will store the name, social
security number, and lot number for each employee. However, we will not store,
say, an employee's address (or gender or age).
The Employees entity set with attributes ssn, name, and lot is shown in Figure 2.1.
An entity set is represented by a rectangle, and an attribute is represented by an
oval.
RELATIONSHIP AND RELATIONSHIP SETS
Descriptive attributes.
THE WORKS-IN RELATIONSHIP SET
A relationship can also have descriptive attributes. Descriptive attributes are used
to record information about the relationship, rather than about any one of the
participating entities;
for example, we may wish to record that RAM works in the CSE department as of
January 1991.
This information is captured in Figure by adding an attribute, since, to Works_In.
In the Works_In relationship set, for example, each Works_In relationship must
be uniquely identified by the combination of employee ssn and department dId.
Thus, for a given employee-department pair, we cannot have more than one
associated since value.
2 Instance
EMPLOYEES WORKS_IN
DEPARTMENTS
Total participation Many to Many
Total participation
Ternary Relationship :
Reports_To Relationship
The entity sets that participate in a relationship set need not be distinct;
sometimes a relationship might involve two entities in the same entity set. For
example, consider the Reports_To relationship set shown in Figure
Since employees report. to other employees, every relationship in Reports_To is
of the form (emlJ1. emp2) , where both empl and empz are entities in Employees.
However, they play different roles: ernpl reports to the managing employee
emp2, which is reflected in the role indicators supervisor and subordinate in
Figure.
If an entity set plays more than one role, the role indicator concatenated with an
attribute name from the entity set gives us a unique name for each attribute in
the relationship set. For example, the Reports_To relationship
set has attributes corresponding to the ssn of the supervisor and the ssn of the
subordinate, and the names of these attributes are supcrvisoLssn and
subordinate-ssn.
1. Key Constraints
Now consider another relationship set called Manages between the Employees
and Departments entity sets such that each department has at most one
manager, although a single employee is allowed to manage more than one
department. The restriction that each department has at most one manager is an
example of a key constraint, and it implies that each Departments entity appears
in at most one Manages relationship in any allowable instance of Manages.
This restriction is indicated in the ER diagram of Figure 2.6 by using an arrow from
Departments to Manages. Intuitively, the arrow states that given a Departments
entity, we can uniquely determine the Manages relationship in which it appears.
While this is also a potential instance for the WorksJn relationship set, the
instance of Works_In shown in Figure violates the key constraint on Manages.
EMPLOYEES MANAGES
DEPARTMENTS
Partial participation One to Many
Total participation
If we add the restriction that each employee can manage at most one department
to the Manages relationship set, which would be indicated by adding an arrow
from Employees to Manages in Figure , we have a one-to-one relationship set.
Participation Constraints
Let us say that every department is required to have a manager. This requirement
is an example of a participation constraint; the particip::ltion of the entity set
Departments in the relationship set Manages is said to be total. A participation
that is not total is said to be partial.
Weak Entity Sets
An Entity set may not have sufficient attributes to form a primary key , such an
entity set is termed as weak entity set.
An Entity set that has a primary key is termed as a strong entity set
Every weak set is to be meaningful, it must be associated with another entity set
called identifying or owner entity set.
Class Hierarchies
1. Specialization
Ex
From the above example two specialization of accounts. i.e saving account and
checking account
The high and lower level entity sets are shown as regular entity sets
From the above example account is a higher level entity , savings account
and checking accounts are the lower level enities
2 Generalization
2 What are the relationship sets and their participating entity sets? Should
we use binary or ternary relationships? Or aggregation?
For example, consider adding address information to the Employees entity set.
One option is to use an attribute address. This option is appropriate if we need to
record only one address per employee, and an address as a string.
An alternative is to create an entity set called Addresses and to record
associations between employees and addresses using a relationship (say,
Has_Address).
This more complex alternative is necessary in two situations:
case 1:
For another example of when to model a concept as an entity set rather than an
attribute, consider the relationship set (called Works:n4)
The Works_In4 Relationship Set
in that it has attributes FROM and to, instead of since. Intuitively, it records the
interval during which an employee works for a department .
The problem is that we want to record several values for the descriptive attributes
for each instance of the Works-ln2 relationship .
We can address this problem by introducing an entity set called, say, Duration,
with attributes from and to,
Entity versus Relationship
Loan Table
Loan-ID Balance
L-17 1000
L-23 1500
L-87 2000
L-26 2300
L-54 2340
an employee can own several policies, each policy can be owned by several
employees, and each dependent can be covered by several policies.
Ternary relationship
For a large enterprise, the design may require the efforts of more than one
designer and span data and application code used by a number of user groups.
The usual approach is that the requirements of various user groups are
considered, any conflicting requirements are somehow resolved, and a single set
of global requirements is generated at the end of the requirements analysis
phase.
Generating a single set of global requirements is a difficult task, but it allows the
conceptual design phase to proceed with the development of a logical schema
that spans all the data and applications throughout the enterprise.
UML, like the ER model, has the attractive feature that its constructs can be
drawn as diagrams. It encompasses a broader spectrum of the software design
process than the ER model:
I. Business Modeling:
This step corresponds to the creation of the ER design for the database. For
this purpose, UML provides many constructs that parallel the ER constructs.
UML diagrams can be used to describe the hardware configuration used for the
application.
Use case diagrams describe the actions performed by the system in response to
user requests, and the people involved in these actions.
Class diagrams are similar to ER diagrams, although they are more general in that
they are intended to model application entities (intuitively, important program
components) and their logical relationships in addition to data entities and their
relationships.
Database Users :
The main goal of a database system is to provide an environment for retrieving
information from and storing new information into the database
1 Naïve Users
These are the unsophisticated users who interact with the system by
permanent application programs that have been written previously.
2 Application Programmers
3 Sophisticated Users
4 Specialized Users
These users are the sophisticated users who write specialized database
applications
They can interact the database with the DDL and DML Statements.
These also maintain the graphics data and video and audio data.
Database Adminstrator
The Person who has such central control over the system is called
database administrator (DBA).
1. Schema definition :
The DBA creates the original database schema by executing a set
of data definition statements in the DDL
5. Routine Maintaince :
1 Periodically backing uo the database .
2 Ensure that enough free disk space is available for normal operations
and upgrading disk space is required .
3 Monitoring jobs running on the database and ensure that
performance is not degraded by very expensive tasks submitted by
some users
The database system is partitioned into modules that deal with each
of the responsibilities of the overall system.
The functional components of a database is divided into two types.
1. Storage Manager
2. Query Processor
1. Storage Manager
Transaction manager :
File Manager :
Which manages the allocation of space on disk storage and the data
structure used to represent information stored on disk.
Buffer Manager :
Which is responsible for fetching data from disk storage into main
memory and deciding what data to cache in main memory .
This is the critical part of the data base . It handles the database sizes
that are much larger than the size of main memory.
2. Query Processor
This simple tabular representation enables even novice users to understand the contents of a
database, and it permits the use of simple, high-level languages to query the data.
The main construct for representing data in the relational model is a relation.
A relation consists of a relation schema and a relation instance. The relation instance is a table,
and the relation schema describes the column heads for the table.
The schema specifies the relation's name, the name of each field (or column, or attribute), and
the domain of each field. A domain is referred to in a relation schema by the domain name and
has a set of associated values.
Students(sid: string, name: string, login: string, age: integer, gpa: real);
This says, for instance, that the field named sid has a domain named string.
The set of values associated with domain string is the set of all character strings.
An instance of a relation is a set of tuples, also called records, in which each tuple has the same
number of
fields as the relation schema. A relation instance can be thought of as a table in which each
tuple is a row, and all rows have the same number of fields.
Table contains six tuples and has, as we expect from the schema, five fields. Note that no two
rows are identical.
In practice, commercial systems allow tables to have duplicate rows.
The relational database schema is the collection of schemas for the relations in the database.
For example,
A university database with relations called Students, Faculty, Courses, Rooms, Enrolled,
Teaches.
Tuples are inserted ,using the INSERT command. We can insert a single tuple into the Students
table as follows
We can delete tuples using the DELETE command. We can delete all Students tuples with name
equal to Smith using the command:
DELETE
FROM Student
WHERE name = 'Smith'
We can modify the column values in an existing row using the UPDATE command.
For example, we can increment the age and decrement the gpa of the student with sid 53688:
UPDATE Students
SET age = age + 1, gpa = gpa - 1
WHERE sid = 53688;
The WHERE clause is applied first and determines which rows are to be modified.
The SET clause then determines how these rows are to be modified. If the column being
modified is also used to determine the new value, the value used in the expression on the right
side of equals (=) is the old value, that is, before the modification.
An integrity constraint (Ie) is a condition specified on a database schema and restricts the data
that can be stored in an instance of the database.
If a database instance satisfies all the integrity constraints specified on the database schema, it
is a legal instance.
Key Constraints
A key constraint is a statement that a certain minimal subset of the fields of a relation is a
unique identifier for a tuple.
A set of fields that uniquely identifies a tuple according to a key constraint is called a candidate
key for the relation;
Key constratints :
1. Primary key may be defined as the key which has one or more columns in a table
used uniquely to identify each row in a table.
2. Single column primary key is called as simple primary key.
3. Multi column primary key is called as composite primary key.
4. This primary key is defined in either create table statement or alter table statement
name CHAR(30),
age INTEGER,
Sometimes the information stored in a relation is linked to the information stored in another
relation. If one of the relations is modified, the other must be checked, and perhaps modified,
to keep the data consistent.
Foreign key is with reference constraints which represents the relationship between tables.
Foreign key is derived from primary key or unique key of some other table.
The table in which foreign key is defined is called a foreign table or detail table.
4.General Constraints
A program that runs against a database is called a transaction, and it can contain several
statements (queries, inserts, updates,etc.) that access the database.
By default, a constraint is checked at the end of every SQL statement that could lead to a
violation, and if there is a violation, the statement is rejected
A relational database query (query, for short) is a question about the data, and the answer
consists of a new relation containing the result. For example, we might want to find all students
younger than 18 or all students enrolled in . A query language is a specialized language for
writing queries.
SQL is the most popular commercial query language for a relational DBMS.
The symbol *, means that we retain all fields of selected tuples in the result.
6. LOGICAL DATABASE DESIGN: ER TO RELATIONAL
Entity Sets to Tables
The following SQL statement captures the preceding information, including the
domain constraints and key information:
All the available information about the Works-ln2 table is captured by the following SQL
definition:
);
Consider the ER diagram shown in Figure 3.17. We can use the key constraints
7. INTRODUCTION TO VIEWS
A view is a table whose rows are not explicitly stored in the database but are computed as
needed from a view definition.
A view in SQL is a logical subset of data from one or more tables. View is used to restrict data
access
Consider the Students and Enrolled relations. Suppose we are often interested in finding the
names and
student identifiers of students who got a grade of B in some course, together with the course
identifier. \Ne can define a view for this purpose.
Syntax for creating a View,
Example
This view can be used just like a base table, or explicitly stored table, in defining new queries or
views .
Force keyword is used while creating a view. This keyword force to create View even if the table
does not exist. After creating a force View if we create the base table and enter values in it, the
view will be automatically updated.
Update a View
A vipw can be dropped using the DROP VIEW command, which is just like DROP TABLE
ALTER TABLE modifies the structure of an existing table. To add a column called maiden-name
to Students, for example, we would use the following command: