0% found this document useful (0 votes)
23 views32 pages

RDBMS Unit I A

Uploaded by

kalpanaapj
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)
23 views32 pages

RDBMS Unit I A

Uploaded by

kalpanaapj
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/ 32

MUTHAYAMMAL COLLEGE OF ARTS AND SCIENCE (AUTONOMOUS)

DEPARTMENT OF COMPUTER APPLICATION

Staff Name: N.HYRUNNISHA, M.C.A,M.Phil., Class: II BCA A Paper Code: 21M3UCA04

Paper Name: RELATIONAL DATABASE MANAGEMENT SYSTEM Unit: I

UNIT – I
Introduction: Database System Applications – DBMS Vs. File System – View of Data – Data
Model – Database Languages – Database users and Administrators – Transaction
Management – Database System Structure – Application Architecture. Data Models: Basic
Concepts – Constraint – Keys – ER Diagram – Weak Entity – Extended ER Features - Design
of an ER Schema.
Introduction
Data: Data is a collection of facts, such as numbers, words, measurements, observations or
just descriptions of things.
Information: A processed data is called information.
Database: A database is an organized collection of data, so that it can be easily accessed and
managed.
DBMS: A Database Management System (DBMS) consists of a collection of interrelated
data and a set of programs to access those data.. 
 The primary goal of a DBMS is to provide an environment that is both convenient
and efficient for people to use in retrieving and storing database information. 
USE OF DATABASE SYSTEMS
 The Database Systems are designed to store large amount of information. The management
of data involves both the definition of structures for the storage of information and the
provision of mechanisms for the manipulation of information. 
 It must provide for the safety of information stored and to prevent unauthorized access. The
data are shared among several users the system must avoid possible anomalous results. 

1
DATABASE SYSTEM APPLICATIONS

FIELD USAGE
Banking For customer information, accounts, loans and banking transactions.

For reservations and schedule information. Airlines were the first to


Airlines
use databases in a geographically distributed manner.
For student information, course registration and grades.
Universities

Credit and
For purchase on credit cards and generation of monthly statements.
Transactions
For keeping records of calls made, generating monthly bills,
Telecommunication maintaining balances on prepaid calling cards, and storing
information about the communication networks.
Sales For customer, product, and purchase information.
For management of supply chain and for tracking production of
Manufacturing items in factories, inventories of items in warehouses, and orders for
items.
For storing information about holdings, Sales, and purchases of
Finance
financial instruments such as stocks and bonds
For information about employees, salaries, payroll taxes and benefits
Human Resources
and for generation of paychecks.

DATABASE SYSTEMS VERSUS FILE SYSTEMS


 To keep the organizational information in a file processing system has a number of
major disadvantages. They are: 
 Data Redundancy and Inconsistency
 Difficulty in Accessing Data
 Data Isolation

2
 Integrity Problems
 Atomicity Problems
 Concurrent-Access Anomalies 
 Security Problems 
Data Redundancy and Inconsistency:
 The same information duplicated in several places (files) is called as Redundancy. This
redundancy leads to higher storage and access cost. 
 The redundancy may lead to data inconsistency; that is, the various copies of the same data
may no longer agree. 
Example:
A changed student address may be reflected in one record but not elsewhere in the system.

Difficulty in Accessing Data:


 The file-processing environments do not allow needed data to be retrieved in a convenient
and efficient manner. 
Example:
The bank officer needs to find out the names of all customers who live within the particular
city. The officers extract the information manually, or ask data-processing department to write the
necessary application program.
It is very difficult to extract the information with the existing application program.
Data Isolation:
 The data are scattered in various files, and files may be in different formats, it is difficult to
write new application programs to retrieve the appropriate data. 
Integrity Problems:
 The data values stored in the database must satisfy certain types of consistency constraints. 
Example:
The balance of bank account may never fall below a prescribed amount ($250). The developers
enforce these constraints in the system by adding appropriate code in the
various application programs. When new constraints are added, it is difficult to change the programs
to enforce them.
Atomicity Problems:
 In computer system any mechanical or electrical device, is subject to failure. Once the failure
has occurred and has been detected, the data are restored to the consistent state that existed

3
prior to the failure. 
 The transaction must be atomic- it must happen in entirely or not at all. It is difficult to
ensure this property in a file-processing system. 
Example:
A program to transfer $50 to account A to account B.
Due to system failure $50 was debited from account A but not credited to B.
It may leads to inconsistency.
Concurrent-Access Anomalies:
 To improve the performance of the system and a faster response time many systems allow
multiple users to update the data simultaneously. 
 The interaction of concurrent updates may result in inconsistent data. 
Example
If an account hold some money. If two customers try to withdraw amount, it leads to data
inconsistent
Security Problems:
 Not every user of the database system should be able to access all the data. The application
programs are added to the system in an ad hoc manner, it is difficult to enforce security
constraints. 
To overcome the above disadvantages database systems was developed .

VIEW OF DATA
 A major purpose of a database system is to provide users with an abstract view of the data.
The system hides certain detail of how data are stored and maintained is called as data
abstraction. 
1.Data Abstraction
 Physical Level 
 Logical Level 
 View Level 
Physical Level:
 The lowest level of abstraction describes how the data are actually stored. The complex low-
level data structures are records are described as a block of consecutive storage locations
(words, bytes). 

4

Logical Level:
 This level describes what data are stored in the database, and what relationships exist among
those data. It is used by database administrators, who must decide what information is to be
kept in the database. 
View Level:
 The highest level of abstraction describes only part of the entire database. It is defined for
simplify the interaction with the system. The system may provide many views for the same
database. 
 To hide the details of the logical level of the database, the views also provide a security
mechanism to prevent users from accessing parts of the database. 
Example:
Consider three tables:
customer with fields cust_id, cust_name, street,city
account with fields acc_no, balance
emp with fields emp_name, salary
 At the physical level, record can be described as a block of consecutive storage locations.
 At the logical level, each record is described by a type definition
 At the view level, computer users see a set of application programs that hide the details
of data types.
2. Instances and Schemas
 The collection of information stored in the database at a particular moment is called an
instance of the database. 
 The overall design of the database is called the database schema. 
 The database systems have several schemas, partitioned according to the levels of
abstraction. At the lowest level is the physical schema; at the intermediate level is the logical
schema; and at the highest level is a subschema. 
5
 The database systems support one physical schema, one logical schema, and several
subschemas. 
 The physical schema is hidden beneath the logical schema. It can be changed easily without
affecting application programs.
DATA INDEPENDENCE
The ability to modify a schema definition in one level without affecting a schema definition
in the next higher level is called data independence. There are two levels of data independence:
 Physical Data Independence 
 Logical Data Independence 
Physical Data Independence:
 It is the ability to modify the physical schema without causing application programs to be
rewritten. 
 The modifications at the physical level are necessary to improve performance. 
Logical Data Independence:
 It is the ability to modify the logical schema without causing application programs to be
rewritten. 

DATA MODELS
The structure of a database is called data model.
It consists of collection tool for describing data, data relationships, data semantics, and consistency
constraints.
 The data model classified into the following groups:
 Relational Model
 Entity-relationship Model
 Object-Based Data Model
 Semi-structured data model.
 Relational Model
 This model uses a collection of tables to represent both data and the relationships among
those data.
 Each table has multiple columns and each column has unique name.
 Tables are also known as relations.
 The relational model is an example of a record based model.
 Record-based models are so called because the database is structured in fixed-format
records of several types.

6
 Each table contains records of a particular type. Each record type defines a fixed number
of fields, or attributes.
 The Column of the table corresponds to the attributes of the record type.
 Entity-Relationship Model:
 It consists of collection of basic objects, called entities, and relationships among those object
is called Entity-Relationship model. 
 The overall logical structure of a database can be expressed graphically by an E-R diagram

C-name C-city C-street Account- Balance

Depositor
Customer Account


 The entities are described in a database by a set of attributes.
 A relationship is an association among several entities. 
 The set of all entities of the same type is called as entity set. 
 The set of relationships of the same type is called as relationship set. 
 The E-R model represents certain constraints. One important constraint is mapping
cardinalities, which express the number of entities to which another entity can be associated
via a relationship set. 
Components of E-R Diagram
 Rectangles represent entity sets. 
 Ellipses represent attributes.
 Diamonds represent relationships among entity sets.
 Lines link attributes to entity sets and entity sets to relationships. 
 Object-Based Data Model
 It is based on a collection of objects. An object contains values stored in instance variable
within the object. The object also contains bodies of code that operate on the object. These
bodies of code are called methods. 
 The object contains the same type of values and the same methods are grouped together into

7
classes. The one object can access the data of another object is by invoking a method of that
other object. This action is called sending a message to the object. 
 Semi-structured Data Model
 The semi structured data model permits the specification of data where individual data
items of the same type may have different sets of attributes.
 The Extensible Markup Language (XML) is widely used to represent semi-structured
data.
DATABASE LANGUAGES
 A database system provides two different types of languages. They are:
i) Data-Definition Language (DDL)
ii) Data-Manipulation Language (DML)
i)Data-Definition Language
 DDL stands for Data Definition Language.
 It is a language used for defining and modifying the data and its structure.
 It is used to build and modify the structure of tables and other objects in the database.
 A data dictionary is a file that contains metadata (data about data). The storage structure
and access methods used by the database system by a set of definitions in a special type of
DDL called a data storage and definition language.
o DDL commands are as follows:
1. CREATE
2. DROP
3. ALTER
4. RENAME
5. TRUNCATE
CREATE COMMAND: It is used for creating objects in the database. It creates a new table.

Syntax:
CREATE TABLE <table_name> (column_name1 datatype, column_name2
datatype, . . . column_name_n datatype);
Example: CREATE TABLE employee
(
empid INT,
ename CHAR,

8
age INT,
city CHAR(25),
phone_no VARCHAR(20)
);
 DROP COMMAND: It allows removing entire database objects from the database. It
removes entire data structure from the database. It deletes a table, index or view.
Syntax:
DROP TABLE <table_name>; OR DROP DATABASE <database_name>;
Example : DROP TABLE employee; OR DROP DATABASE employee;
 ALTER COMMAND: An ALTER command allows to alter or to modify the structure of
the database. It modifies an existing database object. Using this command, we can add
additional column, drop existing column and even change the data type of columns.
Syntax:
ALTER TABLE <table_name> ADD <column_name datatype>; OR

ALTER TABLE <table_name>MODIFY <old_column_name> new_column_name>;


OR
ALTER TABLE <table_name>DROP COLUMN <column_name>;
Example :
ALTER TABLE employee ADD (address varchar2(50)); OR

ALTER TABLE employee MODIFY (phone_no) (contact_no); OR


ALTER TABLE employee DROP COLUMN age;
 To view the changed structure of table, use 'DESCRIBE' command.
For example: DESC employee;
 RENAME COMMAND: It is used to rename an object. It renames a database table.
Syntax: RENAME TABLE <old_name> TO <new_name>;
Example: RENAME TABLE emp TO employee;
 TRUNCATE COMMAND: TRUNCATE command is used to delete all the rows from the
table permanently. It removes all the records from a table, including all spaces allocated for
the records. This command is same as DELETE command, but TRUNCATE command does
not generate any rollback data.
Syntax: TRUNCATE TABLE <table_name>;
Example: TRUNCATE TABLE employee;
9
 The output of the DDL is stored in the data dictionary. The database system consults the data
dictionary before reading or modifying actual data.
ii)Data-Manipulation Language
 DML stands for Data Manipulation Language.
 It is a language used for selecting, inserting, deleting and updating data in a database.
 It is used to retrieve and manipulate data in a relational database.
DML commands are as follows,
1. SELECT
2. INSERT
3. UPDATE
4. DELETE
 DML performs read-only queries of data.
1. SELECT COMMAND: SELECT command is used to retrieve data from the database. This
command allows database users to retrieve the specific information from an operational database. It
returns a result set of records from one or more tables.
Clause Description
WHERE It specifies which rows to retrieve.
GROUP BY It is used to arrange the data into groups.
HAVING It selects among the groups defined by the GROUP BY clause.
ORDER BY It specifies an order in which to return the rows.
It provides an alias which can be used to temporarily rename
AS
tables or columns.
SELECT Command
Syntax: SELECT * FROM <table_name>;
Example: SELECT * FROM employee; OR

SELECT * FROM employee where salary >=10,000;


2. INSERT COMMAND: INSERT command is used for inserting a data into a table. Using this
command, we can add one or more records to any single table in a database. It is also used to add
records to an existing code.

Syntax: INSERT INTO <table_name> (`column_name1` <datatype>,


`column_name2` <datatype>, . . . , `column_name_n` <datatype>) VALUES (`value1`,
10
`value2`, . . . , `value n`);

Example: INSERT INTO employee (`eid` int, `ename` varchar(20), `city` varchar(20))
VALUES (`1`, `ABC`, `PUNE`);
3. UPDATE COMMAND: UPDATE command is used to modify the records present in existing
table. This command updates existing data within a table. It changes the data of one or more
records in a table.
Syntax: UPDATE <table_name> SET <column_name = value> WHERE condition;
Example : UPDATE employee SET salary=20000 WHERE ename='ABC';

4. DELETE COMMAND: DELETE command is used to delete some or all records from the
existing table. It deletes all the records from a table.

Syntax: DELETE FROM <table_name> WHERE <condition>;


Example : DELETE FROM employee WHERE emp_id = '001';
If we does not write the WHERE condition, then all rows will get deleted.
 A query is a statement requesting the retrieval of information. The portion of a DML
that involves information retrieval is called a query language.
Ø The DML consists of the following types:
ü Procedural DML
ü Nonprocedural DML
Ø Procedural DML: It requires a user to specify what data are needed and how to get those
data.
Ø Nonprocedural DML: It requires a user to specify what data are needed without specifying
how to get those data. It is usually easier to learn and use than procedural DMLs.
DATABASE USERS AND ADMINISTRATORS
 A primary goal of a database system is to retrieve information from and store new
information in the database. 
Database Users and User Interface:
1. Application Programmers – are computer professionals who write application programs.
Application programmers can choose from many tools to develop user interfaces. RAD
(Rapid Application tool) tools are tools that enable an application programmer to construct
forms and reports with minimal programming effort.

11
2. Sophisticated Users - They are database developers, who write SQL queries to
select/insert/delete/update data. They do not use any application or programs to request the
database. They directly interact with the database by means of query language like SQL.
These users will be scientists, engineers, analysts who thoroughly study SQL and DBMS to
apply the concepts in their requirement.
3. Specialized Users - These are also sophisticated users, but they write special database
application programs. They are the developers who develop the complex programs to the
requirement.
4. Stand-alone Users - These users will have stand –alone database for their personal use.
These kinds of database will have readymade database packages which will have menus and
graphical interfaces.
5. Native Users - these are the users who use the existing application to interact with the
database. For example, online library system, ticket booking systems, ATMs etc which has
existing application and users use them to interact with the database to fulfill their requests.
Database Administrator:
 The person who has such central control over the system is called the Database
Administrator (DBA). The functions of the DBA include the following: 
 Schema Definition 
 Storage Structure and Access-Method Definition 
 Schema and Physical-Organization Modification 
 Granting of Authorization for Data Access 
 Integrity-Constraint Specification 
Schema Definition:
 The DBA creates the original database schema by writing a set of definitions that is
translated by the DDL compiler to a set of tables that is stored permanently in the data
dictionary. 
Storage Structure and Access-Method Definition:
 The DBA creates appropriate storage structures and access methods by writing a set of
definitions, which is translated by the data-storage and data-definition-language compiler. 
Schema and Physical-Organization Modification:
 Programmers accomplish the modifications either to the database schema or to the
description of the physical storage organization by writing a set of definitions that is used by
either the DDL compiler or the data-storage and data-definition-language compiler to

12
generate modifications to the appropriate internal system tables. 
Granting of Authorization for Data Access:
 The granting of different types of authorization allows the database administrator to regulate
which parts of the database various users can access. 
Integrity-Constraint Specification:
 The data values stored in the database must satisfy certain consistency constraints. The
constraints specified explicitly by the database administrator. 

TRANSACTION MANAGEMENT
 A transaction is a collection of operations that performs a single logical function in a
database application. The transaction manager is responsible for ensuring that the database
remains in a consistent (correct) state despite system failures. 
 Each transaction is a unit of both atomicity and consistency. Each and every transaction does
not violate any database consistency constraints. 
ACID Properties:
 To ensure the integrity of the data the database system maintains the
ACID(Atomicity,Consistency,Isolation,Durability) properties of the transaction. 
Atomicity:
 Either all operations of the transaction are reflected properly in the database, or none are. 
Consistency:
 Execution of a transaction in isolation (that is, no other transaction executing concurrently)
preserves the consistency of the database. 
Isolation:
 Even though multiple transactions may execute concurrently, the system guarantees that, for
every pair of transactions Ti and Tj, the Tj finished execution before Ti started or Tj started
execution after Tj finished. 
Durability:
 After a transaction completes successfully, the changes it has made to the database persist,
even if there are system failures.

DATABASE SYSTEM STRUCTURE


 A database system is partitioned into modules that deal with each of the responsibilities
of the overall system.

13
 The functional components of a database system can be broadly divided into the storage
manager and the Query processor components.
Storage Manager
 The storage manager is a component of a database system that provides the interface
between the low-level data stored in the database and the application programs and
queries submitted to the system. The storage manager is responsible for the
interaction with the file manager. The storage manager translates the various DML
statements into low-level file-system commands.
 The storage manager is responsible for storing, retrieving and updating data in
the database.
 The storage manager components include:

1. Authorization & Integrity manager, which tests for the satisfaction of integrity
constraints and checks the authority of users to access data.
2. Transaction manager, which ensures that the database remains in a consistent state
despite system, failures and that concurrent transaction executions precede without
conflicting.
3. File manager, which manages the allocation of space on disk storage and the data
structures used to represent information stored on disk.
4. Buffer manager, which is responsible for fetching data from disk storage into main
memory, and deciding what data to cache in main memory.
 The storage manager implements several data structures such as:
Data files, which store the database itself.
Data dictionary, which stores metadata.
Indices, which can provide fast access to data items.
Query Processor
 The Query processor components include:
1. DDL Interpreter: This interprets DDL statements and records the definitions
in the data dictionary.
2. DML Compiler: This translates DML statements in a query language into an
evaluation plan consisting of low-level instructions that the query evaluation
engine understands.
3. Query Evaluation Engine: This executes low-level instructions generated by
the DML compiler.
14
APPLICATION ARCHITECTURE
Database architecture is logically divided into two types.

15
1. Logical two-tier Client / Server architecture
2. Logical three-tier Client / Server architecture
Two-tier Client / Server Architecture

 Two-tier Client / Server architecture is used for User Interface program and Application
Programs that runs on client side. An interface called ODBC (Open Database Connectivity)
provides an API that allows client side program to call the dbms. Most DBMS vendors
provide ODBC drivers.
 A client program may connect to several DBMS's. In this architecture some variation of
client is also possible for example in some DBMS's more functionality is transferred to the
client including data dictionary, optimization etc. Such clients are called Data server.
Three-tier Client / Server Architecture

 Three-tier Client / Server database architecture is commonly used architecture for web
applications. Intermediate layer called Application server or Web Server stores the web
connectivity software and the business logic (constraints) part of application used to access
the right amount of data from the database server.

16
 This layer acts like medium for sending partially processed data between the database server
and the client.

DATA MODEL
A data model is a collection of conceptual tools for describing data, data relationships, data
semantics and consistency constraints. We will discuss about the two models
 Entity-Relationship Model: A high - level data model. It is based on a perception of a real
world that consists of a collection of basic objects, called entities, and of relationships among
these objects. 
 Relational Model: A lower – level model. It uses a collection of tables to represent both
data and the relationships among those data.
Example:

Component of ER Diagram

17
1. 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.

a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any
key attribute of its own. The weak entity is represented by a double rectangle.

2. 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.
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.
a.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.

b. Composite Attribute
18
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.

c. 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.

d. Derived Attribute
An attribute that can be derived 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.

19
Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.

Types of relationship are as follows:


a. 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, A female can marry to one male, and a male can marry to one female.

b. 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.

c. 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.

20
d. 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.


CONSTRAINTS
Constraints are the rules enforced on the data columns of a table. These are used to limit the type of
data that can go 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 only to one column, whereas the table level constraints are applied to the whole table.
Most commonly used constraints are
Not null constraint: Ensures that a column cannot have NULL value.
Default Constraint : Provides a default value for a column when none is specified.
Unique Constraint: Ensures that all values in a column are different.
Primary key constraint: Uniquely identifies each row/record in a database table.
Foreign key constaint: Uniquely identifies a row/record in any of the given database table.
Check Constraint: The CHECK constraint ensures that all the values in a column satisfies certain
conditions
Index: Used to create and retrieve data from the database very quickly.

Keys
o Keys play an important role in the relational database.
o It is used to uniquely identify any record or row of data from the table. It is also used to
establish and identify relationships between tables.

21
For example, ID is used as a key in the Student table because it is unique for each student. In the
PERSON table, passport_number, license_number, SSN are keys since they are unique for each
person.

Types of keys:
1. Super Key
2. Primary Key
3. Candidate Key
4. Alternate Key
5. Foreign Key
6. Compound Key
7. Composite Key
1. Primary key
o It is the first key used to identify one and only one instance of an entity uniquely. An entity
can contain multiple keys, as we saw in the PERSON table. The key which is most suitable
from those lists becomes a primary key.
o In the EMPLOYEE table, ID can be the primary key since it is unique for each employee. In
the EMPLOYEE table, we can even select License_Number and Passport_Number as
primary
ary keys since they are also unique.
o For each entity, the primary key selection is based on requirements and developers.


22
2. Candidate key
o A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
o Except for the primary key, the remaining attributes are considered a candidate key. The
candidate keys are as strong as the primary key.
For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of the
attributes, like SSN, Passport_Number, License_Number, etc., are considered a candidate key.

3. Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of a
candidate key.

For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME), the


name of two
o employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this
combination can also be a key.
The super key would be EMPLOYEE
EMPLOYEE-ID (EMPLOYEE_ID, EMPLOYEE-NAME),
NAME), etc.
4. Foreign key
 Foreign keys are the column of the table used to point to tthe
he primary key of another table.

23
 Every employee works in a specific department in a company, and employee and department
are two different entities. So we can't store the department's information in the employee
table. That's why we link these two tables tthrough
hrough the primary key of one table.
 We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in
the EMPLOYEE table.
 In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.

5. Alternate key
There may be one or more attributes or a combination of attributes that uniquely identify each tuple
in a relation.
These attributes or combinations of the attributes are called the candidate keys. One key is chosen as
the primary key from these candidate keys, and the remaining candidate key, if it exists, is termed
the alternate key.
In other words, the total number of the alternate keys is the total number of candidate keys minus
the primary key.
The alternate key may or may not exist. If there is onl
onlyy one candidate key in a relation, it does not
have an alternate key.
For example, employee relation has two attributes, Employee_Id and PAN_No, that act as
candidate keys. In this relation, Employee_Id is chosen as the primary key, so the other candidate
key, PAN_No, acts as the Alternate key
key.

24
6. Composite key
Whenever a primary key consists of more than one attribute, it is known as a composite key. This
key is also known as Concatenated Key.

For example, in employee relations, we assume that an emplo


employee
yee may be assigned multiple roles,
and an employee may work on multiple projects simultaneously. So the primary key will be
composed of all three attributes, namely Emp_ID, Emp_role, and Proj_ID in combination. So these
attributes act as a composite key ssince
ince the primary key comprises more than one attribute.
Mapping Cardinality
It is expressed as the number of entities to which another entity can be associated via a relationship
set.
For binary relationship set there are entity set A and B then the mappin
mappingg cardinality can be one of
the following −
 One-to-one
 One-to-many
 Many-to-one
 Many-to-many

25
One-to-one relationship
One entity of A is associated with one entity of B.

Example
Given below is an example of the one-to-one relationship in the mapping cardinality. Here, one
department has one head of the department (HOD).

One-to-many relationship
An entity set A is associated with any number of entities in B with a possibility of zero and entity in
B is associated with at most one entity in A

Example
Given below is an example of the one-to-many relationship in the mapping cardinality. Here, one
department has many faculties.

26
Many-to-one relationship
An entity set A is associated with at most one entity in B and an entity set in B can be associated
with any number of entities in A with a possibility of zero.

Example
Given below is an example of the many-to-one relationship in the mapping cardinality. Here, many
faculties work in one department.

Many-to-many relationship
Many entities of A are associated with many entities of B.
An entity in A is associated with many entities of B and an entity in B is associated with many
entities of A.
Many to many=many to one + one to many

Example
Given below is an example of the many-to-many relationship in the mapping cardinality. Here,
many employees work on many projects.
27
Extended E-R features
The extended E-R features are
1. Specialization
2. Generalization
3. Higher- and lower-level
level entity sets
4 .Attribute
ttribute inheritance and aggregation.
1.Specialization – An entity set broken down sub
sub-entities
entities that are distinct in some way from other
entities in the set.
Specialization is an “aTop-down
down approach” where a high
high-level
level entity is specialized into two or more
level entities.
Example – Consider an entity set vehicle, with attributes color and no. of tires. A vehicle may be
further classified as one of the following:
 Car
 Bike
 Bus
Each of these vehicle types is described by a set of attributes that includes all the attributes of the
entity set vehicle plus additional attributes.
Example: car entities may be described further by the attribute gear, whereas bike entities may be
described
ibed further by the attributes automatic break.
 The
he process of designating subgroupings within an entity set is called specialization.
 The
he specialization of vehicles allows us to distinguish among vehicles according to whether
they are cars, buses, or bikes.
kes.

28
2.Generalization – It is a process of extracting common properties from a set of entities and
creating a generalized entity from it.
 Generalization
eneralization is a “Bottom
“Bottom-up approach”.
 In which two or more entities can be combined to form a higher
higher-level
level entity
ent if they have
some attributes in common.
 In generalization, Subclasses are combined to make a superclass.
Example: There are three entities given, car, bus, and bike. They all have some common attributes
like all cars, buses, and bikes they all have no. of tires and have some colors. So they all can be
grouped and make a superclass named a vehicle.

3.Inheritance – An entity that is a member of a subclass inherits all the attributes of the entity as the
member of the superclass.
 The
he entity also inherits all the relationships that the superclass participates in.
 Inheritance is an important feature of Generalization and Specialization.
 It allows lower-level
level entities to inherit the attributes of higher
higher-level
level entities.
Example – Car, bikes, and buses inherit the attributes of a vehicle. Thus, a car is described by its
color and no. of tires, and additionally a gear attribute; a bike is described by its color and no. of
tires attributes, and additionally automatic break attribute.
4.Aggregation – In aggregation, the relation between two entities is treated as a single entity. In
aggregation, the relationship with its corresponding entities is aggregated into a higher-level
higher entity.
Example- phone numbers on our mobile phone.
We can refer to them individually – Our mother’s number, Our
ur best friend’s number, etc. But it’s
easier to think of them collectively, as our phone number list.
29
Design of an ER Schema.
Following are the steps to create an ER Diagram

30
Example
In an Organization,
ation, an employee is assigned to projects. An employee must be assigned to at least
one or more projects. Each project is managed by a single manager. To maintain instruction quality,
a manager can control only one project.
Step 1) Entity Identification: We have three entities
 Employee
 Project
 Manager

Step 2) Relationship Identification: We have the following two relationships


 The employee is assigned a project
 Manager
anager control a project

Step 3) Cardinality Identification: For them problem statement we know that,


 An employee can be assigned multiple projects
 A manager can manage only one course

Step 4) Identify Attributes – Initially, identify the attributes without mapping them to a particular
entity.
 Once we have a list of Attributes, we need to map them to the identified entities.
 Ensure an attribute is to be paired with exactly one entity.
 If an attribute should belong to more than one entity, use a modifier to make it unique.
 Once the mapping is done, identify the primary Keys.
 If a unique key is not readily available, create one.

31
Entity Primary Key Attribute
Employee Employee_ID EmployeeName
Manager Manager_ID ManagerName
Project Project_ID ProjectName

Step 5) Create the ERD Diagram – A more modern representation of Entity Relationship Diagram
Example

32

You might also like