Dbms
Dbms
Dbms
asia
LECTURE NOTES ON
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
UNIT-I
----------------------------------------------------------------------------------------------------------------
1. DBMS Application
3. View of DATA
7. DBMS Architecture
2|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
What Is a DBMS?
3|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Datasets increasing in diversity and volume. Digital libraries, interactive video, Human
Genome project, EOS project ... need for DBMS exploding
DBMS encompasses most of CS OS, languages, theory, AI, multimedia, logic
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
4|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
5|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
customer_id:string;
customer_name:string;
customer_stree:string;
customer_city : string;
end;
Summary
• Benefits include recovery from system crashes, concurrent access, quick application
6|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Example: The database consists of information about a set of customers and accounts
and the relationship between them)Analogous to type information of a variable in a
program
Physical schema: database design at the physical level
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 physical schema without
changing the logical schema .
In general, the interfaces between the various levels and components should be well defined so
6.Data Models:
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
8|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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-
9|Page
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
10 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– 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
11 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– Equivalent expressions
• Cost difference between a good and a bad way of evaluating a query can be enormous
must maintain
expressions
12 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• Centralized
• Client-server
• Distributed
13 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
14 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Database Administrator
– Backing up data
– Database tuning.
15 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 1980s:
• 1990s:
• 2000s:
– What information about these entities and relationships should we store in the
database?
16 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
17 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Pharmacy department.
– 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.
18 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
16.Attributes:
• Attribute types:
– Derived attributes
19 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• Composite 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
20 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
21 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
entity sets
• {(e1, e2, … en) | e1 E1, e2 E2, …, en En}where (e1, e2, …, en) is a relationship
– Example:
22 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• For instance, the depositor relationship set between entity sets customer and account
• 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.
23 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
24 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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
25 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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
26 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
27 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
Aggregation
28 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• Design choices:
relationship)?
• Depends upon the use we want to make of address information, and the semantics of the
data:
29 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
30 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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
31 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– 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
32 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– 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).
33 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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
34 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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.
35 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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.
36 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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!)
37 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
– (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),
38 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
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.
39 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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.
40 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
25.Logical DB Design:
41 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• Each dept has at most one manager, according to the key constraint on Manages.
• Since each department has a unique manager, we could instead combine Manages and
Departments.
42 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
43 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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.
44 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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.
45 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
(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).
46 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• The key constraints allow us to combine Purchaser with Policies and Beneficiary with
Dependents.
47 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
26.Introduction To Views:
• 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
48 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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
49 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
• 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
50 | P a g e
jntuworldupdates.org Specworld.in
Smartzworld.com Smartworld.asia
from account
select account_number
from account, max_balance
where account.balance = max_balance.value
• 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.
51 | P a g e
jntuworldupdates.org Specworld.in