DBMS_Unit-1
DBMS_Unit-1
1 Database
• It is a collection of interrelated data of an enterprise in a particular subject.
For example, a university database might contain information about the following:-
• The primary goal of a DBMS is to provide a way to store and retrieve database
information that is both convenient and efficient.
3 Applications of DBMS
Databases are widely used. Here are some representative applications:
2
• Human resources: For information about employees, salaries, payroll taxes and
benefits, and for generation of paychecks.
Data redundancy: Data redundancy refers to the duplication of data, lets say we
are managing the data of a college where a student is enrolled for two courses, the same
student details in such case will be stored twice, which will take more storage than needed.
Data redundancy often leads to higher storage costs and poor access time.
Data inconsistency: Data redundancy leads to data inconsistency, lets take the
same example that we have taken above, a student is enrolled for two courses and we
have student address stored twice, now lets say student requests to change his address, if
the address is changed at one place and not on all the records then this can lead to data
inconsistency.
Difficulty in accessing data: In file system the data is stored in the files. Whenever
data has to be retrieved as per the requirements then a new application program has to
be written. This is tedious process.
Data isolation: Because data are scattered in various files, and files may be in differ-
ent formats, writing new application programs to retrieve the appropriate data is difficult.
Integrity problems: The data values stored in the database must satisfy certain
types of consistency constraints.
For example, the balance of a bank account may never fall below a prescribed amount.
These constraints are enforced in the system by adding appropriate code in the various
application programs. However, when new constraints are added, it is difficult to change
the programs to enforce them. The problem is compounded when constraints involve
several data items from different files.
3
Concurrent-access anomalies: Concurrent access means multiple users can access
database simultaneously. In such an environment, interaction of concurrent updates may
result in inconsistent data.
Consider bank account A, containing $500. If two customers withdraw funds (say $50
and $100 respectively) from account A at about the same time, the result of the concur-
rent executions may leave the account in an incorrect (or inconsistent) state. There is no
central control of data in classical file organization. So, the concurrent access of data by
many users is difficult to implement.
Security problems: Data should be secured from unauthorised access, for exam-
ple a student in a college should not be able to see the payroll details of the teachers,
such kind of security constraints are difficult to apply in file processing systems.
Not every user of the database system should be able to access all the data.
Data Consistency and Integrity: As we discussed earlier the root cause of data
inconsistency is data redundancy, since data normalization takes care of the data redun-
dancy, data inconsistency also been taken care of as part of it.
Easy access to data: Database systems manages data in such a way so that the
data is easily accessible with fast response times.
Easy recovery: Since database systems keeps the backup of data, it is easier to
do a full recovery of data in case of a failure.
Flexible: Database systems are more flexible than file processing systems.
6 Disadvantages of DBMS
• DBMS implementation cost is high compared to the file system
• Performance: Database systems are generic, making them suitable for various ap-
plications. However this feature affect their performance for some applications
4
7 Data abstraction model or Three level data ab-
straction architecture
Data abstraction means to hide the information. To hide the information from some
users, three levels of abstraction is used.
1. External level
It is also called view level. The reason this level is called “view” is because several users
can view their desired data from this level which is internally fetched from database with
the help of conceptual and internal level mapping. The user doesn’t need to know the
database schema details such as data structure, table definition etc. User is only con-
cerned about data which is what returned back to the view level after it has been fetched
from database (present at the internal level). External level is the “top level” of the
Three Level DBMS Architecture.
2. Conceptual level
It is also called logical level. The conceptual level describes the structure of the whole
database. The conceptual schema hides the details of physical storage structures and
concentrates on describing entities, data types, relationships, user operations, and con-
straints. Usually, a representational data model is used to describe the conceptual schema
when a database system is implemented.
3. Physical level
5
This level is also known as internal level. This level describes how the data is actually
stored in the storage devices. This level is also responsible for allocating space to the
data. The internal level describes the physical storage structure of the database. The
internal schema uses a physical data model and describes the complete details of data
storage and access paths for the database. This is the lowest level of the architecture.
Schema is of three types: Physical schema, logical schema and view schema.
Physical schema: The design of a database at physical level is called physical schema,
how the data stored in blocks of storage is described at this level.
Logical schema: Design of database at logical level is called logical schema, program-
mers and database administrators work at this level, at this level data can be described as
certain types of data records gets stored in data structures, however the internal details
such as implementation of data structure is hidden at this level (available at physical
level).
View schema: Design of database at view level is called view schema. This generally
describes end user interaction with database systems.
8.2 Instance
The collection of information stored in the database at a particular moment is called an
instance of the database.
9 Data Independence
Data independence can be explained using the three-schema architecture.
Data independence refers characteristic of being able to modify the schema at one level
of the database system without altering the schema at the next higher level.
There are two types of data independence:
• Logical data independence is used to separate the external level from the conceptual
view.
• If we do any changes in the conceptual view of the data, then the user view of the
data would not be affected.
6
9.2 Physical Data Independence
• Physical data independence can be defined as the capacity to change the internal
schema without having to change the conceptual schema.
• If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
• Physical data independence is used to separate conceptual levels from the internal
levels.
• Physical data independence occurs at the logical interface level.
10 Data Models
Data model is a collection of conceptual tools for describing data, data relationships, data
semantics, and consistency constraints. Data models define how the logical structure of
a database is modeled. Data models define how data is connected to each other and how
they are processed and stored inside the system.
There are different types of data models are used in DBMS. Here, we are going to explain
some data models.
(1) Entity relationship model
(2) Relational model
(3) Network model
(4) Hierarchical model
Entity-relationship model
The entity-relationship (E-R) data model 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. An entity is a “thing” or “object” in the real world that is distinguishable from
other objects. For example, each person is an entity, and bank accounts can be considered
as entities.
Entities are described in a database by a set of attributes. For example, the attributes
account-number and balance may describe one particular account in a bank, and they
form attributes of the account entity set. Similarly, attributes customer-name, customer-
street address and customer-city may describe a customer entity.
A relationship is an association among several entities. For example, a depositor rela-
tionship associates a customer with each account that she has. The set of all entities of
the same type and the set of all relationships of the same type are termed an entity set
and relationship set, respectively.
The overall logical structure (schema) of a database can be expressed graphically by an
E-R diagram, which is built up from the following components:
• Rectangles, which represent entity sets
• Ellipses, which represent attributes
• Diamonds, which represent relationships among entity sets
• Lines, which link attributes to entity sets and entity sets to relationships
7
For example, consider part of a database banking system consisting of customers and
of the accounts that these customers have. Following figure shows the corresponding
E-R diagram. The E-R diagram indicates that there are two entity sets, customer and
account, with attributes as outlined earlier. The diagram also shows a relationship de-
positor between customer and account.
Relational model
The relational model uses a collection of tables to represent both data and the rela-
tionships among those data. Each table has multiple columns, and each column has a
unique name. Following figure presents a sample relational database comprising three
tables: One shows details of bank customers, the second shows accounts, and the third
shows which accounts belong to which customers.
Network model
8
1. Boxes, which correspond to record types
2. Lines, which correspond to links
A data-structure diagram serves the same purpose as an E-R diagram; namely, it specifies
the overall logical structure of the database. Every E-R diagrams can be transformed
into their corresponding data-structure diagrams.
9
Figure 1: data-structure diagram
The data structure diagram of this E-R diagram is shown in the following figure:-
Hierarchical model
10
Figure 2: Sample database for data-structure diagram shown in figure 1.1
There are two database trees. The first tree (Figure a) corresponds to the tree-structure
diagram T1; the second tree (Figure b) corresponds to the tree-structure diagram T2.
Example: Consider the following E-R diagram:-
11
A sample database corresponding to the above tree-structure diagram is shown in the
following figure:-
11 Database languages
A database system provides a data definition language to specify the database schema
and a data manipulation language to express database queries and updates. In practice,
the data definition and data manipulation languages are not two separate languages; in-
stead they simply form parts of a single database language, such as the widely used SQL
language.
1. CREATE :
12
• The create command is used to create a table.
• A Table name should be unique, i.e., it must not match with existing tables.
• A Table name and column name must start with alphabet, must not match with
reserved keywords, and should be combination of A-Z, a-z, 0-9, and ’ ’ (underscore)
having maximum length up to 30 characters.
• Each column definition requires name, data type and size for that column.
• Table name and column name are not case sensitive generally . But if they are
enclosed within double quotes, then they are case sensitive.
2. ALTER :
13
• Alter command can be used for this purpose are described below:
B. Dropping Columns :
This command deletes an existing column from the table along with the data held by
that column.
Syntax:
Alter table TableName Drop column columnName;
Example: Deletion of a column from a table is shown in the following figure:-
C. Modifying Columns :
This command sets newDatatype and newSize as datatype and size for specified column
respectively. The main aim of this command is to modify or change the datatype and
size of the column.
14
Syntax :
Alter table TableName Modify(columnName newDatatype(newSize));
Example:
3. DROP :
• The DROP TABLE command drops the specified table. This means, all records
along with structure of the table will be destroyed.
• Care must be taken while using this command, as all records held within the table
are lost and cannot be recovered.
Syntax :
drop table tablename;
Example:
4. TRUNCATE :
15
• Logically, this is equivalent to DELETE statement that deletes all rows without
using WHERE clause.
• TRUNCATE operation drops and re-creates the table. This is must faster than
deleting all rows one by one.
Syntax :
truncate table tablename;
Example:
A data manipulation language (DML) is a language that enables users to access or ma-
nipulate data as organized by the appropriate data model. There are basically two types:
16
Command Description
CREATE to create objects in a database
ALTER to modify existing data in a table
DROP to delete objects from the database
TRUNCATE to remove all records from the table
• Procedural DMLs require a user to specify what data are needed and how to get
those data.
• Declarative DMLs (also referred to as non-procedural DMLs) require a user to
specify what data are needed without specifying how to get those data.
A query is a statement requesting the retrieval of information. The portion of a DML
that involves information retrieval is called a query language.
Following commands in SQL are used to manipulate database.
These all Commands are shown in detail with their syntax and example:
Command Description
INSERT insert data into table
SELECT retrieve data from the table
UPDATE modify existing data in the table
DELETE delete records from the table
1. INSERT :
• The INSERT command is used insert the data into a table or create a new row in
table.
• To insert user data into tables, ”INSERT INTO ...” SQL statement is used. and
stores the inserted values into respective columns.
Syntax :
insert into tablename (column1, column2, columnN) Values (expression1, expression2, ...
17
, expressionN); Example:
Example:
2. SELECT :
• The SELECT command is used to retrieve selected rows from one or more tables
and displays on the screen. It is most widely used and required statement among
all others in SQL.
• Once a table is loaded with user data, these data can be retrieved in number of
different manners.
• Here, an asterisk (’ * ’) is used as the meta character, and it indicates all the
columns of a given table.
18
• This statement retrieves all the columns and all the rows of the table.
Syntax :
select * from tablename;
Example:
Variations of the basic SELECT statement can be used to retrieve selected data as de-
scribed below:
• This Statement retrieves only selected columns as specified with SELECT clause.
19
Syntax :
select column1, column2, ..., columnN from tablename;
Example:
• This statement retrieves only specific rows that specify the condition given with
WHERE clause.
• Multiple conditions can be combined with logical operators such as AND and OR.
Syntax :
select * from tablename WHERE condition;
Example:
• This Statement retrieves only Selected columns as specified with SELECT clause.
• Also, retrieves only specific rows that specify the condition given with WHERE
clause.
Syntax :
select column1, column2, ..., columnN from tablename WHERE condition;
Example:
20
3. UPDATE :
• The UPDATE command can be used to change or modify the data values in a table.
• It can be used to update either all rows or a set of rows from a table.
• This update command updates all rows from the table, and displays message re-
garding how many rows have been updated.
• The SET clause specifies which column data to modify.
• An expression can be a constant value, a variable, or some expression and it specifies
the new value for related columns.
• You can update specific rows by the WHERE clause, and displays message regarding
how many rows have been updated.
Syntax :
update tablename set column1=expression1,column2=expression2 where condition;
Example:
4. DELETE :
• The DELETE command can be used to remove either all rows of a table, or a set
of rows from a table.
• The DELETE command deletes all rows from the table, and displays message
regarding how many rows have been deleted.
• The DELETE command deletes rows from the table that satisfy the condition
provided by WHERE clause. It also displays message regarding how many rows
have been deleted.
21
Syntax :
delete from tablename;
Example:
22
COMMIT;
ROLLBACK command
This command restores the database to last commited state. It is also used with SAVE-
POINT command to jump to a savepoint in an ongoing transaction. If we have used
the UPDATE command to make some changes into the database, and realise that those
changes were not required, then we can use the ROLLBACK command to rollback those
changes, if they were not commited using the COMMIT command.
Following is rollback command’s syntax,
SAVEPOINT command
SAVEPOINT command is used to temporarily save a transaction so that you can rollback
to that point whenever required.
Following is savepoint command’s syntax,
Example:
23
SELECT * FROM class;
Application programmers
Application programmers are computer professionals who write application programs.
Application programmers can choose from many tools to develop user interfaces. Rapid
application development (RAD) tools are tools that enable an application programmer
to construct forms and reports without writing a program.
Sophisticated users
Sophisticated users interact with the system without writing programs. Instead, they
form their requests in a database query language. They submit each such query to a
query processor, whose function is to break down DML statements into instructions that
the storage manager understands. Analysts who submit queries to explore data in the
database fall in this category. They use some of the tools like Online Analytical Process-
ing(OLAP), Data mining.
Specialized users
Specialized users are sophisticated users who write specialized database applications that
do not fit into the traditional data-processing framework. Among these applications
are computer-aided design systems, knowledge base and expert systems, systems that
store data with complex data types (for example, graphics data and audio data), and
environment-modeling systems.
24
12.2 Database Administrator
A person who has such central control of both the data and the programs that access
those data over the system is called a database administrator (DBA). The functions of a
DBA are the followings:-
• Schema definition: The DBA creates the original database schema by executing
a set of data definition statements in the DDL.
• Storage structure and access-method definition: DBA decides what struc-
ture to be used to store the data and what method to be used to access that.
• Schema and physical-organization modification: The DBA carries out
changes to the schema and physical organization to reflect the changing needs of
the organization, or to alter the physical organization to improve performance.
• Granting of authorization for data access: By granting different types of
authorization, the database administrator can regulate which parts of the database
various users can access.
• Routine maintenance: Examples of the database administrator’s routine main-
tenance activities are:
– Periodically backing up the database, either onto tapes or onto remote servers,
to prevent loss of data in case of disasters such as flooding.
– Ensuring that enough free disk space is available for normal operations, and
upgrading disk space as required.
– Monitoring jobs running on the database and ensuring that performance is not
degraded by very expensive tasks submitted by some users.
Authorization and integrity manager: It checks the integrity constraints and the
authority of users to access data.
25
without conflicting.
File manager: It manages the allocation of space on disk storage and the data struc-
tures used to represent information stored on disk.
Buffer manager: It is responsible for fetching data from disk storage into main mem-
ory, and deciding what data to cache in main memory. The buffer manager is a critical
part of the database system, since it enables the database to handle data sizes that are
much larger than the size of main memory.
The storage manager implements several data structures as part of the physical system
implementation:
• Data files, which store the database itself.
• Data dictionary, which stores metadata about the structure of the database, in
particular the schema of the database.
• Indices, which provide fast access to data items that hold particular values.
DDL interpreter: It interprets DDL statements and records the definitions in the
data dictionary.
14 Application Architectures
Most users of a database system today are not present at the site of the database system,
but connect to it through a network. We can therefore differentiate between client ma-
chines, on which remote database users work, and server machines, on which the database
system runs. Database applications are usually partitioned into two or three parts, as in
Figure .
26
Figure 3: Database system structure
27
Figure 4: Two-tier and three-tier architectures
with an application server, usually through a forms interface. The application server in
turn communicates with a database system to access data. The business logic of the
application, which says what actions to carry out under what conditions, is embedded in
the application server, instead of being distributed across multiple clients.
Three-tier applications are more appropriate for large applications, and for applications
that run on the World Wide Web.
28
ENTITY-RELATIONSHIP MODEL
1 E-R Model
ENTITY RELATIONSHIP (ER) MODEL is a high-level conceptual data model diagram.
ER modeling helps you to analyze data requirements systematically to produce a well-
designed database. The Entity-Relationship model represents real-world entities and the
relationship between them. It is considered a best practice to make ER model before
implementing your database.
The E-R data model uses three important components: entity sets, relationship sets, and
attributes.
1.2 Attributes
Attributes are descriptive properties possessed by each member of an entity set. For
example, possible attributes of the customer entity set are customer-id, customer-name,
customer-street, and customer-city.
In real life, there would be further attributes, such as street number, apartment number,
state, postal code, and country.
Possible attributes of the loan entity set are loan-number and amount.
For each attribute, there is a set of permitted values, called the domain, or value set,
of that attribute. The domain of attribute customer-name might be the set of all text
strings of a certain length.
An attribute, as used in the E-R model, can be characterized by the following attribute
types.
29
called a multi-valued attribute.
For example, loan-number, age are single valued attributes whereas mobile-no, dependent-
name are multi-valued attributes.
Derived attribute
If the value for the attribute is derived from the values of other related attributes, then
this attribute is said to be derived attribute.
For example, Age attribute is derived from attribute date-of-birth, Experience attribute
deried from date-of-joining etc. The value of the derived attribute is not stored but is
computed when required.
Null values: An attributes takes null value when an entity does not have a value
for it( for example middle-name) or if the value is not known.
• For example, we can define a relationship that associates customer Hayes with
loan L-15. This relationship specifies that Hayes is a customer with loan number
L-15.
• It is a mathematical relation on more than one entity sets. If E1 , E2 , ..., En are entity
sets, then a relationship set R is a subset of {(e1 , e2 , ..., en )!e1 ∈ E1 , e2 ∈ E2 , ..., en ∈
En } where (e1 , e2 , ..., en ) is a relationship. Here, entity sets E1 , E2 , ..., En participate
in relationship R.
Example: Consider the two entity sets customer and loan in following Figure. We
define the relationship set borrower to denote the association between customers and the
bank loans that the customers have.
Descriptive attributes: A relationship set may have some new attributes which are
30
not presents in the entity sets are called descriptive attributes. It describes about the
relationship set.
Example: Consider a relationship set depositor with entity sets customer and ac-
count.We could associate the attribute access-date to that relationship to specify the
most recent date on which a customer accessed an account.
2 Constraints
An E-R enterprise schema may define certain constraints to which the contents of a
database must conform. In this section, we examine mapping cardinalities and partici-
pation constraints, which are two of the most important types of constraints.
31
Example: Consider relationship borrower between two entity sets customer and loan.
Participation of loan entity set in this relationship borrower is the total. And participation
of customer entity set in this relationship borrower is the partial.
3 Keys
A key allows us to identify a set of attributes that suffice to distinguish entities from each
other. Keys also help uniquely identify relationships, and thus distinguish relationships
from each other.
Candidate key
A superkey is said to be a candidate key if no proper subset of it is a superkey.
In another words, a minimal superkeys are a candidate keys.
Primary key
Out of all possible candidate keys, the database designer chooses one as a primary key.
That is, a primary key is a candidate key that is chosen by the database designer.
Alternate key
The candidate keys which are not selected as a primary key, are called alternate keys.
Composite key
Any key is said to be composite key if it consists of more than one attributes.
Example: Consider entity set student with attributes (rollNo, name, branch, address,
32
mobileNo).
Superkeys: {rollNo}, {rollNo, name}, {rollNo, address}, {mobileNo},{name, mo-
bileNo}.
Candidate keys: {rollNo}, {mobileNo}.
Primary key: {rollNo}
Alternate key: {mobileNo}.
Composite keys: {rollNo, name}, {rollNo,address},{name, mobileNo}.
• If the relationship set R has no attributes associated with it, then the set of at-
tributes primary-key(E1 ) ∪ primary-key(E2) ∪ · · · ∪ primary-key(En) describes
an individual relationship in set R.
• If the relationship set R has attributes a1, a2, · · · , am associated with it, then the
set of attributes primary-key(E1 ) ∪ primary-key(E2 ) ∪ · · · ∪ primary-key(En ) ∪
{a1 , a2 , ..., am } describes an individual relationship in set R.
The structure of the primary key for the relationship set depends on the mapping
cardinality of the relationship set.
Example: consider the entity sets customer and account, and the relationship set
depositor, with attribute access-date.
• Case 1: If the relationship set is many to many. Then the primary key of depositor
consists of the union of the primary keys of customer and account.
4 Entity-Relationship Diagram
An E-R diagram can express the overall logical structure of a database graphically. Such
a diagram consists of the following major components:
33
4.1 Some E-R diagram examples
1. E-R diagram showing many to many relationship between customer and loan entity
set.
2. E-R diagram showing one to many relationship between customer and loan entity
set.
3. E-R diagram showing many to one relationship between customer and loan entity
set.
4. E-R diagram showing one to one relationship between customer and loan entity set.
34
35
(a) A particular combination of entities from A1 , A2 , ..., Ai can be associated with
at most one combination of entities from Ai + 1, Ai+2 , ..., An . Thus, the pri-
mary key for the relationship R can be constructed by the union of the primary
keys of A1 , A2 , ..., Ai .
(b) For each entity set Ak , i < k ≤ n, each combination of the entities from the
other entity sets can be associated with at most one entity from Ak . Each set
{A1 , A2 , ..., Ak−1 , Ak+1 , ..., An }, for i < k ≤ n, then forms a candidate key.
• An edge between an entity set and a binary relationship set can have an
associated minimum and maximum cardinality, shown in the form l..h, where
l is the minimum and h the maximum cardinality.
• A minimum value of 1 indicates total participation of the entity set in the
relationship set.
• A maximum value of 1 indicates that the entity participates in at most one
relationship, while a maximum value * indicates no limit.
• Note that a label 1..* on an edge is equivalent to a double line.
• An entity set that has a primary key is termed as a strong entity set.
• The relationship associating the weak entity set with identifying entity set is called
an identifying relationship set.
• The identifying relationship is many to one from the weak entity set to the identi-
fying entity set, and the participation of the weak entity set in the relationship is
total.
• The primary key of a weak entity set is formed by the primary key of the strong
entity set on which the weak entity set is dependent plus the weak entity set’s
discriminator.
36
• The identifying relationship set is represented by double diamonds
In this E-R diagram, payment is a weak entity set and loan is a strong entity set. loan-
payment is an identifying entity set. Discriminator of payment is payment-number. Pri-
mary key of payment will be {loan-number,payment-number}.
6.1 Specialization
The process of designating subgroupings within an entity set is called specialization.
Example: Consider an entity set person, with attributes name, street, and city. A
person may be further classified as one of the following:
• customer
• employee
Each of these person types is described by a set of attributes that includes all the at-
tributes of entity set person plus possibly additional attributes. For example, customer
entities may be described further by the attribute customer-id, whereas employee entities
may be described further by the attributes employee-id and salary.
6.2 Generalization
• Generalization is a containment relationship that exists between a higher-level en-
tity set and one or more lower-level entity sets.
• Generalization and specialization are simple inversions of each other. They are
represented in an E-R diagram in the same way.
37
Example: In generalization process, database designer may have first identified a cus-
tomer entity set with the attributes name, street, city, and customer-id, and an employee
entity set with the attributes name, street, city, employee-id, and salary.
There are similarities between the customer entity set and the employee entity set in
the sense that they have several attributes in common. This commonality can be ex-
pressed by generalization.
6.3 Aggregation
• Aggregation is an abstraction through which relationships are treated as a higher
level entity sets and can participate in relationships.
Example: Consider the following E-R diagram:- There is redundant information in the
above figure, however, since every employee, branch, job combination in manages is also
in works-on. If the manager were a value rather than an manager entity,we could instead
make manager a multi-valued attribute of the relationship works-on.
Using aggregation, the relationship set works-on (relating the entity sets employee, branch,
and job) is treated as a higher-level entity set called works-on. Such an entity set is treated
in the same manner as is any other entity set. We can then create a binary relationship
manages between works-on and manager to represent who manages what tasks. It is
shown in the following figure:- Example:
Draw the E-R model or diagram for banking enterprise.
Solution: To design E-R model corresponding to any enterprise, we follow the following
steps:-
• Data requirements
• Identify attributes
38
7.1 Tabular Representation of Strong Entity Sets
Let E be a strong entity set with descriptive attributes a1 , a2 , ..., an . We represent this
entity by a table called E with n distinct columns, each of which corresponds to one of
the attributes of E. Each row in this table corresponds to one entity of the entity set E.
Example:
Consider a strong entity set loan with attributes loan-number and amount. The table
corresponding to loan will be the following
Example:
Consider the weak entity set payment with three attributes: payment-number, payment-
date, and payment-amount. It depends on strong entity set loan. The primary key of
loan is loan-number. Thus, we represent payment entity set by a table with four columns
labeled loan-number, payment-number, payment-date, and payment-amount. The table
corresponding to payment will be the following
Example:
Consider the relationship set borrower. This relationship set involves the following two
entity sets:
Assume relationship set borrower has no attributes. Then, the borrower table has two
columns, labeled customer-id and loan-number. Borrower table is the following:-
39
loan-number amount
L-1 10000
L-2 15000
L-3 20000
customer-id loan-number
C-34 L-1
C-45 L-2
C-20 L-3
40
7.4 Tabular Representation corresponding to Composite At-
tributes
We handle composite attributes by creating a separate attribute for each of the compo-
nent attributes; we do not create a separate column for the composite attribute itself.
Example:
Suppose address is a composite attribute of entity set customer, and the components
of address are street and city. The table generated from customer would then contain
columns address-street and address-city; there is no separate column for address.
Example:
Consider the above E-R diagram for banking enterprise. The diagram includes the mul-
tivalued attribute dependent-name. For this multivalued attribute, we create a table
dependent-name, with columns dname, referring to the dependent-name attribute of em-
ployee, and employee-id, representing the primary key of the entity set employee. Each
dependent of an employee is represented as a unique row in the table.
1. Create a table for the higher-level entity set. For each lower-level entity set, create
a table that includes a column for each of the attributes of that entity set plus a
column for each attribute of the primary key of the higher-level entity set.
For the above E-R diagram, we have three tables:
41
42
43
2. If the generalization is disjoint and complete, that is, if no entity is a member of
two lower-level entity sets directly below a higher-level entity set, and if every entity
in the higher level entity set is also a member of one of the lower-level entity sets.
Here, do not create a table for the higher-level entity set. Instead, for each lower-
level entity set, create a table that includes a column for each of the attributes of
that entity set plus a column for each attribute of the higher-level entity set.
For the above E-R diagram, we have two tables:
8 Exercise
1. Construct an E-R diagram for a car-insurance company whose customers own one
or more cars each. Each car has associated with it zero to any number of recorded
accidents.
2. Construct an E-R diagram for a hospital with a set of patients and a set of medical
doctors. Associate with each patient a log of the various tests and examinations
conducted.
5.
44
8.1 Solution of Exercise
1. An E-R diagram for a car-insurance company is the following:-
2. An E-R diagram for a hospital with a set of patients and a set of medical doctors
is the following:-
(a) A class meets only at one particular place and time. This E-R diagram cannot
model a class meeting at different places at different times.
(b) There is no guarantee that the database does not have two classes meeting at
the same place and time.
4. Appropriate tables for each of the E-R diagrams used in exercises 1 to 3 are the
following:-
45
46
47