Module 1 (DBMS)
Module 1 (DBMS)
INTRODUCTION TO DATABASES
Data: Known facts that can be recorded and have an implicit meaning.
Database System: The DBMS software together with the database. Sometimes,
the applications are also included.
Typical DBMS Functionality
Define a database : In terms of data types, structures
and constraints.
Other features:
1BM14CS001 Aditya 3 WP
1BM14CS002 Bharath 3 DS
1BM14CS001 1000
1BM14CS002 1000
1BM14CS001 S
1BM14CS002 B
Main Characteristics of the Database Approach
Student_ExamFee_Details Student_Grade_Details
USN Amount USN Grade
1BM14CS001 1000 1BM14CS001 S
1BM14CS002 1000 1BM14CS002 B
Main Characteristics of the Database Approach
fp=fopen("student.txt","r");
while(fscanf(fp,"%s %s %s",USN,name,subjects)!=EOF)
{
printf("USN: %s Name: %s Subjects: %s",USN,name,subjects);
}
fp=fopen("student.txt","r");
while(fscanf(fp,"%s %s %s",USN,name,subjects)!=EOF)
{
printf("USN: %s Name: %s Subjects: %s",USN,name,subjects);
}
What will be the Output of the above program statements ?
Main Characteristics of the Database Approach
Data Abstraction:
The characteristics that allows program – data independence and
program – operation independence is called data abstraction.
A data model is used to hide storage details and present the users
with a conceptual view of the database.
End-users: they use the data for queries, reports and some of them
actually update the database content.
Economies of scale:
By consolidating data and applications across departments wasteful overlap of
resources and personnel can be avoided.
Brief History of Database Applications
The above gives rise to new research and development in incorporating new
data types, complex data structures, new operations and storage and
indexing schemes in database systems.
When not to use a DBMS
Main inhibitors (costs) of using a DBMS:
High initial investment and possible need for additional hardware.
Overhead for providing generality, security, concurrency control, recovery,
and integrity functions.
Database Schema
The description of a database. Includes descriptions of the database structure and the
constraints that should hold on the database.
Schema Diagram
A diagrammatic display of (some aspects of) a database schema.
Schema Construct
A component of the schema or an object within the schema, e.g., STUDENT, COURSE.
Database State
The actual data stored in a database at a particular moment in time. Also called
snapshot or instance or occurrence.
Three-Schema Architecture
Proposed to support DBMS characteristics of:
Program-data independence.
Pre-compiler Approach
Entity
A thing in the real world with an independent existence.
Eg: A particular person, Car, House or an Employee
Attribute
The particular property that describes the entity.
Eg: An Employee’s name, age, address, salary and job
Types of Attributes
Composite versus simple(Atomic) Attributes
Complex Attributes
For example, {Address_phone({Phone(Area_Code,
Phone_Number)}, Address(Street_Address(Number, Street,
Apartment_Number), City, Zip_Code))}
Null Values
Entity Types
A collection of entities that have the same attributes.
CAR
Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)
car1
((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black))
car2
((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))
car3
((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))
.
Entity Set .
.
Relationship Types, Relationship Sets, and
Instances
e1 r1 d1
e2 r2
e3 d2
r3
e4
r4 d3
e5
e6 r5
e7 r6
r7
Example 2…
EMPLOYEE WORKS_ON PROJECT
r9
e1
r1 p1
e2 r2
e3 p2
r3
e4
r4
e5 p3
r5
e6
e7 r6
r7
r8
Relationship Degree
The degree of a relationship type is the number of
participating entity types.
e1 2
1 r1
e2 2
1 r2
e3 2
1 r3
e4
2
e5 1
1 r4
e6
2
1
r5
e7
2
r6
(1) Supervisor Role
(2) Subordinate Role
Constraints on Relationship Types
There are two types of relationship constraints:
Cardinality ratio
The cardinality ratio for binary relationship specifies the maximum number of
relationship instances that an entity can participate in.
The possible cardinality ratio for binary relationship types are 1:1, 1:N, N:1
and M:N
Participation
The participation constraint specifies whether the existence of an entity
depends on its being related to another entity via the relationship type.
This constraint specifies the minimum number of relationship instances that
each entity can participate in.
e1 r1 d1
e2 r2
e3 d2
r3
e4
e5
. d3
e6
.
e7
.
1:N Relationship
EMPLOYEE WORKS_FOR DEPARTMENT
e1 r1 d1
e2 r2
e3 d2
r3
e4
r4 d3
e5
e6 r5
e7
r6
r7
M:N Relationship
EMPLOYEE WORKS_ON PROJECT
r9
e1 r1 p1
e2 r2
e3 p2
r3
e4
r4 p3
e5
r5
e6
e7
r6
r7
r8
Participation Constraint and Existence
Dependence
The entity types which contain key attributes of their own are called regular entity
types or strong entity types.
Entities belonging to weak entity type are identified by being related to specific entities
from another entity type in combination with one of their attribute values. This other
entity type is called as identifying entity type or owner entity type.
The relationship type that relates a weak entity type to its owner is called as
identifying relationship of the weak entity type.
The weak entity type normally has a partial key, which is the set of attributes that can
uniquely identify weak entities that are related to the same owner entity.
Example…
Example:
Suppose that a DEPENDENT entity is identified by
the dependent’s first name and birth date, and the
specific EMPLOYEE that the dependent is related to.
ENTITY TYPE
RELATIONSHIP TYPE
ATTRIBUTE
KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
E1 R E2 TOTAL PARTICIPATION OF E2 IN R
Superclasses: EMPLOYEE
ENGINEER
EMPLOYEE Subclasses: SECRETARY, ENGINEER,
TECHNICIAN TECHNICIAN,
SALARIED_EMPLOYEE,
HOURLY_EMPLOYEE
SALARIED_EMPLOYEE
HOURLY_EMPLOYEE
d
d
TypingSpeed MANAGER
TGrade EngType HOURLY_EMP
SECRETARY
EMPLOYEE Fname, Lname, SSN, Addr TypingSpeed
TECHNICIAN
Fname, Lname, SSN, Addr, TGrade
d ENGINEER
Fname, Lname, SSN, Addr, EngType
TypingSpeed EngType
TGrade
SECRETARY ENGINEER
TECHNICIAN
Example
d
d
TypingSpeed MANAGER
TGrade EngType HOURLY_EMP
Esuper
…
…
E2
E1
Example
EMPLOYEE
d
d
MANAGER HOURLY_EMP
MANAGES BELONGS_TO
PROJECT TRADE_UNION
Specialization
The specialization process allows us to do the
following:
Define a set of subclass of an entity type
subclass
Establish additional specific relationship types
MaxSpeed Tonnage
CAR Price TRUCK Price
VehicleID VehicleID
VEHICLE
NoOfPassengers d NoOfAxles
MaxSpeed
CAR TRUCK Tonnage
Generalization (cont.)
We can view {CAR, TRUCK} as a specialization of
VEHICLE
Alternatively, we can view VEHICLE as a
generalization of CAR and TRUCK
Generalization (cont.)
Generalization suppresses the difference among
several entity types, identifying their common
features, and generalize them into a single
superclass of which the original types are special
subclasses.