module 2 DBMS
module 2 DBMS
Complex Attributes
Composite and multi-valued attributes can be nested. We can represent
such attributes by grouping the components using parenthesis () and
separated by commas (,) and displaying between curly braces {}. Such
attributes are called complex attributes
For eg if a person has more than one residence with different address
{
(housename1, place 1),(house name2,place2),…
}
Relationship types
A relationship type defines a relationship set among the entities of certain
entity types. The relationship type is illustrated in ER diagram with
diamond symbol.
Following figure shows the relationship among two entity type ‘customer’
and ‘account’
Relationship sets
Relationship set is a set of relationships of the same type. It is a collection of
relationships all belonging to one relation type
Relationship Instances
The relationship set R of particular relationship type contains a set of
relationship instances ri, Where each ri associates n individual entities
e1,e2,e3 ….
For example, in a relationship type ‘Enrolled in’, the each enrolment of a
student in a course is an instance of that relationship. Where ‘student’ and
‘course’ are entity types
Relationship instances
S2----R1---- c1
S1----R2----c3
S3-----R3---c3
S4-----R4--c3
STUDENT COURSE
ST ENROLL
ED
ED
Not all employees are the manages the department
Cardinality Ratios for binary relationship
The cardinality ratios for a binary relationship specifies the maximum
number of relationship instances that an entity can participate in.
Possible cardinality ratios for binary relationship are
1. One-to-one(1:1)
2. One-to-many(1:M)
3. Many-to-one(M:1)
4. Many-to-many(M:M)
One-to-one ( 1: 1)
An entity is associated with at most one entity is called one to one
relationship
EMPLOYEE DEPARTMENT
1 MANAGES 1
S
One employee manages one department. There will be one manager for
each department
One-to-many ( 1: 1)
An entity is associated with any number of entities
Domain
A domain D is a set of atomic values. By atomic, mean that each value in the
domain is indivisible. Domain specifies a data type. Examples of domain
include
Mob_no -- set of 10 digit phone number are valid
Names – the set of character strings
Emp-ages ---possible age of employee in a company must be between
18 and 60(example only)
Attributes
In the context of relational database, attribute is the name of the role
played by some value. Ex: name,designation etc
Definition
The domain of attribute A is denoted as dom(A).
A relation schema R, denoted by R (A1,A2…..An) is made up of a relation
name R and a list of attributes A1,A2,……An. Each attribute Ai is the name of
a role played by some domain D. Thus D is called domain of Ai denoted by
dom(Ai).The degree or arity of a relation is the number of attributes in a
relation
Tuple
One row of information in a table is called tuple, ie, one record
Table name: employee relation name
attribute
Characteristics of Relations
1. Ordering of tuples
NULL values are used to represent the values of attribute that may be
unknown or may not apply to a tuple.
4. Interpretation of a relation
1. Constraints that are inherent in the data model are called inherent
model based constraints or implicit constraints
2. Constraints that can be directly expressed in the schemas of the data
model is called schema based constraints or explicit constraints
3. Constraints that cannot be directly expressed in the schemas of the
data model and hence must be expressed and enforced by the
application programs. These are called application based or semantic
constraints or business rules
Schema based constraints include
Domain constraints
Key constraints
Entity integrity constraints
Referential integrity constraints
Domain constraints
Domain constraints specify that within each tuple, the value of each
attribute A must be an atomic value from the domain dom(A)
It specify the data types associated with domains. They include
Numeric data type for integers. Ie short integer, integer, long integer
etc
Data type for real numbers. Ie float and double
Data type for characters
Data type for fixed and variable length strings
Boolean type
Key constraints
Key constraints include key,s that are associated with the database tables.
Key’s are used to easily identify any row of data in a table
Student
roll_no Sname Phone age
1 Anu 9847123456 17
2 Anju 9895983451 18
3 Varun 9991008112 18
4 Appu 9961002345 17
1. Super key
A super key (SK) specifies a uniqueness constraints that no two
distinct tuples in any state of relation R can have the same value for
SK
Or
Super key is the combination of more than one attribute that is used
to uniquely identify every tuple in the relation
In the above table super key include
Sk = { roll_no,(roll_no,sname),phone}
A super key also have redundant attributes. Here in (roll_no, sname) ,
sname is a redundant attribute
2. Candidate key
Candidate keys are defined as the minimal set of fields which can uniquely
identify each record in the table
The value of the candidate key is unique. There can be more than one
candidate key in a relation
In the above example
Candidate key = {roll_no,phone}
The set of keys which have a chance to become the primary key are called
candidate keys
3. Primary key
There can be more than one candidate key in a relation, out of which one
can be chosen as the primary key
Primary key uniquely identifies each record in a table. It must have unique
values and cannot include NULL values
In the above example, roll_no and phone are treated as candidate keys. But
from them, roll_no is chosen as a primary key of that relation
4. Composite key
If a primary key contains two or more attributes which are used to
uniquely identify any record in a table is called composite key
5. Alternative key
The candidate key which are not selected as primary key are called
alternative keys or secondary keys
In the above example, roll_no and phone are treated as candidate keys. But
from them, roll_no is chosen as a primary key of that relation. Then the
phone attribute is called alternative key
6. Non-key attributes
The attributes of a table other than the candidate key attributes are called
non-key attributes
7. Non-prime attributes
The attributes of a table other than the primary key attribute is called non-
prime attributes