Chapter 2
Chapter 2
1 Adam 34 13000
2 Alex 28 15000
3 Smith 20 18000
4 John 42 19020
1 Adam 34 13000
Rows/Records/Tuples
Attributes / What is Field?
In Relational table, a column is a set of value
of a particular type.
Fields also kwon as Columns and Attributes.
The above Employee table consists of four
fields, ID, Name, Age and Salary.
For example, in Employee table, Name is a
column that represents names of employee.
Name
Adam
Alex
Smith
John
Column/ Fields/Attributes
Domain
A domain is defined as the set of all
unique values permitted for an attribute.
In a relational table a domain can have a
Single value or no (Null) value.
Database Keys
Database Keys
Keys are very important part of Relational
database. They are used to establish and identify
relation between tables.
Types:
Super Key
Candidate Key
Primary Key
Foreign Key
Super Key
Super Key is defined as a set of attributes within a
table that uniquely identifies each record within a table.
Candidate Key
A Candidate Key is a set of one or more
fields/columns that can identify a record uniquely in a
table.
Primary Key
Primary Key is a one fields/columns of a table that
uniquely identify a record in database table.
Foreign Key
Primary Key of one table become a attributes of
another table is called Foreign Key.
Super Key
Customer
Example:
Customer
Example:
Customer
Example:
Customer{ Cust_ID},
Composite Key / Compound Key
Composite Key that consists of two or more
attributes that uniquely identify an entity is called
Composite key.
Cust-ID account_no
Customer
Example:
Customer{ Cust_ID,account_no.},
Foreign Key
Foreign key represents relationship between tables.
Customer
Relationship
Account
Example:
OR
Integrity Constraints
Primary Foreign
Not Null Check Unique Reference
Key Key
1) Domain Integrity Constraints
Types:
a) NOT NULL
b) Check
a) NOT NULL
Types:
a) Primary Key
b) Unique
a) Primary Key
2) Only one primary key in the table. 2) More than one Unique key in the table.
3) Syntax 3) Syntax
create table <table_name> create table <table_name>
(column_name1 datatype(size) (column_name1 datatype(size)
constraint <constraint_name> primary constraint <constraint_name> unique,
key, column_name2 datatype(size),
column_name2 datatype(size), .
. .
column_namen datatype(size)); column_namen datatype(size));
4) Example 4)Example
create table emp eg
(id number(6) primary key, create table emp
name char(25), (id number(6) unique,
age number(2), name char(25),
sal number(7,2)); age number(2),
sal number(7,2));
3) Referential Integrity Constraints
1 Adam 34 13000
2 Alex 28 15000
3 Smith 20 18000
4 John 42 19020
Entity Name
Example
Student
Attributes
An entity is represented by a set of attributes. It
corresponds to a field in a table.
Notation
Attributes are represented by ovals and are
connected to the entity with a line in ER model.
Each oval contains the name of the attribute it
represents.
Attribute Name
Example
Student
Roll no Year
name
Student
Example
Consider the following Student table-
Student
This complete table is referred to as “Student Entity Set” and each row
represents an “entity”.
Representation as ER Diagram-
Composite Attribute :
Attribute value not atomic.
Example :
Address : House_no:City:State
Name : First Name: Middle Name: Last Name
Example
2) Single Valued and Multi Valued attribute
Single Valued
Attribute
Multi Valued
Attribute
3) Null Attributes
Null value is used when an entity does not have
a value for an attributes.
Null can also designate that an attribute is
unknown i.e missing or not known.
Roll no
Student
4) Stored and Derived Attributes
The value for the derived attribute is derived from the
other attribute.
For example 'Date of birth' of a person is a attribute. The
value for the attribute 'AGE' can be derived by
subtracting the 'Date of Birth'(DOB) from the current
date.
Stored attribute supplies a value to the related attribute.
Notation:
5) Derived Attribute:
An attribute that’s value is derived from a other
attribute.
Notation:
Relationships are represented by a diamond connected to the
related entities in ER Model.
Example
For example, ‘Enrolled in’ is a relationship
type that exists between entity type Student and
Course.
Example
Relationship Set
A set of relationships of same type is known as relationship set.
The following relationship set depicts S1 is enrolled in C2, S2 is
enrolled in C1 and S3 is enrolled in C3.
Winter-18
1) Define the term Data Model.(2M)