K Dms Chapter2
K Dms Chapter2
SuperKey :
Superkey is a set of one or more attributes which are taken collectively used to
identify uniquely an entity in the entity set.
Superkey may have extra attribute i.e if k is a superkey then any superset of k is also a super key.
Here Cust_id is a superkey. Also (Cust_id,Cust_name) is a superkey but Cust_name is not a
superkey.
Candidate Key:
The candidate key can be defined as when two or more attributes uniquely identifies an instance
of entity set. These attributes or combination of attributes are called as candidate key.
Primary key:
Within a relation there is always one attribute which has values that are unique in a relation also
not null, thus can be used to identify tuple of that relation. Such a unique identifier is called the
primary key.
E.g. 1) In the Student relation RNO is the primary key.
2) In Customer relation Cust_id is a primary key
Foreign Key:
Foreign key is a field in database table that is Primary key in another table.
It can accept multiple null, duplicate value
Consider two schemas Student and Course as follows:
Example:
alter table dept add constraint dept_deptno_pk primary key(deptno);
3) Referential integrity constraint:
It is used to establish the parent child relation between two tables having common
column. Value of foreign key is derived from primary key.
We should define the column in the parent table as a primary key and same column
in the child table as a foreign key referring to the corresponding parent key
dept={deptno, dname}
emp={empid,ename,deptno,salary
}
In table dept , deptno is a primary key containing unique values for deptnos.
To set the relationship between these two tables , we can define emp.deptno as
a foreign key as
At table creation :
1. create table dept
(deptno number(5) constraint dept_deptno_pk primary key,
dname varchar2(20));
2 Create table emp
( empid number(4),
ename varchar2(25),
deptno number(5) constraint emp_deptno_fk references dept(deptno),
salary number(10,2));
After table creation
alter table emp add constraint emp_deptno_fk foreign key(deptno)references
dept(deptno);
E-R Model
1. The Entity-Relationship model (E-R Model) is a high level conceptual model developed
by Chen in 1976 to facilitate database design. It is object based logical model
2. E-R model is based on a perception of a real world that consists of a set of basic
objects called entities and of the relationship among these objects.
3. The basic component of the model is the Entity Relationship diagram which is used to
visually represent data objects. Entities are real world objects like person, things,
organization etc. The relationship is how one entity is related with the other entity as 1:1,
1: N, M: N.
4. Main advantage of E-R model is that, once it is drawn it can be easily convert. The
constructs used in ER model can be easily be transformed into relational table.
5. This model is used by database designer to communicate the design to the end user.
ER diagram is build up of following components
Components of ER Model
Entitiy: Entity is a thing or object in the real world that is distinguishable from all other objects.
e.g. Student of a university is entity or
Customer of a bank is an entity.
Entity are represented by rectangles.
Student
Entity Set:
Entity set is a set of entities of the same type that share the same properties or attributes.
E.g. The set of all students
Attributes: Attributes are various descriptive properties possessed by an entity.
Books relation attributes are {Title, ISBN, Price}
Attributes are denoted by Ellipse
2)Composite Attributes :The attributes which can be divided into subparts are called composite
attributes.
e.g attribute name could be structured as a composite attribute consisting of
first_name,middle_name and last_name
4)Multivalued Attributes:
The attribute has set of values for a specific entity called as multi valued attribute.
e.g Phone_no is multivalued attribute because employee may have zero,one or several phone no.
5) Derived Attribute:
The value for this type of attribute can be derived from the values of other related attributes or
entities.
e.g Customer entity has attribute age and date_of_birth. We calculate age from date_of_birth
and current_date.
Here age is derived attribute and date_of_birth is base or stored attribute
6)Null Arrtibute:
An attribute takes a null value when an entity does not have a value for it. Null can indicate “not
applicable”- that is value does not exist for the entity.
e.g apartment_no
What is difference between weak entity set and strong entity set ?
(Any 4 difference points : 1 Marks each)
Ans :
It does not have sufficient attribute to The relationship between two strong entity
form a primary key on its own. set is represented by a diamond symbol
The Member of weak entity set is called The member of strong entity set is called
as subordinate entity set. as dominant entity set.
The line connecting weak entity set with The line connecting weak entity set with
the identifying relationship is double. the identifying relationship is double.
Relationship
Binary Relationship
Binary Relationship means relation between two Entities. This is further divided into three types.
1. One to One : This type of relationship is rarely seen in real world.
The above example describes that one student can enroll only for one course and a course will
also have only one Student. This is not what you will usually see in relationship.
2. One to Many : It reflects business rule that one entity is associated with many number of
same entity. For example, Student enrolls for only one Course but a Course can have many
Students.
The arrows in the diagram describes that one student can enroll for only one course.
3 Many to Many
The above diagram represents that many students can enroll for more than one courses.
Explain generalization of ER with suitable diagram.
(Explanation- 2 Marks, Diagram- 2 Marks)
1. Generalization is abstracting process of viewing set of object as a single general class.
2. It means Generalization is the result of taking union of two or more entity set to produce a
higher level entity set.
3. Generalization is a bottom-up
● Book -the set all the books in the library. Each book has a Book-id, Title, Author, Price, and
Available (y or n) as its attributes.
● Member-the set all the library members. The member is described by the attributes Member_id,
Name, Street, City, Zip_code, Mem_type, Mem_date (date of membership), Expiry_date.
● Publisher-the set of all the publishers of the books. Attributes of this entity are Pub_id, Name,
Street, City, and Zip_code.
● Supplier-the set of all the Suppliers of the books. Attributes of this entity are Sup_id, Name,
Street, City, and Zip_code.
Assumptions: a publisher publishes a book. Supplier supplies book to library. Members borrow
the book (only issue).
Return of book is not taken into account
Sketch E-R diagram for customer and loan. Assume suitable attributes.
[Correct shape 1mark, correct entity 1 Mark, correct attributes 1 Mark, proper
relationship set 1 Mark]
Cust_id Name L_no Amoun
Addres Phone