RDBMS Unit-2 Notes
RDBMS Unit-2 Notes
RDBMS Unit-2 Notes
(3) Logical Database Design: We must choose a DBMS to implement our database
and convert the conceptual database
design,
design into a database schema in the data model of the
chosen DBMS. We will only consider relational
DBMSs, and the task in the
therefore, logical
design step is to convert an ER schema into a relational database schema.
The result is a conceptual schema, sometimes called the logical schema, in the relational data
model.
represents
Entity
relationship
attribute
weak entity
weak entity
relationship
Multivalued
atribute
1.14. BEYOND ER DESIGN
The ER diagram is
just an approximate description of the data, constructed through
a very subjective evaluation of the
information collected during requirements analysis.
Once we have
good logical schema, we must consider performance criteria and
a
design the physical schema. Finally, we must address security issues and ensure that users are
able to access the data they need, but not data that we wish to hide from them. The
three steps of database
remaining
design are briefly described below:
(4) Schema Refinement: The fourth step in database design is to analyze the collection of
relations in our relational database schema to
identify potential problems,
(5) Physical Database Design: In this step we must consider typical expected workloads that
our database must support and further refine the database
design to ensure that it meets
desired performance criteria
(6) Security Design: In this step, we identify di erent user groups and di erent roles played
by various users (e.g., the development team for a product, the customer support
representatives, the product manager).
For each role and user group, we must identify the parts of the database that they must be
able to access and the parts of the database that they should not be allowed to access, and take
steps to ensure that they can access only the necessary parts.
Attributes
Entities are represented by means of their properties, called atributes. All attributes have
values. For example, a student entity may have name, class, age as attributes.
There exist 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 attributes
Attributes are properties of entities. Attributes are represented by means of eclipses. Every
eclipse represents one attribute and is directly connected to its entity (rectangle).
Simple attribute:
Simple attributes are atomic values, which cannot be divided further. For example,
student's phone-number is an atomic value of 10 digits.
Name
BirthDate
cent
Composite attribute:
Composite attributes are made of more than one simple attribute. For example, a
student's complete name may have first_name and last_name.
If the attributes are composite, they are further divided in a tree like structure. Every node is
then connected to its attribute. That is composite attributes are represented by eclipses that
are connected with an eclipse.
LastName
FirstNamo
Name BirthDate
Studem
R o l No.
Multi-value attribute may contain more than one values. For example, a person can
have more than one phone numbers, email_addresses etc.
Name BithDate
Student
RollLNo
PhoneNo
Derived attribute:
Derived atributes are atributes, which do not exist physical in the database, but there
values are derived from other atributes presented in the database. For example,
average salary in a department should be saved in database instead it can be derived.
For another example, age can be derived from data_of_birth.
Derived attributes are
depicted by dashed eclipse.
1.14.2. RELATIONSHIPS AND RELATIONSHIP SETS
The association
among entities is called
has relation work relationship. For example, employee entity
s_at with
department. Another example is for student who enrolls in some course.
Here, Works_at and Enrolls are called
relationship.
Relationship Set:
The number
of participating entities in an relationship defines the degree of the
relationship.
.Binary =degree 2
Ternary = degree 3
n-ary = degree
Mapping Cardinalities:
Cardinality defines the number of entities in one entity set which can be associated to the
number of entities of other set via relationship set.
One-to-one: one entity from entity set A can be associated with at most one entity of
entity setBand vice versa.
A B
one entity.
O O
A B
Many-to-one: More than one entities from entity set A can be associated with at most
entity of entity set B but one entity from entity set B can be associated with more
than one entity from entity set A.
O
O
O
O
A B
Many-to-many: one entity from A can be associated with more than one entity fromn
B and vice versa.
O
O
A B
»KeyConstraints
Participation Constraints
Weak Entities
Class Hierarchies
Aggregation
1.15.1. KEY CONSTRAINTS
There must be at least one minimal subset of attributes in the relation, which can identify a
tuple uniquely. This minimal subset of attributes is called key for that relation. If there are
more than one such minimal subsets, these are called candidate keys.
since
(name dname
Ssn lot did budget
in a relation with a key attribute, no two tuples can have identical value for key
attributes.
Works_in
since
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 (one owner, many weak entities).
Weak entity set must have total participation in this identijfying relationship set.
A n entity set that does not have a primary key is referred to as a weak entity set.
The existence ofa weak entity set depends on the existence ofa 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 Identifying relationship depicted using a double diamond
The discriminator (or partial key) of a weak entity set is the set of attributes that
distinguishes among all the entities of a weak entity set. 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.
Under line the discriminator of a weak entity set with a dashed line.
10
1.15.3.2. More Weak Entity Set Examples
modeled as a weak
In university, a course is a strong entity and a course offering can be
a
and
entity The discriminator of course_ofering would be semester (including year)
as a strong
section_number (if there is more than one section). If we model course_offering
with course
entity we would model course_number as an attribute. Then the relationship
would be implicit in the course_number attribute.
A weak entity sets is one which does not have any primary key associated with it.
Porsen
ISA
Studen Trescher
HOlINO EmED
10
Create tables for all higher level entities
Add primary keys of higher level entities in the table of lower level entities
Declare primary key of higher level table the primary key for lower level table
1.15.4.1. Generalization
As mentioned above, the process of generalizing entities, where the generalized entities
contain the properties of all the generalized entities is called Generalization. In
generalization, a number of entities are brought together into one generalized entity based on
their similar characteristics. For an example, pigeon, house sparrow, crow and dove all can be
generalized as Birds.
Birds
[Image: Generalization]
1.15.4.2. Specialization
1S A
Studet Teacher
LImage: Specialization]
1.15.4.3. Aggregation
F o r a large enterprise, the design may require the e orts of more than one
designerand span data and application code used by a number of user groups.
Using a high-level, semantic data model such as ER diagrams for conceptual design
in such an environmento ers the additional advantage that the high-level design can
be diagrammatically represented and is easily understood by the many people who
must provide input to the
design process.
An important aspect of the design process is the methodology used to structure the
development of the overall design and to ensure that the design takes into account all
user requirements and is consistent.
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 di cult 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.
Today, the relational model is by far the dominant data model and is the foundation for the
leading DBMS products, including IBM's DB2 family, Microsof's Access and SQL-Server,
FoxBase, and Paradox.
The relational model is very simple andeleganf a database is a collection of one or more
relations, where_each relation _is a table _with rows and columns, 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 major advantages of
the relational model over the older data models are its simple data representation and the ease
with which even complex queries can be expressed.
The main construct for representing data in the relational model is a relation. A
relation
consists ofa relation schema and a relation instance. The relation instance is a table, and the
relation
schema describes the column heads for the
table. We first describe the relation schema and then
the relation instance.
Field names
sid name
login age gpa
50000 Dave
dave@cs 19
3.3
$3666Jones jones@cs 18 3.4
TUPLES 53688 Samith smith@ee 18 3.2
(RECORDS, ROWS) $3650 Smith smith@math 19 3.8
53831 Madayan
madayan@music 11 1.8
53832 Quldu guldu@music 12 2.0
Figure 3.1 An Instance of the S1 of the Students Rclation
Creating and modify ing relations using SQL
Create
Insert
Update
Delete
1.17.2. INTEGRITY CONSTRAINTS QVER RELATIONS
IC: condition that must be true for any instance of the database; e.g., domain constraints
A legal instance ofa relation is one that satisfies all specified ICs.
If the DBMS checks ICs, stored data is more faithful to real-world meaning.
Candidate Key
Primary Key
Super Key
1.17.2.2. Foreign Key Constraints
10
insertion
of Students shown Figure 3.1. The following
in
Consider the instance Sl with the sid 53688,
constraint because there is already tuple
a
violates the primary key
the DBMS:
and it will be rejected by
rejected.
Enrolled rows
is deleted? The options are: Delete all
What should we do if a Students row
2.
row. Disallow the
deletion of the Students row if an
deleted Students
that refer to the some (existing) 'default' sudent,
Enrolled row refers to it. Set
the sid column to the sid of
sid CHAR(20),
cid CHAR(20),
ACTION)
ON
to a 'default' student by using
If a is deleted, we can switch the enrollment
Students row
student is specified as part of
the definition of the sid
DELETE SET DEFAULT. The default
field in Enrolled;
DEFAULT '53666'.
For example, sid CHAR(20)
default
in some situations (e.g.,
a
of a default value is appropriate
Although the specification not appropriate to
switch
supplier goes out of business), it is really
parts supplier if particular
a
this example is to
also delete all
enrollments to a student. The correct solution in
default
student (that is, CASCADE), or to reject the update.
enrollment tuples for the deleted
DELETE SET NULL.
of null as the default value by specifying ON
SQL also allows the
use
DATA:
1.19. QUERYING RELATIONAL consists of a
Data and the answer
CREATETABLEEmployees
name (ssn CHAR(I1),
Ssn
lot name CHAR(20),
lot INTEGER,
PRIMARY KEY (ssn))
Employees
Tables
Relationship Sets to
attributes of the relation must include:
In translating a relationship set to a relation,