0% found this document useful (0 votes)
7 views11 pages

Bcs Sem II Dbms Unit III

Unit III focuses on database design and the E-R data model, emphasizing the organization of data and the identification of interrelationships. It covers the design process, including gathering user requirements, creating E-R diagrams, and implementing relational data models to enhance data consistency and minimize redundancy. Additionally, it discusses entity sets, relationship sets, attributes, constraints, and various types of keys essential for maintaining data integrity in databases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

Bcs Sem II Dbms Unit III

Unit III focuses on database design and the E-R data model, emphasizing the organization of data and the identification of interrelationships. It covers the design process, including gathering user requirements, creating E-R diagrams, and implementing relational data models to enhance data consistency and minimize redundancy. Additionally, it discusses entity sets, relationship sets, attributes, constraints, and various types of keys essential for maintaining data integrity in databases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Database Management Systems (DBMS) UNIT III

Unit III
DATABASE DESIGN & THE E-R DATA MODEL

3.1 Overview of the Design Process

Database design is the organization of data according to a database model. Database


design involves classifying data and identifying interrelationships among that data.

Database design develops the logical and physical structure of a database in a given
database management system so that it contains all the information required by the user.
Properly designed database are easy to maintain, improves data consistency and are cost
effective in terms of disk storage space.

Fig.1 Database Development Life-Cycle

The most important process in database development is communication, i.e. gathering


requirements from a client on the required database. Appropriate data elements & their
characteristics are to be described that can be transformed into appropriate information. The
designer’s efforts are focused on:

 Information for needs: What kind of information is needed –that is, what output
(reports and queries) must be generated by the system, what information does the
current system generate, and to what extent is that information adequate?

 Information of users: Who will use the information? How is the information to be
used? What are the various end-user data views?

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 1


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

 Interfacing with the systems design group: The database design process is part of
the Systems Development Life Cycle(SDLC). In some cases, the systems analyst in
charge of designing the new system will also develop the conceptual database model.

Database designs also include E-R(Entity-relationship model) diagrams. An ER


diagram is a diagram that helps to design databases in an efficient way.
ER data model specifies standard set of rules that applies to all logical levels of table.
Once data is modeled in using ER model, it is implemented using Relational data model
using SQL commands. At physical level, the location of data to be stored is considered that
provides efficient retrieval of data.
Use of such models to design database, improves data consistency & minimizes data
redundancy. This also helps to improve user accessibility & communication of user with the
data.

3.2 The Entity-Relationship Model


The E_R model defines the conceptual view of a database. It works around real-
world entities and the associations among them. This model is used to define the data
elements and relationship for a specified system.
a. Entity Sets:
An Entity may be an object with a physical existence –a particular person, car, house,
or employee-or it may be an object with a conceptual existence –a company, a job, or a
university course. In other words, an entity is a piece of data –an object or concept about
which data is stored.
An Entity is an object of Entity type and set of all entities is called as an entity set.
The entity set which does not have sufficient attributes to form a foreign key is called as
Weak entity set. An entity set that has a primary key is called as Strong Entity Set.
For e.g.: E1 is an entity having Entity Type Student and set of all students is called
Entity Set.

S1
Student
S2
Entity
S3

Entity-Set

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 2


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

b. Relationship Sets:
The association among entities is called a relationship. For example, an employee
works at a department, a student enrolls in a course. Here, Works at and Enrolls are
called relationships.
For example, ‘Enrolled in’ is a relationship type that exists between entity
Student and Course. In ER diagram, relationship type is represented by a diamond and
connecting the entities with lines.

A set of relationships of same type is known as relationship set. A set of relationships


of similar type is called a relationship set. Like entities, a relationship too can have attributes.
These attributes are called descriptive attributes.
The number of different entity sets participating in a relationship set is called as
degree of a relationship set.

1. Unary Relationship-
When there is only one entity set participating in a relation, the relationship is called as unary
relationship. For example, one person is married to only one person.

2. Binary Relationship –
When there are two entities set participating in a relation, the relationship is called as binary
relationship. For example, Student is enrolled in Course.

3. N-ary Relationship-
When there are n entities set participating in a relation, the relationship is called as n-ary
relationship. For example, an employee works in a department at a specific location.

The number of times an entity of an entity set participates in a relationship set is known as
cardinality. Cardinality can be of different types:

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 3


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

1. One-to-One: When a single instance of an entity is associated with a single instance


of another entity then it is called one to one relationship. For example, a person has
only one passport and a passport is given to one person.

1 has 1 Passport

2. One-to-Many: When a single row of an entity is associated with more than one rows
of another entity then it is called one to many relationships. For example-a customer
can place many orders but an order cannot be placed by many customers.

1 placed M Order

3. Many-to-many: When more than one rows of an entity are associated with more than
one rows of another entity then it is called many to many relationships. For example,
a can be assigned to many projects and a project can be assigned to many students.

M Assigned M Project

 Attributes: An attribute is a characteristic property. Attributes are used to describe the


properties of all entities. Every entity has attributes. An attribute is represented as Oval in
an ER diagram.
For e.g.: A student entity may have attributes as roll number, class, name etc.

Types of attributes
1. Key attribute: A key attribute can uniquely identify an entity from an entity set. It
can be simple attribute and also a single-valued attribute.
For e.g.: Student’s roll number can uniquely identify a student from a set of students. Key
attribute is represented by oval same as other attributes however the text of key attribute is
underlined to represent it as a primary key.

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 4


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

2. Composite attributes- Attributes that can be further subdivided are composite


attributes. These are made up of simple attributes.
For e.g.: Student_name-first, middle , last.

3. Multi-valued attributes: Attributes with more than one value are multi-valued
attributes. It is represented with double ovals in an ER diagram.
For e.g.: Mobile_No, Email_id, etc.

4. Derived attributes- Attributes that do not have physical existence in the database but
get their values from existing attributes are derived attributes. It is represented by
dashed oval in an ER diagram.
For e.g.: DOB derives age, average salary derived from salary.

Entity and their attributes


3.3 Constraints
Constraints apply limits to the data or type of data that can be
inserted/updated/deleted from a table. Constraints are the rules that we can apply on the type
of data in a table. The whole purpose of constraints is to maintain the data integrity during an
update/delete/insert into a table.

This ensures the accuracy and reliability of the data in the database. Constraints could
be either on a column level or a table level. The column level constraints are applied to the
whole table.
Some of the available constraints in SQL are:

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 5


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

1. NOT NULL:The NOT NULL constraint specifies that the column does not accept NULL
values. 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.
Adding constraint in a New Table:
SQL>CREATE TABLE STUDENT(RNO INT NOT NULL<NAME
VARCHAR(10),CLASS VARCHAR(5));
Adding constraint in an existing Table:
SQL>ALTER TABLE STUDENT ADD NOT NULL(RNO);
Dropping Constraint:
SQL>ALTER TABLE STUDENT DROP NOT NULL RNO;

2. UNIQUE: The UNIQUE constraint specifies that the column does not have accept
(redundant) duplicate values. It ensures that each row for a column must have a unique value.
We can have more than one UNIQUE columns in a table.

Adding Constraint in a New Table:


SQL>CREATE TABLE STUDENT(RNO INT UNIQUE,NAME VARCHAR(10),CLASS
VARCHAR(5));
Adding Constraint in an existing Table:
SQL>ALTER TABLE STUDENT ADD UNIQUE(RNO);
Dropping Constraint:
SQL>ALTER TABLE STUDENT DROP UNIQUE RNO;

3. PRIMARY KEY: A PRIMARY KEY is a combination of not null & unique constraints
i.e. does not allow null and duplicate values in the column. Primary key constraint uniquely
identifies each record in a database. Multiple UNIQUE constraints can be defined on a table.

Adding Constraint in a New Table:


SQL>CREATE TABLE STUDENT(RNO INT, NAME VARCHAR(10), CLASS
VARCHAR(5),PRIMARY KEY(RNO));
Adding Constraint in an existing Table:
SQL>ALTER TABLE STUDENT ADD PRIMARY KEY(RNO);

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 6


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

Dropping Constraint:
SQL> ALTER TABLE STUDENT DROP PRIMARY KEY;

4. FOREIGN KEY: FOREIGN KEY is a field in a table which uniquely identifies each row
of a another table i.e. this field points to primary key of another table. The relationship
between 2 tables matches the primary key in one of the tables with a foreign key in the
second table. FOREIGN KEY constraint applied column must have same data type as the
reference on another table column.

Adding Constraint in a New Table:


SQL>CREATE TABLE STUDENT(RNO INT, NAME VARCHAR(10),CLASS
VARCHAR(5),FOREIGN_KEY(C_ID)REFERENCES COURSE(C_ID));
Adding Constraint in an existing Table:
SQL>ALTER TABLE STUDENT ADD FOREIGN KEY(C_ID) REFERENCES
COURSE(C_ID);
Dropping Constraint:
SQL>ALTER TABLE STUDENT DROP FOREIGN KEY;

5. CHECK: Using the CHECK constraint we can specify a condition for a field, which
should be satisfied at the time of entering values for this field.
Check constraint is used to restrict the value of a column between a range. It performs check
on the values, before storing them into the database.
For example, the below query creates a table Student and specifies the condition of the field
AGE as (AGE>=18), i.e. the user will not be allowed to enter any record in the table with
AGE<18.
Adding Constraint in a New Table:
SQL>CREATE TABLE STUDENT(RNO INT, NAME VARCHAR(10),CLASS
VARCHAR(5),AGE INT NOT NULL CHECK(AGE>=18));
Adding Constraint in an existing Table:
SQL>ALTER TABLE STUDENT ADD CHECK(AGE>=18);
SQL>ALTER TABLE STUDENT ADD CONSTRAINT VERIFY_AGE
CHECK(AGE>=18);
Dropping Constraint:

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 7


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

SQL>ALTER TABLE STUDENT DROP CHECK;


SQL>ALTER TABLE STUDENT DROP CHECK VERIFY_AGE;

6. DEFAULT: This constraint is used to provide a default value for the fields. That is, if at
the time of entering new records in the table if the user does not specify any value for these
fields then the default value will be assigned to them.

Adding Constraint in a New Table:


SQL>CREATE TABLE STUDENT(RNO INT, NAME VARCHAR(10),CLASS
VARCHAR(5),COUNTRY VARCHAR(10) DEFAULT ‘INDIA’);
Adding Constraint in an existing Table:
SQL>ALTER TABLE STUDENT ADD CONTRY VARCHAR(10) DEFAULT ‘INDIA’;
SQL>ALTER TABLE STUDENT MODIFY COUNTRYSET DEFAULT ‘INDIA’;
Dropping Constraint:
SQL>ALTER TABLE STUDENT ALTER COUNTRY DROP DEFAULT;

 KEYS:

A DBMS key is an attribute or set of an attribute which helps you to identify a row(tuple)
in a relation (table). They allow you to find the relation between two tables.
Keys help you uniquely identify a row in a table by a combination of one or more
columns in that table.
DBMS has following seven types of keys each has their own functionality:

1. Primary Key: PRIMARY KEY is a column or group of columns in a table that


uniquely identify every row in that table. A table cannot have more than one primary
key. The value in a primary key column can never be modified or updated if any
foreign key refers to that primary key.

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 8


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

2. Foreign Key: In a relationship between two tables, a primary key of one table is
referred as a foreign key in another table. Foreign key can have duplicate values in it
and can also keep null values if column is defined to accept null values.

3. Alternate Key: A table can have multiple choices for a primary key but only one can
be set as the primary key. All the keys which are not primary key are called as
Alternate key.

4. Composite Key: COMPOSITE KEY is a combination of two or more columns that


uniquely identify rows in a table. The combination of columns guarantees uniqueness,
through individually uniqueness is not guaranteed. Hence, they are combined to
uniquely identify records in a table.

5. Super Key: A super key 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. Primary key, Alternate Key are a subset of super keys.

6. Candidate Key: Candidate key is a super key with no repeated attributes. The
primary key should be selected from the candidate keys. Every table must have at
least a single candidate key. A table can have multiple candidate keys but only a
single primary key.
7. Unique Key: We can have other fields also in a table beyond primary key which are
also be able to uniquely identify the record. It can accept only one null value and it
cannot have duplicate values in it.
 Participation Constraints: In a Relationship, participation constraint specifies the
presence of an entity when it is related to another entity in a relationship type. It is also
called the minimum cardinality constraint.
This constraint specifies the number of instances of an entity that are participating in
the relationship.

There are two types of Participation constraint:

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 9


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

1. Total Participation:
 It specifies that each entity present in the entity set must mandatorily participate in at
least one relationship instance of that relationship set, for this reason, it is also called
as mandatory participation.
 It is represented using a double line between the entity set and relationship set.
 For e.g., It specifies that each student must be enrolled in at least one course where
the “student” is the entity set and relationship “enrolled in” signifies total
participation. It means that every student must have enrolled at least in one course.

2. Partial participation:
 It specifies that each entity in the entity set may or may not participate in the
relationship instance of the relationship set, is also called as optional participation.
 It is represented using a single line between the entity set and relationship set in the
ER diagram.
 A single line between the entities i.e. courses and enrolled in a relationship signifies
the partial participation, which means there might be some courses where enrollments
are not made i.e. enrollments are optional in that case.

3.4 Entity Relationship Diagram

An Entity-relationship model (ER model) describes the structure of a database with the
help of a diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER
model is a design or blueprint of a database that can later be implemented as a database. The
main components of E-R model are: entity set and relationship set.
An ER diagram shows the relationship among entity sets. An entity set is a group of
similar entities and these entities can have attributes. Peter Chen developed ERDs in 1976.
ER diagram uses certain standard shapes to denote different components of a database
object. There are five main components of an ERD as:

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 10


www.nandigramiit.org
Database Management Systems (DBMS) UNIT III

1. Entity: An entity can be represented in rectangles, as:

Student

2. Attributes:
i. Simple Attribute
ii. Composite Attribute
iii. Multi-valued Attribute
iv. Derived Attribute

Fig. ER Diagram with two entities and a relationship

NANDIGRAM INSTITUTE OF INFORMATION TECHNOLOGY, NANDED 11


www.nandigramiit.org

You might also like