You are on page 1of 81

Data Base Management System -II

BCA-302

Dr. BhimRao Ambedkar University, Agra
Lets Get Back
What is data?
What is information?
What is a database?
What is DBMS?
Need of DBMS
Advantage of DBMS
Disadvantage of DBMS

DATA
Data are raw, facts and figures or a set of entities.

INFORMATION
Information is not a synonym of data. Infact, you
can have gigabytes of data, yet have no information.
The whole purpose of databases is to work with
information. Generally, data has little or no value. Or
we can say collection of data according to our need
and requirement makes information.

DATABASE
A database is an orderly collection of information.
Sales order, stock control or student records
systems are all examples of databases
A database categorizes information into logical
groups, which are physically stored in files called
tables.
A table is an orderly collection of records.
A record is a collection of fields.
For example: a book stores data, a web-page
stores data, etc., but they dont have well defined
structure. Databases store data according to the
defined metadata*
it is the structure of the database.


-A student record database holds details of students,
courses and staff-

Roll No Name Address
9712345 Amit Delhi

9682374 Deepak Agra

9754322 Gaurav Mathura

9567892 Neeraj Kanpur

6763333 Rohit Delhi

etc
Table
Records
Fields


Database Management System
It is a collection of computer programs that allow
storage, modification, and extraction of information
from a database. There are many different types of
DBMSs, ranging from small systems that run on
personal computers to huge systems that run on
mainframes.
Few examples of database applications: computerized
library systems, automated teller machines, flight
reservation systems, computerized parts inventory
system.
The examples of DBMS are MS-ACCESS, ORACLE,
SQL SERVER etc.

Need of DBMS (Database Management System):
The typical file processing systems have permanent record that
are stored in various files and are used to extract records and
to add new records to the particular file. In the file processing
system, hetre were number of major disadvantage
Data redundancy and inconsistency.
Difficulty in accessing data.
Integrity problem.
Atomicity Problem.
Concurrent access anomalies.
Security Problem.

Keeping organizational information in a file processing
system has a no. of disadvantages.

1-Data Redundancy And Inconsistency Since different
programs creates the files and application programs over a long
period, the various files are likely to have different structure and
the program may be written in several programming language.
For example - the address and telephone no. of a particular
customer may appear in a file that consist of seeing account
records and in a file that consists of checking account records.
This redundancy leads to higher storage and access cost.
In addition, it may leads to data inconsistency, that is, the various
copies of the same data may no longer agree.
2-Difficulty In Accessing Data- Suppose that one of the bank
officers needs to find out the name of all customers who lives in a
particular postal code area. The officers asks the data processing
department to generate such a list, because the designer of the
original system did not anticipate this request, there is no
application program on hand to meet it .There is, however, on
application program to generate the list of all customer .The bank
manager has now two choice either obtain the list of all customer
and extract the needed information manually or ask a system
programmer to write the necessary application program. Both
alternatives are obviously unsatisfactory.
3-Data Isolation- Because data are scattered in various files
&files may be in different formats, writing new application program
to retrieve the appropriate data is difficult.
4-Integrity Problems- The data values stored in the database may satisfy
certain types of consistency.
For example-the balance of certain types of bank accounts may never fall
below a prescribed amount ($25).The problem is compounded when
constraints involve several data items from different files.

5-Atomicity Problem- a computer system like any other mechanical or
electrical device is subject to failure. Consider a program to transfer $50 from
account a to account b. If a system failure occurs during the execution of the
program. It is possible that the $50 was removed from a/c a but was not
credited to a/c b, resulting in an inconsistent database state. Clearly, it is
essential to database state consistency that either both the credit and debit
occur or neither occur that is funds transfer must be atomic. It must happen in
its entirely or not to all. It is difficult to ensure atomicity in a conventional file-
processing system.

6-Concurrent-Access Anomalies-
For the sake of overall performance of the system and faster
response many system allow multiple users to update the data
simultaneously. Indeed, today, the largest internet retailers may
have million of access per day to their data by shoppers. In
such an environment interaction of concurrent updates is
possible and may result in inconsistent data. Consider bank a/c
A, containing $500. If two customers withdraw funds from a/c A
at the same time, the result of the concurrent execution may
leave the a/c in an incorrect state. If the two programs run
concurrently, they may both read the value $500 and write back
$450 and $400 respectively. But supervision is difficult to
provide because data may be accessed by many different
applications programs that have not been coordinated
previously.

7-Security Problem-
Not every user of the database system should be able to
access all the data.
For example- In a banking system, payroll personnel need to
see only that part of the database that has information about
the various bank employees. They do not need access to
information about customer accounts. But, since application
programs are added to the file processing system in a
manner. Enforcing such security constraints is difficult.

Advantage of DBMS (Database Management System):

One of the main advantages of using a database System is that organization
expert, DBA (Data Base Administrator) has centralized and control over the
data. The DBA (Data Base Administrator) is the focus of centralized controlled.
Any applications require a change in the structure of the data record require an
arrangement with the DBA (Data Base Administrator) who makes the necessary
modification.
Centralized controlled
Reduction of redundancy
Shared data
Integrity
Security
Data Independence
Reduction of redundancy: Centralized controlled of data by the
DBA(Data Base Administrator) avoids unnecessary duplication of data and
effectively reduce the total amount of data storage required . it also
eliminate the extra processing necessary to trace the required data in a
large body of data. Another advantage of avoiding duplication is the
elimination of the inconsistency that trend to be present in redundant data
file.

Shared Data: Database allows the sharing of data under its control by any
number of application program or user.

Integrity: Centralized control can also ensure that adequate checks are
incorporated in the DBMS (Data base Management) to provide data
integrity. The data integrity means that the data contain in the database is
both accurate and consistent. Therefore data values being entered for
storage could be checked to ensure that they fall with in a specific range
and one of the correct format. The value for the age of an employee may be
in the range of 16 and 75.
Security:
Data is of importance to an organization and may be confidential; such confidential
data must not be accessed by an unauthorized person. The DBA (Data Base
Administrator), who has ultimate responsibility for the data. In the DBMS can ensure
the proper access, procedures are followed. Including proper authentications scheme
for access to the DBMS and additional checks before permitting access to sensitive
data. Different level of security could be implemented for various type of data and
operation. The enforcement of security could be data value dependant.

Note: Over all structure of database known as schema.

Centralized controlled:
One of the main advantage of using a database system is that the organization can
have centralized control over the data. The DBA(Data Base Administrator ) controls
the data centrally. Any application requiring a change in the structure of a data record
requires an arrangement with the DBA(Data Base Administrator ),who makes the
necessary modification such modification do not effect on other application or user.


Data Independence: Data independence is the ability to modify
schema definition in one level without affecting the schema definition in
next higher level is called data independences. It is of two type:

(a) Physical data Independence

(b) Logical data Independence
Disadvantage with DBMS:

(A) Problem with centralized control

(B) Cost of Software, Hardware and migration.

(C) Problem with backup and recovery.

(D) Security should be needed.


Problem with centralized control:
Database undergo with problem of centralized control while centralization
reduce the redundancy, the lack of duplication requires proper backup so
that, in the case of failure the data can be recover. Centralization also mean
that data is accessible from a single source. This improve the problem of
overload on a single side.

Cost of Software, Hardware and migration:
A significant disadvantage of DBMS is the cost. In addition to the cost of the
software, hardware, work space(memory) require for the execution and
storage. The processing over hand introduce by the DBMS to implement
security, integrity and sharing of data, reduce the response time. The addition
cost is response time. The addition cost is require for a traditionally separate
application environment to an integrated one.







Problem with backup and recovery:
Centralization reduce duplication but we require backup of the data so that in
case of failure the data can be recovered. Backup and recovery operation are
fairly complex. In the DBMS environment and complicated with the multi-user
database system.


Security should be needed. The over head for providing concurrency
control and integrity constraints
Database Users


Different types of users:
1. Database administrators. Database administrators are experts who
manage the DBMS. The DBA is responsible for authorizing access to the
database, for coordinating and monitoring its use, and for acquiring software
and hardware resources as needed. The DBA is accountable for problems such
as security or poor system response time. In large organizations, the DBA is
assisted by a staff that helps carry out these functions.

2. Database Designers. Database Designers are responsible for
identifying the data to be stored in the database and for choosing appropriate
structures to represent and store this data.

3. End users. End users are the people whose jobs require access to the database for
querying, updating, and generating reports.

Casual users- Casual user access the DBMS with SQL queries. The term casual as
used here implies that the user has changing necessities from one session to the next,
so that it is not economical to try to write a menu-based program application for each
such casual use. Queries that are formulated on the spot to answer some immediate
need are known as interactive queries or ad hoc queries.

A naive user execute one of the permanent application programs that have been
written previously

Sophisticated end users. write specialized database applications that do not fit into the
traditional data processing framework. Sophisticated end users include engineers,
Scientists, business analysts.
DBA (data base administrator)
Centralized control over database maintained by the person or a group
under the supervision of a high-level administrator. This person is referred
to as database administrator. They are the user who are most recognizable
with database and responsible for creating, manipulating, buffering its three
level architecture. The DBA specify the external view of the various users
and is responsible for the definition of the inner level including the storage
formation and access method to be used for the optimum performance of
DBMS. Changes to any of the three level is controlled by the DBA.
The DBA is also responsible for defining procedures to recover the
database from failure due to human, natural, hardware. The function (role)
of the DBA include :-

Schema definition

Storage structure and admission method definition

Schema and physical organization alteration

Granting of authorization for data access

Integrity constraints (rules) specification

Regular maintenance (recovery of backup)
Schema Definition:- The DBA create the original database schema by
writing a set of definition that is translated by DDL (data definition language)
compiler to a set of table that is stored permanently in the data dictionary.

Storage structure and access method definition:-The DBA create
appropriate storage structure and access method by writing a set of
definition.

Schema and physical organization modification. The DBA carries out
changes to the schema and physical organisation to reflect the changing
needs of the organisation, in order to improve performance.

Granting of authorization for data access:- The granting of different
types of authorization allow the database administrator to regulate which
part of database various users can access. The authorization information is
kept in a central system structure, that the database system consults
whenever someone attempts to access the data in the system

Integrity constraints specification:-The data value stored in the database
must satisfy certain consistency constraints. That type of constraints is defined
by DBA .

Routine maintenance :- Some of its activities are
Periodically backing up the database, either on tape/remote servers.
Ensuring enough free memory space for normal operations.
Ensuring performance of the system by monitoring jobs running on the
database.
Schema
The overall design of database is called schema, The schema is the chart of the type
of data, it is a framed work in which the value of data can be fitted like the display at
airport authority given arrival and departure information. The schema will remain the
same while the value fitted into it can change time to time.

Sub- Schema: - Database system has several schema, partitioned according to the
level of abstraction; the physical schema describe the database design at physical
level while the logical schema describes the database at logical level. A database
may also have several schema at view level, some times called subschema. That
describes different views of the database.

Instances: - Database change over time as information is inserted or deleted. The
collection of information stored in the database at a particular moment is called an
instance of a database.
Database structure/abstraction
DBMS is the collection of inter-related data and a set of programs that allows
user to access and modifying these data. A major purpose of DBMS is to
provide users with an abstract view of data.
For the system usuable, it must retrieve data efficiently. So this need has led to
the design of complex data structure for the representation of data in database.
Since many database system users are not computer expert, developers hide
the complexity from the user through several levels of abstraction, to simplify
users interaction with the system.
The data base implemented through three general levels, i.e. , architecture of
DBMS (database management system).
Internal Level (Physical level)

Conceptual level (logical level)

External level(view level)

View-1

View -2

View-3

View-n

CONCEPTUAL
LEVEL
PHYSICAL
LEVEL
physical level
Logical level
External level
Physical/ Internal Level:- The lowest level of abstraction describes how the data are
actually stored. The physical level describes the complex low level data structure in
detail .The internal level is expressed by the internal schema which contain the definition
of the stored record the method of representing the data field. Eg. A customer, account,
or employee record can be described as a block of consecutive storage location(
word/bytes). The compiler hides this details from programmers.

Logical/ Conceptual level:- the next higher level of abstraction describe what the data
are stored in the database and what relationship exits among those data .The entire
database is described in term of a small number of relatively simple structure. The
conceptual or logical level is defined by the conceptual schema. It describes all the
records by a type definition and their relationship. It is complete database mode. DBA
usually work at this level.

External/ View level: - The highest level of abstraction describes only part of the entire
database. As many users of data base system will not be concerned with all the
database; instead they need to access only a part of the database so that they could
retrieve their information. At view level several view of the database are defined, and db
user view their view. In addition to hide details of the logical
level of the db, The views also provide a security mechanism
to prevent users from accessing certain part of the database.



Data Independence

Definition
Data independence is the ability to modify schema
definition in one level without affecting the schema
definition in next higher level is called data independences.

There are two levels of data independence.

1. Physical Data Independence.

2. Logical Data Independence.

Physical data independence
It is the ability to modify the physical schema without affecting the scheme
definition followed at conceptual level. Modification at the physical level are
occasionally done in order to improve the performance of the system.

Logical data independence
It is ability to modify the logical level without causing application programs to
rewritten. Modification of logical levels are necessary whenever the logical
structure of database is altered.
Ex. Changing data field of a table.
Logical data independence is more difficult to achieve than physical data
independence since application programs are heavily dependent on the logical
structure of the data that may access.
The concepts of data independence is similar to abstraction. As it only, allow
user to concentrate on the general structure rather than on low level
implementation /details.

Data Dictionary
The output of DDL is placed in meta data (data dictionary) i.e. data about data. The data
dictionary is considered to be a special type of table, which can only be accessed and
updated by the DBA. A db system consults the data dictionary before reading or
modifying actual data. A useful data dictionary should store and manage the following
type of information:
Description of the schemas of the db system.
Detailed information on physical database design, such as storage structure, access
path and file record sizes.
Description of the db user, their responsibilities and their access rights.
Descriptions of the db transaction.
The relationship between db transactions and the data items referenced by them.

DBMS language
A database management system provides two different
types of languages,
one to specify database schema
and other one to express the database query and
updates(major ones).
They are called as:

Data definition language (DDL).
Data manipulation language (DML).
Data Control Language (DCL)
Transaction Control Language(TCL)
DDL (data definition language )

A data base schema is specified by a set of definition expressed by a special
language called DDL. DBMS have a DDL compiler whose function is to process DDL
statement in order to identify description of the schema constraints and to store the
schema description in DBMS catalogue. The DDL is used to specify the conceptual
schema only. DDL is used to define both conceptual and external schema.
Some of its command are
CREATE, DROP, DELETE, ALTER etc

DML (data manipulation language)

User needs to manipulate the data like retrieve, insertion, deletion and modification
of the data.
So DML provides following activities

Retrieval of information stored on the database.
Insertion of new information into the database.
Deletion of information from the database.
Modification of information stored in the database.
DML is a language that enables user to access or manipulate data as organized by
the appropriate model. The DBMS provide a DML which is of two types.

Procedural DML.
Non Procedural DML.

Procedural DML: - Requires a user what data are needed and how to get those
data. This type of DML typically retrieves individual records from the database and
processes each separately. In this language, the looping, branching etc. statements
are used to retrieve and process each record from a set of records. Ex. PL-SQL .
Non Procedural DML or Declarative:- Requires a user to specify what data are
needed without specifying how to get those data. Usually a single statement is
given to the DBMS to retrieve or update multiple records.. The DBMS translates a
DML statement into a procedure that manipulates the set of records. Ex. SQL.
Data Control Language (DCL)
It is a computer language and a subset of SQL, used to control access to data in a
database.
Examples of DCL commands include:

GRANT to allow specified users to perform specified tasks.
REVOKE to cancel previously granted or denied permissions.

Transaction Control Language(TCL)
These statements are used to manage the changes made by DML statements. It
allows statements to be grouped together into logical transactions.

COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation level and what
rollback segment to use


Components / Structure of DBMS
A data base system is partitioned into modules that deal with each of the
responsibility of the overall system. The functional components of a database
system can be broadly classified into two components :
1. Storage manager
2. Query processor
Storage manager:
The storage manager is important because db requires generally large amount of
storage space. It generally consist of:
1) Authorization and integrity Manager: It tests for the satisfaction of integrity
constraints and check the authority of the user to access the data
2) Transaction Manager: It ensures that the db remains in a consistent state
(despite of power failure, concurrent access etc)
3) File manager: It manages the allocation of the space on the storage disk and the
data structure used to represent information.

4) Buffer manager: It is responsible for fetching the data from disk storage to the
main memory.
The storage manager implements separate data structures as part of the physical
system implementation.
a) Data Files: it stores the db itself.
b) Data dictionary: It stores the meta data.
c) Indices: It provides fast access to data item that hold particular value

Query Processor It helps the db system by simplifying and facilitating access to the
data. It includes:
DDL interpreter: It interprets the DDL statements and records the definition in
the data dictionary.
DML compiler: It translates DML statements(i.e. query language) into low level
instructions that the query evaluation engine understands.
Query Evaluation Engine which executes low level instruction generated by
DML compiler.



Data Model
A data model is a collection of concepts that can be used to describe the structure of a
database (i.e. data types, relationships, and constraints that should hold on the data).
Most data models also include a set of basic operations for specifying, retrievals and
updates on the database. Thus, one speaks of a relational DBMS, a network DBMS,
and so on, depending on the type of data model a DBMS supports. A data model is
collection of tools for describing
1. Data
2. Data relationships
3. Data semantics
4. Data constraints

Types of Data Models
There are two types of data models
1. Record based Data Models.
2. Object based Data Models.*

* Discuss later
1) Record based Data Models In this model, the database is organized in fixed-
format records of several types. A fixed number of fields, or attributes, are defined in
each record type, and each field is usually of a fixed length.
The three most popular record-based data models are
I) Relational Data Model
ii) Network Data Model*
iii) Hierarchical Data Model.*

Relational Data Model:-
It is a low level model. The relational model uses tables to represent the data and
the relationships among those data. Each table has multiple columns, and each
column is identified by a unique name.




SSN Name Address DEPT. NO
DEPT. NO. DEPT. NAME DEPT. ADDRESS
Here both the tables have a common key i.e. DEPT NO. These two tables can relate
with this column




* Discuss later
Advantages of Relational Data Model

Structural Independence Relational database model has structural independence,
in the database i.e. structure do not affect the DBMSs capability to access data.
Ease of designing, implementation and usage Due to the inherent features of
data independence and structural independence, and the relational model makes it
easy to design, implement, maintain and use the databases.
Simplicity The relational model is the simplest model at the conceptual level. It
allows the designer to concentrate on the logical view of the database, leaving the
physical data storage details
Adhoc query capability One of the main reasons for the popularity of the relational
database model is the presence of powerful, flexible and easy-to-use query capability.
The query language of the relational database model Structure Query Language or
SQL is a fourth generation language.
A 4GL concentrates on the what and not on the how of the problem. Selective output
can be achieved by giving a simple query. The relational database translates the user
queries into the code required to extract the desired information
Disadvantages of Relational Data Model

Hardware overheads The RDBMS needs comparatively powerful
hardware as it hides the implementation complexities and the physical data
storage details from the users.

Ease of design can result in bad design As the relational database is an
easy-to-design and use system, it can result in the development and
implementation of poorly designed database management systems. As the
size of the database increases, several problems may creep in system
shutdown, performance degradation and data corruption.
Entity Relationship model:-
The Entity-Relationship (ER) model was originally proposed by Peter in 1976 [Chen76]
as a way to unify the network and relational database views. Simply stated the ER
model is a conceptual data model that views the real world as entities and
relationships. An ER model is a diagram containing entities or "items", relationships
among them, and attributes of the entities and the relationships.

Entity
An entity is a real-world item or concept that exists on its own.. Some specific
examples of entities are EMPLOYEES, PROJECTS, and INVOICES. An entity is
analogous to a table in the relational model. In an ER model, we diagram an entity type
as a rectangle containing the type name, such as EMPLOYEE.


Entity set
An entity set is a set of entities of the same type that share the sane properties for
attribute. Eg: The set of all person who are customer of the same bank can be defined
as the entity set customer

EMPLOYEE
Attribute
Attribute is the property of entity. Attributes describe the entity of which they are
associated. For example, Employee has properties of its own Identification number,
name, and grade. In an ER model, an attribute name appears in an oval that has a line
to the corresponding entity box




Sometimes the value of an attribute is unknown or missing. In such cases, the attribute
can have the special value of null.
An attribute can be simple or composite. A simple attribute, such as Employee serial
no, is one component that is atomic. If we consider the name in three parts, last name,
middle name and first name, then the name attribute is a composite

Employee
Employee
Emp. Serial No.
Emp. Name
Last Name
Middle Name
First Name
Simple attribute
Composite Attribute
Employee
Emp. Name
Another way to classify attributes is either as single-valued or multi-valued. For an
entity an attribute, such as Employee Serial no., usually holds exactly one value,
such as E-101, and thus is a single-valued attribute. However, the project which an
employee handles may have two or more locations the projection location attribute for
the entity project is multi-valued. A multi-valued attribute has more than one value
for a particular entity. We illustrate this situation with a double oval around the project
location type.
Employee
Emp. Serial
No.
Project
Project location
Date of Birth.
Age
A derived attribute can be obtained from other attributes or related entities. For
example, the age of an employee can be determined from the date of birth. We request
the derived attribute with a dotted oval and line.
Employee
Drive Attribute
An attribute or set of attributes that uniquely identifies a particular entity is a key
attribute. Eg. Employee serial no. uniquely identifies all employees. In the ER diagram,
we underline the key attribute. Sometime a single attribute is not enough to identify
record uniquely, such a case we use Multiple (more than one) attributes as key attribute.
Employee
Name EmpSerial No.
First
Name
Middle
Name
Department
Last
Name
Key Attribute
Relationships and Structural Constraints
A relationship is an association among several entities .Each student is
assigned a roll_no, therefore, this an relationship. Anybody who does not
have roll_no is not the student of that particular college. Relationship is a set
of meaningful associations among entities. It is uniquely identifiable
association within a set.
A relation ship set is a mathematical relation on entities(n>=2), each taken
from entity sets {(e1,e2,.en) | e1 e E1, e2 e E2,., en e En }
where (e1,e2,.en) is a relationship.

Relationship Degree and Recursive Relationships
The degree of a relationship type is the number of participating entity types.
The role name signifies the role that a participating entity plays in a
relationship instance. In some cases, the same entity type participates more
than once in a relationship type in different roles. Such relationship types
are called recursive relationships





Constraints on Relationship Types
Cardinality ratios for Binary Relationships.
The cardinality ratio specifies the number of relationship instances that an entity can
participate in. The possible cardinality ratios for binary relationship types are 1:1, 1:N,
N:1, and M:N. Cardinality ratios for binary relationships are displayed on ER diagrams
by displaying 1, M, and N on the diamonds. The participation constraint specifies
whether the existence of an entity depends on its being related to another entity via the
relationship type. If an entity e can exist only if it participates in a relationship instance
r, the participation is called total participation (existence dependency). Otherwise the
participation is partial. In ER diagrams, total participation is displayed as a double line
connecting the participating entity type to the relationship, whereas participation is
represented by a single line. Cardinality ratio and participation constraints together are
referred as the structural constraints.



1. One to one: An entity in X is associated with at most one entity in Y, & an entity in Y
is associated with at most one entity in X.






X Y
2. One to many: An entity in X is associated with any number (zero or more) of entities
in Y. An entity in Y however can be associated with at most one entity in X
.







a1
a2
a3
a4

b1
b2
b3
b4

a1
a2
a3
a4

b1
b2
b3
b4

X Y
Mapping Cardinalities
It shows the number of entities to which other entity can be associated with a
relationship set. It is of the following types:-
3. Many to one: An entity in X is associated with at most one entity in Y. An entity in Y
however can be associated with any number (zero or more) of entities in X.







X Y

4. Many to many: An entity in X is associated with any number (zero or more) of
entities in Y & an entity in Y is associated with any number (zero or more) of entities
in X.
a1
a2
a3
a4

b1
b2


a1
a2
a3
a4

b1
b2
b3
b4


X Y
An E-R diagram can express the overall logical structure of a database graphically.
E-R diagram consist of the following major components:
1. Rectangles: which represent entity set

2. Ellipses: which represent attributes

3. Diamonds which represent relationship sets

4. Lines which link attributes to entity sets and entity sets to relationship sets.

5. Double Ellipses which represent multivalued attributes.

6. Dashed Ellipse which represents derived attributes.

7. Double Linear which denote total participation of an entity in a relationship set.

8. Double rectangle which represent weak entity set







Above fig shows two entity set customer and loan (with their attribute) related
through a binary relationship set borrower. Attributes of entity set that are the
members of the primary key are underlined.
The relationship set borrower may be many-to-many, one-to-many, many-to-one,
one-to-one.
i) A directed line from the relationship set borrower to the entity set loan specifies
that borrower is either a one-to-one or many-to-one relationship set, from
customer to loan; borrower cannot be many-to-many or a one-to-many
relationship set from customer to loan.

ii) An undirected line from the relationship set borrower to the entity set loan specifies
that borrower is either a one-to-many or many-to-many relationship set, from customer
to loan.
One to One Relationship
One to Many relationship
Many to One relationship







The degree of a relationship type is the number of entity types that participate. If a
relationship type has degree 2, which we call a binary relationship type. To clarify the
role that an entity plays in each relationship instance, we can label a connecting
edge with a role name that indicates the purpose of an entity in a relationship. For
example, we can have two binary relationship types associating the student and
team types, TeamMemberOf and LeaderOf. In the former case, a student entity is a
member of a team entity; in the later case, a student can be a leader of a team.
Many to Many relationship
A relationship type can also have attributes. The relationship type order connects
entities chemical and supplier. The relationship is many-to-many because each
chemical can be from several suppliers and each supplier has a number of
chemicals. An order has a purchase date, amount, and total cost as well as the
chemical and supplier information. Thus, order has attributes PurchaseDate,
amount, and TotalCost that we cannot appropriately associate with chemical or
supplier.
Weak Entity Types
Entity types that do not have key attributes of their own are called weak entity
types. Entities of a weak entity type are identified by being related to specific
entities of another entity type in combination with some of their attribute
values. We call this other entity type the identifying or owner entity type,
and we call the relationship the identifying relationship of the weak entity
type. A weak entity type normally has a partial key (sometimes called
discriminator), which can uniquely identify weak entities. In ER diagrams,
both a weak entity type and its identifying relationship are distinguished by
surrounding their boxes with double lines. The partial key is underlined with a
dashed or dotted line.
In short an entity set that does not possess sufficient attributes to form a
primary key is called a weak entity set. One that does have a primary key is
called a strong entity set. For a weak entity set to be meaningful, it must be
part of a one-to-many relationship set.

The use of double line indicates the participation of weak entity set (payment) in this
relationship (payment) is total.
Generalization
A bottom-up design process combine a number of entity sets that share the
same features into a higher-level entity set. Generalization hides differences and
emphasizes similarities. Distinction made through attribute inheritance. Attributes of
higher-level entity are inherited by lower-level entities.
Consider extending the entity set account by classifying accounts as being either
savings-account or chequing-account. Each of these is described by the attributes of
account plus additional attributes (savings has interest-rate and chequing has
overdraft-amount.) We can express the similarities between the entity sets by
generalization.

Aggregation
The E-R model cannot express relationships among relationships. When would we need such a
thing? Consider a DB with information about employees who work on a particular project and
use a number of machines doing that work. We get the E-R diagram shown in Figure
Relationship sets work and uses could be combined into a single set. However, they
shouldn't be, as this would obscure the logical structure of this scheme.The solution is to
use aggregation. An abstraction through which relationships are treated as higher-level
entities. For our example, we treat the relationship set work and the entity sets
employee and project as a higher-level entity set called work.
Transforming an E-R diagram with aggregation into tabular form is easy. We create a
table for each entity and relationship set as before. The table for relationship set uses
contains a column for each attribute in the primary key of machinery and work.
Figure shows the E-R diagram with aggregation
Q1) Construct an E-R diagram for a car insurance company whose customer
own one or more cars each. Each car has zero to any no of recorded accidents
Q1) Consider a database used to record the marks that student get in different
exams of different course offerings.
a) Construct an E-R diagram that models exams as entities, and uses a ternary
relationship for the database
Construct an E-R diagram that models library system
Construct an E-R diagram that models hospital system
Banking system
CREATE - To make a new. database, table, index, or stored query

CREATE TABLE [table name] ( [column definitions] ) [table parameters].

Column Definitions [column name] [data type] {NULL | NOT NULL} {column options}

CREATE TABLE employees ( id INTEGER PRIMARY KEY, first_name CHAR(50)
NULL, last_name CHAR(75) NOT NULL, dateofbirth DATE NULL );

Where CHAR, INTEGER, ETC. are built-in data types.



After a table is created, we can use the INSERT statement to add tuples into the
table

INSERT INTO EMPLOYEE VALUES ('Amit', 'Kumar', 'gupta', 'E101', '1985-01-
08,'168 Ram Nagar, Agra', M, 50000, '1044');

We can modify an existing tuple using the UPDATE statements:

UPDATE EMPLOYEEE SET E.SALARY = E.SALARY + 3000
WHERE E.SSN = 123456789;

To delete a tuple, we use the DELETE command:

DELETE FROM EMPLOYEE E WHERE E.SSN = 123456789;



Integrity Constraints
In the create table command, additional constraints (Like- Not Null , Primary key,
foreign Key, Unique) can be specified. The following is an example.
CREATE TABLE EMPLOYEE (
FNAME CHAR(15) NOT NULL,
MNAME CHAR(14),
LNAME CHAR(15) NOT NULL,
SSN VARCHAR(9) NOT NULL,
BDATE DATE,
ADDRESS VARCHAR(30),
SEX CHAR,
SALARY DECIMAL(10,2),
DNO INTEGER NOT NULL,
PRIMARY KEY (SSN),
FOREIGN KEY (DNO) REFERENCES DEPARTMENT(DNUMBER)
);
Drop - To destroy an existing database, table, index, or view.

DROP object type objectname

DROP TABLE employees;

ALTER - alters the structure of the database

SYNTAX:
ALTER TABLE table_name <ADD column_name data_type;
MODIFY column_name data_type;>

The following is an example:
ALTER TABLE COMPANY.EMPLOYEE ADD JOB VARCHAR(12);
CREATE VIEW

This statement defines a virtual table (a named relation), using SELECT clauses to
define a relation which may not really exist in the data base. Such a table may contain
virtual columns holding computed values. The VIEW facility has three major uses:

To give the data base administrator power to enforce privacy constraints.
To define a (complex) query for use in further queries.
To supply a convenient interface for users who would not be capable of generating
their own queries.

For example, to create a view of the patient table consisting only of female patients:
CREATE VIEW male_patients AS
SELECT * FROM patient WHERE gender = 'M'

Note--- VIEW definitions are destroyed using DROP.
Non Procedural data manipulation language require a user to specify what
data are needed without knowing how to get those data The preceding type
of languages are usually non- consider different languages a
comprehensive integrated languages is used that include constructs for the
conceptual definition, view definition and data manipulation. Storage
definition is kept separate a typical example of comprehensive database
language is SQL (Structure query language) which represents a
combination of DDL and DML as well as the constraints specification.

SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space
for the records remain
MERGE - UPSERT operation (insert or update)