Database Management Systems - Unit 1 Material
Database Management Systems - Unit 1 Material
----------------------------------------------------------------------------------------------------------------
1. DBMS Application
3. View of DATA
7. DBMS Architecture
What Is a DBMS?
In the early days, database applications were built directly on top of file systems
Failures may leave database in an inconsistent state with partial updates carried out
Example: Transfer of funds from one account to another should either complete or not
happen at all
Example: Two people reading a balance and updating it at the same time
Security problems
Application must stage large datasets between main memory and secondary storage
(e.g., buffering, page-oriented access, 32-bit addressing, etc.)
Special code for different queries
Must protect data from inconsistency due to multiple concurrent users
Crash recovery
Security and access control
3. View of Data:
4. Data Abstraction:
Major purpose of dbms is to provide users with abstract view of data i.e. the system
hides cert ain details of how the data are stored and maintained. Since database system
users are not computer trained,developers hide the complexity from users through 3
levels of abstraction , to simplify user’s interaction with the system.
Levels of Abstraction
customer_id:string;
customer_name:string;
customer_stree:string;
customer_city : string;
end;
Summary
• Benefits include recovery from system crashes, concurrent access, quick application
Logical schema: database design at the logical level Instances and Schemas
Instance – the actual content of the database at a particular point in time alogous to the value
of a variable.
Physical Data Independence – the ability to modify the physi cal schema without
changing the logical schema .
In general, the interfaces between the various levels and components should be well defined so
6. Data Models:
Conceptual schema:
Physical schema:
Course_info(cid:string,enrollment:integer)
Data Independence:
• Language for accessing and manipulating the data organized by the appropriate data
Model.
• DML also known as query language
• Two classes of languages
Procedural – user specifies what data is required and how to get those data
Declarative (nonprocedural) – user specifies what data is required without specifying how to
get those data
branch_name char(10),
balance integer)
– Database schema
– Integrity constraints
• Domain constraints
– Authorization
– Example: Find the balances of all accounts held by the customer with customer-
Id 192-83-7465.
select account.balance
from depositor, account
where depositor.customer_id = ‘192-83-7465’ and
depositor.account_number = account.account_number
Example: Find the balances of all accounts held by the customer with customer-id 192-83-7465
select account.balance
from depositor, account
where depositor.customer_id = ‘192-83-7465’ and
depositor.account_number = account.account_number
SQL
be sent to a database.
9. Transaction Management:
database application
consistent (correct) state despite system failures (e.g., power failures and operating
– Storage management
– Query processing
– Transaction processing
Storage Management
• Storage manager is a program module that provides the interface between the low-level
data stored in the database and the application programs and queries submitted to the
system.
• Issues:
– Storage access
– File organization
Query Processing
– Equivalent expressions
• Cost difference between a good and a bad way of evaluating a query can be enormous
must maintain
expressions
11. Database Architecture:
• Centralized
• Client-server
• Distributed
Database Users
Users are differentiated by the way they expect to interact with the system
• Specialized users – write specialized database applications that do not fit into the
• Naïve users – invoke one of the permanent application programs that have been written
previously
– Examples, people accessing database over the web, bank tellers, clerical staff
Database Administrator
– Backing up data
– Database tuning.
• 1980s:
• 1990s:
• 2000s:
– What information about these entities and relationships should we store in the
database?
diagrams).
15. ER Diagrams:
• Entity: Real-world object distinguishable from other objects. An entity is described (in
– All entities in an entity set have the same set of attributes. (Until we consider
– An n-ary relationship set R relates n entity sets E1 ... En; each relationship in R
Modeling:
– a collection of entities,
• An entity set is a set of entities of the same type that share the same properties.
16. Attributes:
• Attribute types:
– Derived attributes
• Express the number of entities to which another entity can be associated via a relationship set.
• 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
Mapping Cardinalities:
Note: Some elements in A and B may not be mapped to any elements in the other set
Mapping Cardinalities
Note: Some elements in A and B may not be mapped to any elements in the other set
17. Relationships and Relationship Sets
entity sets
• {(e1, e2, … en) | e1 E1, e2 E2, …, en En}where (e1, e2, …, en) is a relationship
– Example:
• Relationship sets that involve two entity sets are binary (or degree two). Generally,
ternary relationship set between entity sets employee, job, and branch
• Relationships between more than two entity sets are rare. Most relationships are binary.
Weak Entities
• A weak entity can be identified uniquely only by considering the primary key of another
(owner) entity.
Owner entity set and weak entity set must participate in a one-to-many
Weak entity set must have total participation in this identifying relationship set.
• An entity set that does not have a primary key is referred to as a weak entity set.
• The existence of a weak entity set depends on the existence of a identifying entity set
it must relate to the identifying entity set via a total, one-to-many relationship
set from the identifying to the weak entity set
• The discriminator (or partial key) of a weak entity set is the set of attributes that
• The primary key of a weak entity set is formed by the primary key of the strong entity
set on which the weak entity set is existence dependent, plus the weak entity set’s
discriminator.
• depict a weak entity set by double rectangles.
• Note: the primary key of the strong entity set is not explicitly stored with the weak
• If loan_number were explicitly stored, payment could be made a strong entity, but then
weak entity
attribute.
Then the relationship with course would be implicit in the course_number attribute
ISA (`is a’) Hierarchies
Aggregation
• Design choices:
relationship)?
• Depends upon the use we want to make of address information, and the semantics of the
data:
• Previous example illustrated a case when two binary relationships were better than one
ternary relationship.
• An example in the other direction: a ternary relation Contracts relates entity sets Parts,
Departments and Suppliers, and has descriptive attribute qty. No combination of binary
relationships is an adequate substitute:
– S “can-supply” P, D “needs” P, and D “deals-with” S does not imply that D
– Constructs are expressive, close to the way people think about their applications.
• Basic constructs: entities, relationships, and attributes (of entities and relationships).
hierarchies. Some foreign key constraints are also implicit in the definition of a
relationship set.
ER model.
– Constraints play an important role in determining the best database design for an
enterprise.
• ER design is subjective. There are often many ways to model a given scenario!
Analyzing alternatives can be tricky, especially for a large enterprise. Common choices
include:
– Entity vs. attribute, entity vs. relationship, binary or n-ary relationship, whether
• Ensuring good database design: resulting relational schema should be analyzed and
refined further. FD information and normalization techniques are especially useful.
– Schema : specifies name of relation, plus name and type of each column.
• E.G. Students (sid: string, name: string, login: string, age: integer, gpa:
real).
• Can think of a relation as a set of rows or tuples (i.e., all rows are distinct).
• A major strength of the relational model: supports simple, powerful querying of data.
• Queries can be written intuitively, and the DBMS is responsible for efficient evaluation.
– Allows the optimizer to extensively re-order operations, and still ensure that the
• Creates the Students relation. Observe that the type of each field is specified, and
enforced by the DBMS whenever tuples are added or modified.
CREATE TABLE Students (sid: CHAR(20), name: CHAR(20), login: CHAR(10), age: INTEGER,
gpa: REAL)
• As another example, the Enrolled table holds information about courses that students
take.
• IC: condition that must be true for any instance of the database; e.g., domain constraints.
• If the DBMS checks ICs, stored data is more faithful to real-world meaning.
1. No two distinct tuples can have same values in all key fields, and
– If there’s >1 key for a relation, one of the keys is chosen (by DBA) to be the
primary key.
• E.g., sid is a key for Students. (What about name?) The set {sid, gpa} is a superkey.
Primary and Candidate Keys in SQL
• Possibly many candidate keys (specified using UNIQUE), one of which is chosen as
• Foreign key : Set of fields in one relation that is used to `refer’ to a tuple in another
relation. (Must correspond to primary key of the second relation.) Like a `logical
pointer’.
• E.g. sid is a foreign key referring to Students:
– If all foreign key constraints are enforced, referential integrity is achieved, i.e.,
no dangling references.
• Links in HTML!
• Only students listed in the Students relation should be allowed to enroll for courses.
• Consider Students and Enrolled; sid in Enrolled is a foreign key that references
Students.
(Reject it!)
– (In SQL, also: Set sid in Enrolled tuples that refer to it to a special value null,
– SET NULL / SET DEFAULT (sets foreign key value of referencing tuple)
• ICs are based upon the semantics of the real-world enterprise that is being described in
• We can check a database instance to see if an IC is violated, but we can NEVER infer
– From example, we know name is not a key, but the assertion that sid is a key is
given to us.
• Key and foreign key ICs are the most common; more general ICs supported too.
• Two mathematical Query Languages form the basis for “real” languages (e.g. SQL),
plans.
– Relational Calculus: Lets users describe what they want, rather than how to
Preliminaries
• A query is applied to relation instances, and the result of a query is also a relation
instance.
– Schemas of input relations for a query are fixed (but query will run regardless of
instance!)
– The schema for the result of a given query is also fixed! Determined by
readable.
• We’ll use positional or named field notation, assume that names of fields in query
results are `inherited’ from names of fields in query input relations.
25. Logical DB Design:
• Since each department has a unique manager, we could instead combine Manages and
Departments.
Review: Participation Constraints
• Does every department have a manager?
• A weak entity can be identified uniquely only by considering the primary key of another
(owner) entity.
– Owner entity set and weak entity set must participate in a one-to-many
relationship set (1 owner, many weak entities).
– Weak entity set must have total participation in this identifying relationship set.
Translating Weak Entity Sets
• Weak entity set and identifying relationship set are translated into a single table.
– When the owner entity is deleted, all owned weak entities must also be deleted.
Review: ISA Hierarchies
(Allowed/disallowed)
• General approach:
Hourly_Emps: Every employee is recorded in Employees. For hourly emps, extra info
recorded in Hourly_Emps (hourly_wages, hours_worked, ssn); must delete Hourly_Emps tuple
if referenced Employees tuple is deleted).
• The key constraints allow us to combine Purchaser with Policies and Beneficiary with
Dependents.
• Participation constraints lead to NOT NULL constraints.
• Views can be used to present necessary information (or a summary), while hiding
– Given YoungStudents, but not Students or Enrolled, we can find students s who
have are enrolled, but not the cid’s of the courses they are enrolled in.
• View Definition
• A relation that is not of the conceptual model but is made visible to a user as a “virtual
relation” is called a view.
• A view is defined using the create view statement which has the form
where <query expression> is any legal SQL expression. The view name is represented
by v.
• Once a view is defined, the view name can be used to refer to the virtual relation that
• Example Queries
• Uses of Views
– Consider a user who needs to know a customer’s name, loan number and branch
– Define a view
(create view cust_loan_data as
select customer_name, borrower.loan_number, branch_name
from borrower, loan
where borrower.loan_number = loan.loan_number )
– Grant the user permission to read cust_loan_data, but not borrower or loan
– Processing of Views
– the query expression is stored in the database along with the view name
– the expression is substituted into any query using the view
• View Expansion
• Let view v1 be defined by an expression e1 that may itself contain uses of view
relations.
repeat
Find any view relation vi in e1
Replace the view relation vi by the expression defining vi
until no more view relations are present in e1
• As long as the view definitions are not recursive, this loop will terminate
• With Clause
• The with clause provides a way of defining a temporary view whose definition is
• Find all branches where the total account deposit is greater than the average of the total
• Update of a View
• Create a view of all loan data in the loan relation, hiding the amount attribute
• Destroys the relation Students. The schema information and the tuples are deleted.
• Views
• A view is just a relation, but we store a definition, rather than a set of tuples.