Lecture 05
Lecture 05
and Design
CSE 4004
For each attribute there is a set of permitted values, called domain (or range) of
that attribute.
Example: a student’s name cannot be a numeric value. It has to
be alphabetic. A student’s age cannot be negative, etc. a student roll_no
can be numeric between some range like (0 - 10000)
Attributes
Attribute Types
Simple Attributes
Composite attributes
Derived Attributes
Key Attribute.
Multi-valued Attributes
Attributes
Simple Attributes
Simple attributes are those attributes which can not be divided further.
Example: student’s age
weight
Composite Attributes
A composite attribute is made up of more than one simple attribute. Can
be divided into further parts.
Example: Name – First Name, Middle Name, Last Name
Address – street name, city, country, pincode
Attributes
Composite Attributes
Attributes
Derived Attributes
Multivalued Attributes
These attributes can have set of
values for a particular entity.
Represented by double-ellipse
Entity
Relationship
Attribute
Weak Entity
Weak Entity Relationship Composite
Multivalued Attribute Attribute
Key Attribute
Relationships
Unary Relationship
Exists when there is an association with only one entity.
Example: one person is married to only one person
.
Degree of Relationship
Binary Relationship
Exists when there is an association among two entities and is the most
common relationship degree.
Example: student is enrolled in Course
Degree of Relationship
Ternary Relationship
Exists when there is an association among three entities
Example: the university might need to record which teachers taught
which subjects in which courses.
.
Degree of Relationship
N-ary Relationship
When there are n entities set participating in a relation, the
relationship is called as n-ary relationship.
.
Relationship Constraints
Cardinality Ratio
Maximum number of relationship instances that an entity can participate
in.
Possible cardinality ratios for binary relationship are 1:1, 1:N, N:1, M:N
.
Relationship Constraints
Employee 1 manages
1 Department
.
Relationship Constraints
Employee 1 Works_for
N Department
1 Employee can works_for many departments and many Department can have
maximum of 1 Employee
Relationship Constraints
Scientist 1 invents
N Invention
Scientist can invent many inventions, but the invention is done by the only
specific scientist.
Relationship Constraints
.
Relationship Constraints
Employee N Works_for
1 Department
Student
N enroll
1 Course
Student enrolls for only one course, but a course can have many students.
.
Relationship Constraints
.
Relationship Constraints
Student M studies
N Subject
Many Students can study any number of subjects and many subjects can be
studied by any number of students.
Relationship Constraints
Employee
M Is N Project
assigned
Employee can assign by many projects and project can have many
employees.
.
Relationship Constraints
.
Relationship Constraints
Participation Constraints
Specifies whether existence of an entity depends on its being related to another
entity.
.partial participation is shown using one line and the total participation is shown using
two lines.
Example
E1
E2
. D1
.
E3 . D2
.
E4 D3
E5
E1
E2
. D1
E3 . D2
.
E4 D3
E5
Employee E1 managed D1 and E4 manages D2 and E5 manages D3. this means all the
departments should have 1 manager. So the entire department set participates in the
relationship manages. Hence we have total participation.
In the employee entity set not all employees will be managers. Only E1, E4 and E5 are
managers. So this employee set participates partially in the relationship manages. Hence
it’s a partial participation
Attributes of Relationship Types
A relationship type can have attributes
Example: HoursPerWeek of Works_On
Its value for each relationship instance describes the number of hours per week that
an Employee works on a Project
hours
.
Primary Key
A primary key is a column or set of columns in a table that uniquely identifies
tuples (rows) in that table.
Keys
Primary Key
A primary key is a column or set of columns in a table that uniquely identifies
tuples (rows) in that table.
We can have license_id also as primary key
Because it is also unique.
In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are
related.
We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in the EMPLOYEE
table.
In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.
Alternate Key
There may be one or more attributes or a combination of attributes that uniquely identify
each tuple in a relation.
These attributes or combinations of the attributes are called the candidate keys.
One key is chosen as the primary key from these candidate keys, and the remaining
candidate key, if it exists, is termed the alternate key.
Primary key never accepts null A foreign key may accept multiple
values null values
You can have a single primary key in You can have multiple foreign keys in
a table a table
Tables from ER Diagrams