Uploaded by Kartik Patil

DBMS Generalization

advertisement
DBMS Generalization
Generalization is a process in which the common attributes of more than one entities form a new entity. This newly
formed entity is called generalized entity.
Generalization Example
Lets say we have two entities Student and Teacher.
Attributes of Entity Student are: Name, Address & Grade
Attributes of Entity Teacher are: Name, Address & Salary
The ER diagram before generalization looks like this:
These two entities have two common attributes: Name and Address, we can make a generalized entity with these
common attributes. Lets have a look at the ER model after generalization.
The ER diagram after generalization:
We have created a new generalized entity Person and this entity has the common attributes of both the entities. As
you can see in the following ER diagram that after the generalization process the entities Student and Teacher only
has the specialized attributes Grade and Salary respectively and their common attributes (Name & Address) are now
associated with a new entity Person which is in the relationship with both the entities (Student & Teacher).
Note:
1. Generalization uses bottom-up approach where two or more lower level entities combine together to form a
higher level new entity.
2. The new generalized entity can further combine together with lower level entity to create a further higher level
generalized entity.
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 example, pigeon, house sparrow, crow and dove
can all be generalized as Birds.
Generalization is a bottom-up approach in which two lower level entities combine to form a higher level entity. In
generalization, the higher level entity can also combine with other lower level entities to make further higher level
entity.
It's more like Superclass and Subclass system, but the only difference is the approach, which is bottom-up. Hence,
entities are combined to form a more generalised entity, in other words, sub-classes are combined to form a superclass.
For example, Saving and Current account types entities can be generalised and an entity with name Account can
be created, which covers both.
Specialization
Specialization is the opposite of generalization. In specialization, a group of entities is divided into sub-groups
based on their characteristics. Take a group ‘Person’ for example. A person has name, date of birth, gender, etc.
These properties are common in all persons, human beings. But in a company, persons can be identified as
employee, employer, customer, or vendor, based on what role they play in the company.
Similarly, in a school database, persons can be specialized as teacher, student, or a staff, based on what role they
play in school as entities.
Specialization
Specialization is opposite to Generalization. It is a top-down approach in which one higher level entity can be
broken down into two lower level entity. In specialization, a higher level entity may not have any lower-level entity
sets, it's possible.
Aggregration
Aggregration is a process when relation between two entities is treated as a single entity.
In the diagram above, the relationship between Center and Course together, is acting as an Entity, which is in
relationship with another entity Visitor. Now in real world, if a Visitor or a Student visits a Coaching Center, he/she
will never enquire about the center only or just about the course, rather he/she will ask enquire about both.
Aggregation –
An ER diagram is not capable of representing relationship between an entity and a relationship which may be
required in some scenarios. In those cases, a relationship with its corresponding entities is aggregated into a higher
level entity. For Example, Employee working for a project may require some machinery. So, REQUIRE relationship
is needed between relationship WORKS_FOR and entity MACHINERY. Using aggregation, WORKS_FOR
relationship with its entities EMPLOYEE and PROJECT is aggregated into single entity and relationship REQUIRE
is created between aggregated entity and MACHINERY.
What is the Super key?
A superkey is a group of single or multiple keys which identifies rows in a table. A Super key may have additional
attributes that are not needed for unique identification.
Example:
EmpSSN
EmpNum
Empname
9812345098
AB05
Shown
9876512345
AB06
Roslyn
199937890
AB07
James
In the above-given example, EmpSSN and EmpNum name are superkeys.
What is a Primary Key?
A column or group of columns in a table which helps us to uniquely identifies every row in that table is called a
primary key. This DBMS can't be a duplicate. The same value can't appear more than once in the table.
Rules for defining Primary key:
•
•
•
•
Two rows can't have the same primary key value
It must for every row to have a primary key value.
The primary key field cannot be null.
The value in a primary key column can never be modified or updated if any foreign key refers to that
primary key.
Example:
In the following example, <code>StudID</code> is a Primary Key.
StudID
Roll No
First Name
LastName
Email
1
11
Tom
Price
abc@gmail.com
2
12
Nick
Wright
xyz@gmail.com
3
13
Dana
Natan
mno@yahoo.com
What is the Alternate key?
All the keys which are not primary key are called an alternate key. It is a candidate key which is currently not the
primary key. However, A table may have single or multiple choices for the primary key.
Example: In this table.
StudID, Roll No, Email are qualified to become a primary key. But since StudID is the primary key, Roll No, Email
becomes the alternative key.
StudID
Roll No
First Name
LastName
Email
1
11
Tom
Price
abc@gmail.com
2
12
Nick
Wright
xyz@gmail.com
3
13
Dana
Natan
mno@yahoo.com
What is a Candidate Key?
A super key with no repeated attribute is called candidate key.
The Primary key should be selected from the candidate keys. Every table must have at least a single candidate key.
Properties of Candidate key:
•
•
•
•
•
It must contain unique values
Candidate key may have multiple attributes
Must not contain null values
It should contain minimum fields to ensure uniqueness
Uniquely identify each record in a table
Example: In the given table Stud ID, Roll No, and email are candidate keys which help us to uniquely identify the
student record in the table.
StudID
Roll No
First Name
LastName
Email
1
11
Tom
Price
abc@gmail.com
2
12
Nick
Wright
xyz@gmail.com
3
13
Dana
Natan
mno@yahoo.com
What is the Foreign key?
A foreign key is a column which is added to create a relationship with another table. Foreign keys help us to
maintain data integrity and also allows navigation between two different instances of an entity. Every relationship in
the model needs to be supported by a foreign key.
What is the Compound key?
Compound key has many fields which allow you to uniquely recognize a specific record. It is possible that each
column may be not unique by itself within the database. However, when combined with the other column or
columns the combination of composite keys become unique.
Example:
OrderNo
PorductID
Product Name
Quantity
B005
JAP102459
Mouse
5
B005
DKT321573
USB
10
B005
OMG446789
LCD Monitor
20
B004
DKT321573
USB
15
B002
OMG446789
Laser Printer
3
In this example, OrderNo and ProductID can't be a primary key as it does not uniquely identify a record. However, a
compound key of Order ID and Product ID could be used as it uniquely identified each record.
What is the Composite key?
A key which has multiple attributes to uniquely identify rows in a table is called a composite key. The difference
between compound and the composite key is that any part of the compound key can be a foreign key, but the
composite key may or maybe not a part of the foreign key
Definition of Composite key: A key that has more than one attributes is known as composite key. It is also known
as compound key.
Note: Any key such as super key, primary key, candidate key etc. can be called composite key if it has more than
one attributes.
Download