Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
ER diagram
1. NAME : MITALI MANIYAR
EN.NO.:150410107048
CLASS : SY CE-1
DEPT. : COMPUTER
Constraints, Keys,
Design issues , E-R diagrams
2. KEYS
A key is an attribute or set of attributes that uniquely identifies a tuple in a
relation/table.
Keys are used to access or sequence stored data and to create relationship between
different tables.
Types of Keys are:
1.Primary key
2.Foreign key
3.Super key
4.Candidate key
5.Unique key
3. • Primary Key – A primary is a column or set of columns in a table that uniquely
identifies tuples (rows) in that table.
• Super Key – A super key is a set of one of more columns (attributes) to uniquely
identify rows in a table.
• Candidate Key – A super key with no redundant attribute is known as candidate
key. With the help of primary key, candidate key can use to identify all other
tuples in table.
• Foreign Key – Foreign keys are the columns of a table that points to the primary
key of another table. They act as a cross-reference between tables.
• Unique Key – Unique key is a special case of primary key. It has a condition
that its value can be null while in primary key can’t have null value as input.
4.
5. CONSTRAINT
• Constraints enforce limits to the data or type of data that can be
inserted/updated/deleted from a table. The whole purpose of constraints is to
maintain the data integrity during an update/delete/insert into a table. In this
tutorial we will learn several types of constraints that can be created in Relational
DBMS.
• Types of constraints
1.NOT NULL
2.UNIQUE
3.DEFAULT
4.CHECK
5.Key Constraints – PRIMARY KEY, FOREIGN KEY
6. Not Null
• NOT NULL constraint makes sure that a column
does not hold NULL value. When we don’t
provide value for a particular column while
inserting a record into a table, it takes NULL
value by default. By specifying NULL constraint,
we can be sure that a particular column(s)
cannot have NULL values.
Unique
• UNIQUE Constraint enforces a column or set of
columns to have unique values. If a column has
a unique constraint, it means that particular
column cannot have duplicate values in a table.
CREATE TABLE STUDENT(
ROLL_NO NUMBER NOT
NULL, STU_NAME
VARCHAR (35) NOT NULL,
STU_AGE NUMBER NOT
NULL, STU_ADDRESS
VARCHAR (235), PRIMARY
KEY (ROLL_NO) );
CREATE TABLE STUDENT(
ROLL_NO NUMBER NOT
NULL, STU_NAME VARCHAR
(35) NOT NULL UNIQUE,
STU_AGE NUMBER NOT
NULL, STU_ADDRESS
VARCHAR (35) UNIQUE,
PRIMARY KEY (ROLL_NO) );
7. Default
• The DEFAULT constraint provides a default value
to a column when there is no value provided
while inserting a record into a table.
Check
• This constraint is used for specifying range of
values for a particular column of a table. When
this constraint is being set on a column, it
ensures that the specified column must have the
value falling in the specified range.
CREATE TABLE STUDENT(
ROLL_NO NUMBER NOT NULL,
STU_NAME VARCHAR (35) NOT NULL,
STU_AGE NUMBER NOT NULL,
EXAM_FEE NUMBER DEFAULT 10000,
STU_ADDRESS VARCHAR (35) ,
PRIMARY KEY (ROLL_NO)
);
CREATE TABLE STUDENT(
ROLL_NO NUMBER NOT
NULL CHECK(ROLL_NO >1000),
STU_NAME VARCHAR (35)
NOT NULL,
STU_AGE NUMBER NOT
NULL,
EXAM_FEE NUMBER DEFAULT
10000,
STU_ADDRESS VARCHAR (35) ,
PRIMARY KEY (ROLL_NO)
);
8. KEY CONSTRAINTS
Primary Key
• Primary key uniquely identifies each record in a
table. It must have unique values and cannot
contain nulls. In the below example the ROLL_NO
field is marked as primary key, that means the
ROLL_NO field cannot have duplicate and null
values.
Foreign key
• Foreign keys are the columns of a table that
points to the primary key of another table. They
act as a cross-reference between tables.
CREATE TABLE STUDENT(
ROLL_NO NUMBER NOT NULL,
STU_NAME VARCHAR (35) NOT
NULL UNIQUE,
STU_AGE NUMBER NOT NULL,
STU_ADDRESS VARCHAR (35)
UNIQUE,
PRIMARY KEY (ROLL_NO)
);
9. ER DIAGRAMS
• An Entity Relationship Diagram (ERD) is a visual representation
of different data using conventions that describe how these
data are related to each other. For example, the elements
writer, novel, and consumer may be described using ER
diagrams this way.
• In the diagram, the elements inside rectangles are called
entities while the items inside diamonds denote the
relationships between entities.
10. ER DIAGRAM SYMBOL AND NOTATION
• There are three basic elements in an ER Diagram: entity,
attribute, relationship. There are more elements which are
based on the main elements. They are weak entity,
multivalued attribute, derived attribute, weak relationship
and recursive relationship.
11. Entity
• An entity can be a person, place, event, or object
that is relevant to a given system. For example, a
school system may include students, teachers,
major courses, subjects, fees, and other items.
Entities are represented in ER diagrams by a
rectangle and named using singular nouns.
• weak entity is an entity that depends on the
existence of another entity. In more technical terms
it can defined as an entity that cannot be identified
by its own attributes. It uses a foreign key combined
with its attributed to form the primary key.
Attributes
• An attribute is a property, trait, or characteristic of an
entity, relationship, or another attribute. For example,
the attribute Inventory Item Name is an attribute of the
entity Inventory Item. An entity can have as many
attributes as necessary. Meanwhile, attributes can also
have their own specific attributes. For example, the
attribute “customer address” can have the attributes
number, street, city, and state.
• There are composite attribute, multivalued attribute
and derived attribute .
12. Relationship
• A relationship describes how entities interact.
For example, the entity “carpenter” may be
related to the entity “table” by the relationship
“builds” or “makes”. Relationships are
represented by diamond shapes and are labelled
using verbs.
13. HOW TO DRAW E-R DIAGRAMS ?
• Identify all the relevant entities in a given system and determine the relationships among these
entities.
• An entity should appear only once in a particular diagram.
• Provide a precise and appropriate name for each entity, attribute, and relationship in the
diagram. Terms that are simple and familiar always beats vague, technical-sounding words. In
naming entities, remember to use singular nouns. However, adjectives may be used to
distinguish entities belonging to the same class (part-time employee and full time employee,
for example). Meanwhile attribute names must be meaningful, unique, system-independent,
and easily understandable.
• Remove vague, redundant or unnecessary relationships between entities.
• Never connect a relationship to another relationship.
14. DESIGN ISSUES
• It is not always clear whether an object is best expressed by an entity set or a relationship set.
• Two problems arise as a result of the replication: (1) the data are stored multiple times, wasting storage
space, and (2) updates potentially leave the data in an inconsistent state, where the values differ in two
relationships for attributes that are supposed to have the same value.
• Relationships in databases are often binary. Some relationships that appear to be nonbinary could
actually be better represented by several binary relationships.