DMS UNIT 2
DMS UNIT 2
DMS UNIT 2
Foreign Key:-
A FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY is
a field (or collection of fields) in one table that refers to the PRIMARY KEY in
another table. It acts as a cross-reference between tables because it references the
primary key of another table, thereby establishing a link between them.
Domain Constraint –
It is used to maintain value according to user specification For example: Not null,
check constraint.
1) Not Null: By default, all columns in tables allows null values. When a NOT
NULL Constraint is enforced on column or set of columns it will not allow null
values.
Example SQL> CREATE TABLE STUDENT (ROLL_NO NUMBER (5), NAME
VARCHAR2 (20) NOT NULL);
2) Check Constraint: The constraint defines a condition that each row must
satisfy. A single Column can have multiple check condition.
Example SQL> CREATE TABLE EMP (ID NUMBER (5), NAME VARCHAR2
(10), SAL NUMBER (10) CHECK (SAL>15000));
Entity:-
• An entity may be any object, class, person or place. In the ER diagram, an
entity can be represented as rectangles.
• Consider an organization as an example- manager, product, employee,
department etc. can be taken as an entity.
Entity set:-
• An entity set is a group of similar entities and these entities can have
attributes.
• In terms of DBMS, an entity is a table or attribute of a table in database, so by
showing relationship among tables and their attributes, ER diagram shows the
complete logical structure of a database.
Strong Entity:-
• The strong entity has a primary key or Unique key.
• Weak entities are dependent on strong entity. Its existence is not dependent on
any other entity.
• Strong Entity is represented by a single rectangle −
• example, Professor is a strong entity here, and the primary key is
Professor_ID.
Weak Entity:-
• The weak entity in DBMS do not have a primary key and are dependent on the
parent entity. It mainly depends on other entities.
• Weak Entity is represented by double rectangle −
• Continuing our previous example, Professor is a strong entity, and the primary
key is Professor_ID. However, another entity is Professor_Dependents,
which is our Weak Entity.
Attribute:-
• The attribute is used to describe the property of an entity. Eclipse is used to
represent an attribute.
• For example, id, age, contact number, name, etc. can be attributes of a student.
Types Of Attribute:-
• Key Attribute
• The key attribute is used to represent the main characteristics of an entity. It
represents a primary key. The key attribute is represented by an ellipse with the
text underlined.
•
Composite attribute:-
• An attribute that composed of many other attributes is known as a composite
attribute. The composite attribute is represented by an ellipse, and those ellipses
are connected with an ellipse.
Multivalued Attribute:-
• An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued
attribute.
• For example, a student can have more than one phone number.
Derived Attribute:-
• An attribute that can be calculated from other attribute is known as a derived
attribute. It can be represented by a dashed ellipse.
• For example, A person's age changes over time and can be derived from another
attribute like Date of birth.
Different symbols used in ER-Model are the following:
Relationship:-
• A relationship is used to describe the relation between entities. Diamond is used
to represent the relationship.
One-to-One Relationship:-
• When only one instance of an entity is associated with the relationship, then
it is known as one to one relationship.
• For example, one Department have one Manager
One-to-many relationship:-
• When only one instance of the entity on the left, and more than one instance of
an entity on the right associates with the relationship then this is known as a
one-to-many relationship.
• For example, Scientist can invent many inventions, but the invention is done by
the only specific scientist.
Many-to-one relationship:-
• When more than one instance of the entity on the left, and only one instance of
an entity on the right associates with the relationship then it is known as a
many-to-one relationship.
• For example, Student enrolls for only one course, but a course can have many
students.
Many-to-many relationship:-
• When more than one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then it is
known as a many-to-many relationship.
• For example, Employee can assign by many projects and project can have
many employees.
Functional dependency
A functional dependency occurs when one attribute in a relation uniquely
determine another attribute.
(OR)
A relation say R attribute X is functionally dependent on attribute Y if every value
in X in the relation has exactly one value of Y in the given relation.
The above relation is in 1NF as all the domains are having atomic value. But it is not in 2NF.
Benefits of denormalization
Reduce number of relations : It reduce the number of relations because it
combines two relations into one new relation.
Reduce number of foreign keys-It reduce number of foreign keys because
number of relations are reduced .
Minimizes need for joins-It minimizes need for joins because it combines many
relations into one.
Increase Performance - It increase performance of database by adding redundant
data or by grouping data.
Drawbacks of demoralization.
Slow Data Updates-It may speed up the retrieval but can slow down database
updates
Increase size of relations -It can increase size of the relations due to combining
multiple relations into one single relation.
Complex implementation -It may simplify implementation in some cases but may
make it more complex in other.
Application Specific -It is always application-specific and needs to be re-
evaluated if the application changes.
List of Advantages of Normalization are the following:
1. More efficient data structure.
2. Avoid redundant fields or columns.
3. More flexible data structure i.e. we should be able to add new rows and data
values easily
4. Better understanding of data.
5. Ensures that distinct tables exist when necessary.
6. Easier to maintain data structure i.e. it is easy to perform operations and
complex queries can be easily handled.
7. Minimizes data duplication.
8. Close modeling of real world entities, processes and their relationships.