0% found this document useful (0 votes)
24 views91 pages

Unit 1

The document provides an introduction to Database Management Systems (DBMS), defining key concepts such as databases, data, and mini-worlds. It outlines various applications of DBMS across different sectors, advantages over traditional file systems, and the importance of data integrity, security, and recovery. Additionally, it covers data models, database languages, and the roles of database users and administrators.
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)
24 views91 pages

Unit 1

The document provides an introduction to Database Management Systems (DBMS), defining key concepts such as databases, data, and mini-worlds. It outlines various applications of DBMS across different sectors, advantages over traditional file systems, and the importance of data integrity, security, and recovery. Additionally, it covers data models, database languages, and the roles of database users and administrators.
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/ 91

Database Management Systems

Introduction to Databases and Database


Management System

Unit – 1

Dr. D. Sudheer
Assistant Professor
Department of CSE
VNR VJIET

DBMS PPT © Dr. D. SUDHEER 1


DBMS PPT © Dr. D. SUDHEER 2
Introduction

• Database: A collection of related data. (Phone


Numbers)
• Data: Known facts that can be recorded and have an
implicit meaning.
• Mini-world: Some part of the real world about
which data is stored in a database. For example,
student grades and transcripts at a university.
• Database Management System (DBMS): A software
package/ system to facilitate the creation and
maintenance of a computerized database.

DBMS PPT © Dr. D. SUDHEER 3


Database-System Applications

• Enterprise Information
❖ Sales: For customer, product, and purchase
information.
❖ Accounting: For payments, receipts, account
balances, assets and other accounting information.
❖ Human resources: For information about
employees, salaries, payroll taxes, and benefits, and
for generation of paychecks.
❖ Manufacturing: For management of the supply
chain and for tracking production of items in
factories, inventories of items in warehouses and
stores, and orders for items.
❖ Online retailers: For sales data noted above plus
online order tracking, generation
DBMS PPT © Dr. D. SUDHEER
of 4
recommendation lists, and maintenance of online
• Banking and Finance
❖ Banking: For customer information, accounts, loans,
and banking transactions.
❖ Credit card transactions: For purchases on credit
cards and generation of monthly statements.
❖ Finance: For storing information about holdings,
sales, and purchases of financial instruments such as
stocks and bonds; also for storing real-time. market
data to enable online trading by customers and
automated trading by the firm.
• Universities:
❖ For student information, course registrations, and
grades (in addition to standard enterprise
information such as human resources and
accounting)
DBMS PPT © Dr. D. SUDHEER 5
• Airlines: For reservations and schedule information.
Airlines were among the first to use databases in a
geographically distributed manner.
• Telecommunication: For keeping records of calls
made, generating monthly bills, maintaining balances
on prepaid calling cards, and storing information
about the communication networks.

DBMS PPT © Dr. D. SUDHEER 6


Advantages of DBMS over File
system
• File System: The file management system is also a
database management system where data is stored in
the form of files. It is an old traditional way to store the
data in the files. Each file does not have any relation
with other files. Tables are stored in the files, and
sometimes only a single table is stored in a file which is
also known as a flat file.
• DBMS: DBMS stands for Database Management System,
which is a tool, or a software used for the creation,
deletion, and manipulation of the data in the database.
DBMS helps users to insert new data sets into the
existing database or delete some data from the
database. DBMS allows users to share the database,
which means multiple users can access the database7
DBMS PPT © Dr. D. SUDHEER
and use its data. DBMS also makes sure that the data
• Data Redundancy and Inconsistency: Redundancy
means repeating the data in a system. In a normal file
system, there is a high chance that there can be
various files of the same data used by different users
for specific purposes. If any user changes the data in
its files, then the changes are not reflected in all files.
This creates inconsistency in the data, and it may lead
to the failure of the system.
But in the DBMS, there is only one repository of data,
and multiple users can use it. If any user changes the
data, then it is reflected to each user as they are using
the same repository.
• Data Sharing: In the normal file system, data sharing
is too difficult because file sharing is a complex task.
In DBMS, all the data is centralized, so data sharing is a
very easy task. DBMS PPT © Dr. D. SUDHEER 8
• Data Concurrency: When more than one user accesses
the database simultaneously, then it is called
concurrency. In a file system, when multiple users are
using the files at the same time, then there may be a
chance of anomalies in the data due to changes, and it
does not provide any method to detect anomalies.
But in DBMS, we have a locking system to detect the
anomalies so we can protect the data.
• Data Searching: To search the data in a file system, we
have to write a specific program and run it.
In DBMS, we have query languages by which we can
write small queries to get the data we want from the
database. We can use various query languages, like
MySQL, Oracle, etc., for a database to search and
retrieve the data.
DBMS PPT © Dr. D. SUDHEER 9
• Data Integrity: When we insert new data into the
database, we require some specific constraints on the
data like integer or not null, etc. The file system does not
provide any system to check the constraints.
whereas DBMS has the functionality to check the
constraints on the data, and it allows user defined data
types.
• System Crashing: There are various reasons by which
our system can crash. Once a system crashes, the file
system loses all its files and data, and we can not recover
it again.
But DBMS has a recovery manager which can recover
the data if the system crashes.
• Data Security: In the file system, we have only
password protection to save the files and data, but it is
not reliable. In DBMS, we have special algorithms and
features to secure the data. DBMS PPT © Dr. D. SUDHEER 10

• Backup: For the backup of data, DBMS creates a


Views of Data

• A database system is a collection of interrelated data


and a set of programs that allow users to access and
modify these data.
• A major purpose of a database system is to provide
users with an abstract view of the data.
• The system hides certain details of how the data are
stored and maintained.
Data abstraction
Complexity is hidden by the developers from the
users through several levels of abstractions.

Physical level
Logical level
View level
DBMS PPT © Dr. D. SUDHEER 11
Physical level
How the data are stored.
Data base administrators will be aware of certain
details collected from the data base programmers.
Lowest level of abstraction.

Logical level
What data is stored in the database and what
relationship exist among those data.
Here each record is describe by the type
definition and the interrelationship among all the
records.
Programmers & data administrators works at this
level.
Second level of abstraction. DBMS PPT © Dr. D. SUDHEER 12
View level
⚫ This is the highest level of abstraction which
describes only a part of the entire program.
⚫ The system may provide many views from the same
database.
⚫ Application programs hide details of data types.
⚫ Views can also hide information for security
purposes.
⚫ Database users will see these views.
Instances and Schemas
• The overall design of the database is called the
database schema.
• The collection of information stored in the database
at a particular moment is called an instance

DBMS PPT © Dr. D. SUDHEER 13


SubSchemas

DBMS PPT © Dr. D. SUDHEER 14


Example Record

type instructor = record

ID : char (5);
name : char (20);
dept name : char (20);
salary : numeric (8,2);

end;

DBMS PPT © Dr. D. SUDHEER 15


Data models
It is the structure of a data base
It is the collection of describing data, data
relationships , and consistency constraints
These are classified as 4 categories
Relational models
Collection of tables to represent both data and
relationship among those tables.

DBMS PPT © Dr. D. SUDHEER 16


Entity-relationship model (E-R models)

These are the collection of objects called entities


and relationship among these objects.

DBMS PPT © Dr. D. SUDHEER 17


Object-based data model
The development of an object-oriented data model that
can be seen as extending the E-R model with notions
of encapsulation, methods (functions), and object
identity

DBMS PPT © Dr. D. SUDHEER 18


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.
(Ex: XML)

DBMS PPT © Dr. D. SUDHEER 19


Historically, the network data model and the
hierarchical data model preceded the relational data
model. These models were tied closely to the
underlying implementation, and complicated the task
of modeling data.

DBMS PPT © Dr. D. SUDHEER 20


Database Languages- DDL & DML
⚫ A DBMS has appropriate languages and
interfaces to express database queries and
updates.
⚫ Database languages can be used to read, store
and update the data in the database.

DBMS PPT © Dr. D. SUDHEER 21


1. Data Definition Language

⚫ DDL stands for Data Definition Language. It is


used to define database structure or pattern.

⚫ It is used to create schema, tables, indexes,


constraints, etc. in the database.

⚫ Using the DDL statements, you can create the


skeleton of the database.

⚫ Data definition language is used to store the


information of metadata like the number of tables
and schemas, their names, indexes, columns in
each table, constraints, etc.
DBMS PPT © Dr. D. SUDHEER 22
⚫ Here are some tasks that come under DDL:
◦ Create: It is used to create objects in the database.
◦ Alter: It is used to alter the structure of the
database.
◦ Drop: It is used to delete objects from the database.
◦ Truncate: It is used to remove all records from a
table.
◦ Rename: It is used to rename an object.
◦ Comment: It is used to comment on the data
dictionary.

DBMS PPT © Dr. D. SUDHEER 23


Important constraints for DDL
Consistency Constraints: Ex. Account balance of
department must never negative.
Domain Constraints: A domain of possible values
must be associated with every attribute (Ex. Integer,
Char, Date).
Referential Integrity: There are cases where we wish
to ensure that a value that appears in one relation for
a given set of attributes also appears in a certain set of
attributes in another relation.
Assertions: An assertion is any condition that the
database must always satisfy. Domain constraints and
referential-integrity constraints are special forms of
assertions. However, there are many constraints that
we cannot express by using only these special forms.
Authentication: We may want to differentiate among
the users as far as the type of access DBMS PPT © Dr.they
D. SUDHEERare 24

permitted on various data values in the database.


• Notice that the "PersonID" column in the "Orders"
table points to the "PersonID" column in the
"Persons" table.

DBMS PPT © Dr. D. SUDHEER 25


2. Data Manipulation Language
⚫ DML stands for Data Manipulation Language.
It is used for accessing and manipulating data
in a database. It handles user requests.
⚫ Here are some tasks that come under DML:
◦ Select: It is used to retrieve data from a
database.
◦ Insert: It is used to insert data into a table.
◦ Update: It is used to update existing data
within a table.
◦ Delete: It is used to delete all records from a
table.
◦ Merge: It performs UPSERT operation, i.e.,
insert or update operations.
◦ Call: It is used to call a structured query
language or a Java subprogram. DBMS PPT © Dr. D. SUDHEER 26

◦ Explain Plan: It has the parameter of


3. Data Control Language

⚫ DCL stands for Data Control Language. It is


used to retrieve the stored or saved data.
⚫ The DCL execution is transactional. It also has
rollback parameters.
⚫ Here are some tasks that come under DCL:
◦ Grant: It is used to give user access privileges
to a database.
◦ Revoke: It is used to take back permissions
from the user.

DBMS PPT © Dr. D. SUDHEER 27


4. Transaction Control Language

⚫ TCL is used to run the changes made by the


DML statement. TCL can be grouped into a
logical transaction.
⚫ Here are some tasks that come under TCL:
◦ Commit: It is used to save the transaction on
the database.
◦ Rollback: It is used to restore the database to
original since the last Commit.

DBMS PPT © Dr. D. SUDHEER 28


Database Users and Administrators
• Database can be categorized as database users or
database administrators.
• There are four different types of database-system
users, differentiated by the way they expect to interact
with the system.
• Different types of user interfaces have been designed
for the different types of users.

Naıve users are unsophisticated users who


interact with the system by invoking one of the
application programs that have been written
previously.

Application programmers are computer


professionals who write application programs.29
DBMS PPT © Dr. D. SUDHEER
Application programmers can choose from many
Sophisticated users interact with the system without
writing programs. Instead, they form their requests
either using a database query language or by using
tools such as data analysis software.

Specialized users are sophisticated users who write


specialized database applications that do not fit into the
traditional data-processing framework.

Database Administrator
One of the main reasons for using DBMSs is to have
central control of both the data and the programs that
access those data. A person who has such central
control over the system is called a database
administrator (DBA).
DBMS PPT © Dr. D. SUDHEER 30
DBA controls below opoerations:
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.
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.

DBMS PPT © Dr. D. SUDHEER 31


Routine maintenance.
Periodically backing up the database
Ensuring that enough free disk space is available
Monitoring jobs running on the database and
ensuring the performance

DBMS PPT © Dr. D. SUDHEER 32


DBMS PPT © Dr. D. SUDHEER 33
Database Design and E-R Diagrams

• The high level data model provides the database


designers with conceptual framework to specify the
requirements of the users.
• The designers will characterize to fulfill these
requirements.
• The designers need to interact with domain experts
and users to carryout this task.
• The designer can also examine the design to remove
any redundant features.

DBMS PPT © Dr. D. SUDHEER 34


Design phases:

1. Representing Requirements
2. Conceptual Design
3. Specifications of Functional Requirements
4. Logical Design Phase
5. Physical Design Phase

DBMS PPT © Dr. D. SUDHEER 35


Design phases:

1. Representing Requirements
2. Conceptual Design
3. Specifications of Functional Requirements
4. Logical Design Phase
5. Physical Design Phase

Conceptual Design
The Designer choose the data model and translates the
requirements to conceptual schema of chosen model.

DBMS PPT © Dr. D. SUDHEER 36


Design phases:

1. Representing Requirements
2. Conceptual Design
3. Specifications of Functional Requirements
4. Logical Design Phase
5. Physical Design Phase
Specifications of Functional
Requirements
The fully developed conceptual schema also indicates
the functional requirements of the enterprise. Like
operations of users (modifying, updating and
searching etc.)

DBMS PPT © Dr. D. SUDHEER 37


Design phases:

1. Representing Requirements
2. Conceptual Design
3. Specifications of Functional Requirements
4. Logical Design Phase
5. Physical Design Phase

Logical Design Phase


In this phase mapping the conceptual schema like E-R
model into Relational model by implementing on
database system.

DBMS PPT © Dr. D. SUDHEER 38


Design phases:

1. Representing Requirements
2. Conceptual Design
3. Specifications of Functional Requirements
4. Logical Design Phase
5. Physical Design Phase

Physical Design Phase


Physical design phase specifies the physical features of
the database like file organization and choice of index
structure, etc.

DBMS PPT © Dr. D. SUDHEER 39


In designing a database schema, we must ensure
that we avoid two major pitfalls:

Redundancy: A bad design may repeat information.

Incompleteness: A bad design may make certain


aspects of the enterprise difficult or impossible to
model.

DBMS PPT © Dr. D. SUDHEER 40


The Entity-Relationship Model

• The entity-relationship (E-R) data model was developed


to facilitate database design by allowing specification of
an enterprise schema that represents the overall logical
structure of a database.
• Many database-design tools draw on concepts from the
E-R model.
• The E-R data model employs three basic concepts:
entity sets, relationship sets, and attributes.
Entity Sets

• An entity is a “thing” or “object” in the real world that


is distinguishable from all other objects.
• For example, each person in a university is an entity.

DBMS PPT © Dr. D. SUDHEER 41


• An entity has a set of properties, and the values for
some set of properties may uniquely identify an entity.
• An entity may be concrete, such as a person or a book,
or it may be abstract, such as a course, a course
offering, or a flight reservation.
• An entity set is a set of entities of the same type that
share the same properties, or attributes. The set of all
people who are instructors at a given university, for
example, can be defined as the entity set instructor.
• Entity sets do not need to be disjoint. For example, it is
possible to define the entity set of all people in a
university (person). A person entity may be an
instructor entity, a student entity, both, or neither.

DBMS PPT © Dr. D. SUDHEER 42


An entity is represented by a set of attributes.
Attributes are descriptive properties possessed by
each member of an entity set.

DBMS PPT © Dr. D. SUDHEER 43


Relationship Sets

• A relationship is an association among several entities.


• A relationship set is a set of relationships of the same
type.
• Mathematically a relation on n greater than or equal
to 2 entities.
• If E1,E2,…En are entity sets.

R
(relation
)

DBMS PPT © Dr. D. SUDHEER 44


Consider the two entity sets instructor and student, we
define relationship set advisor to denote the
association between instructors and students.

DBMS PPT © Dr. D. SUDHEER 45


Recursive Relationship in ER Diagram:
• Relationship form an entity of the same entity type to another entity
of the same entity type it becomes the Recursive relation in DBMS.

In a company there are many employees, an


employee can be a developer, manager, CEO, etc. All
the developers (who are employees) are managed by
the manager (who is also an employee) means an
employee manages other employees. DBMS PPT © Dr. D. SUDHEER 46
A relationship may also have attributes called
descriptive attributes.

DBMS PPT © Dr. D. SUDHEER 47


Degree of Relationship sets:

• The number of entity sets that participate in a


relationship set is the degree of the relationship set.
• Unary
• Binary
• Ternary Unary degree=1
• N-ary

DBMS PPT © Dr. D. SUDHEER 48


Binary degree=2

Ternary degree=3

DBMS PPT © Dr. D. SUDHEER 49


N-ary degree>3

DBMS PPT © Dr. D. SUDHEER 50


Attributes

• For each attribute, there is a set of permitted values,


called the domain, or value set, of that attribute.
• Ex: The domain of attribute course id might be the set
of all text strings of a certain length.

Attribute Types:
Simple and composite
Single-valued and multi-valued
Derived attribute

DBMS PPT © Dr. D. SUDHEER 51


Simple: Simple attributes have not been divided into
subparts.
(Ex. ID, course, etc.)
Composite: Attributes can be divided into subparts.
(Ex. Name: First name, Middle name, Last Name)
Single valued: Consists single value for a particular
entity.
(Ex. Student_ID, Subject_ID, etc.)
Multi valued: There may exists multiple values for
single entity.
Ex. {Phone_Number}
To denote that an attribute is multivalued, we enclose it
in braces{}.

DBMS PPT © Dr. D. SUDHEER 52


Derived attribute: The value for this type of attribute
can be derived from the values of other related
attributes or entities.

Ex. Instructor_advised this attribute value can be


derived by counting number of students advised by
instructor.
Ex2. calculate age from DOB.

An attribute takes a null value when an entity does not


have a value for it. The null value may indicate “not
applicable”— that is, that the value does not exist for
the entity.

DBMS PPT © Dr. D. SUDHEER 53


Constraints
Domain Constraints: Domain is set of acceptable
values for each attribute. Dom(A) represents the
atomic value of attribute A. Data type associates with
attributes define domain constraints. Check
constraints also used to define domain constraints.

Key constraints: Primary key, candidate key,


alternative keys and unique.

Entity Integrity Constraints or Referential Integrity


Constraints

Ex: Using foreign key by referring parent relation it


can be achieved. DBMS PPT © Dr. D. SUDHEER 54
E-R Constraints

1. Mapping Cardinalities or Cardinality ratios:


express the number of entities to which another entity
can be associated via a relationship set.
For a binary relationship set R between entity sets A
and B, the mapping cardinality must be one of the
following:

One-to-one. An entity in A is associated with at most


one entity in B, and an entity in B is associated with at
most one entity in A.

One-to-many.An entity in A is associated with any


number (zero or more) of entities in B. An entity in B,
however, can be associated with at most one entity in55
DBMS PPT © Dr. D. SUDHEER

A.
a. one-to-one and b. one-to-many

DBMS PPT © Dr. D. SUDHEER 56


Many-to-one. An entity in A is associated with at most
one entity in B. An entity in B, however, can be
associated with any number (zero or more) of entities
in A.
Many-to-many. An entity in A is associated with any
number (zero or more) of entities in B, and an entity in
B is associated with any number (zero
Many-to-one Many-to-
or more) of
entities in A. many

DBMS PPT © Dr. D. SUDHEER 57


2. Participation Constraints:

Total: If every entity in E participates in at least one


relationship in R.

Partial: If only some entities in E participate in


relationships in R.

3. Keys
• We must have a way to specify how entities within a
given entity set are distinguished.
• The entities must be identified uniquely by values of
attributes.
• No two entities in an entity set are allowed to have
exactly the same value for all attributes.
• A key for an entity is a set of attributes that suffice to
DBMS PPT © Dr. D. SUDHEER 58
distinguish entities from each other.
Super Key:

• We can define a super key as a set of those keys that identify a row
or a tuple uniquely.
• It is the superset where the candidate key is a part of the super key
only

DBMS PPT © Dr. D. SUDHEER 59


Candidate key: It is a minimal super key.
rules
no proper subset of super key should be a super key.
It must contain unique values.
It can contain NULL values.
It must contain unique values.
It can contain NULL values.

DBMS PPT © Dr. D. SUDHEER 60


Candidate key: It is a minimal super key.
rules
no proper subset of super key should be a super key.
It must contain unique values.
It can contain NULL values.
It must contain unique values.
It can contain NULL values.

{STUD_NO},{SNAME},{PHONE} are candidate keys


DBMS PPT © Dr. D. SUDHEER 61
DBMS PPT © Dr. D. SUDHEER 62
Primary Key:
A primary key in a table that uniquely identifies each
row and column or set of columns in the table. The
primary key is an attribute or a set of attributes that
help to uniquely identify the tuples(records) in the
relational table.
Rules:
Minimal: The primary key is composed of a minimum
number of attributes that satisfy the unique
occurrence of the tuples or records.
Accessible: The primary key is used to check the
ability to access and interact with the database.
NON NULL Value: The primary key which refers to a
nonnull value that is required for the identification of
the tuple (record).
Time Invariant: The values of the primary key must63
DBMS PPT © Dr. D. SUDHEER
not change or become null during the lifetime of the
Alternate key or secondary key: The candidate key
other than the primary key is called an alternate key.
DBMS PPT © Dr. D. SUDHEER 64
Foreign key:
• If an attribute can only take the values which are
present as values of some other attribute, it will be a
foreign key to the attribute to which it refers.
• It is a key it acts as a primary key in one table and it
acts as
secondary key in another table.

DBMS PPT © Dr. D. SUDHEER 65


Composite key: Sometimes, a table might not have a
single column/attribute that uniquely identifies all the
records of a table. To uniquely identify rows of a table,
a combination of two or more columns/attributes can
be used.

It acts as a primary key if there is no primary key in a


table.

DBMS PPT © Dr. D. SUDHEER 66


Entity-Relationship
Diagrams
An E-R diagram can express the overall logical
structure of a database graphically.

• Rectangles divided into two parts represent entity sets.


The first part, which in this textbook is shaded blue,
contains the name of the entity set. The second part
contains the names of all the attributes of the entity set.
• Diamonds represent relationship sets.

DBMS PPT © Dr. D. SUDHEER 67


• Undivided rectangles represent the attributes of a relationship set.
Attributes that are part of the primary key are underlined.
• Lines link entity sets to relationship sets.
• Dashed lines link attributes of a relationship set to the relationship set.
• Double lines indicate total participation of an entity in a relationship
set.
• Double diamonds represent identifying relationship sets linked to
weak entity sets

E-R diagram with an attribute attached to a


relationship set.
DBMS PPT © Dr. D. SUDHEER 68
Relationships. (a) One-to-one. (b) One-to-many. (c) Many-to-many.

DBMS PPT © Dr. D. SUDHEER 69


Mapping
Cardinality

Role
s indicate roles in E-R diagrams by labeling the lines
We
that connect diamonds to rectangles.

DBMS PPT © Dr. D. SUDHEER 70


Alternative Notation for
Cardinality Limits

DBMS PPT © Dr. D. SUDHEER 71


Complex Attributes:

DBMS PPT © Dr. D. SUDHEER 72


Weak entity sets
An entity set that does not have sufficient attributes to
form a primary key is termed a weak entity set. An
entity set that has a primary key is termed a strong
entity set.

Owner entity set and weak entity set must participate


in a one-to-many relationship set (one owner, many
weak entities).

Weak entity set must have total participation in this


identifying relationship set.

DBMS PPT © Dr. D. SUDHEER 73


DBMS PPT © Dr. D. SUDHEER 74
Database design for a schema
Represent a database that conforms to an E-R database
schema by a collection of relation schemas.

Both the E-R model and the relational database model


are abstract, logical representations of real-world
enterprises.

Representation of Strong Entity Sets with Simple


Attributes:

DBMS PPT © Dr. D. SUDHEER 75


DBMS PPT © Dr. D. SUDHEER 76
Representation of Strong Entity Sets with Complex
Attributes

DBMS PPT © Dr. D. SUDHEER 77


Representation of Weak Entity Sets

Strong entity set B -> {b1,b2,..bn} as primary key attributes.

Week entity set A ->{a1,a2,..an} as descriptor attributes.

DBMS PPT © Dr. D. SUDHEER 78


Primary key constraints relational schema R:
• For a binary many-to-many relationship, the union of
the primary-key attributes from the participating
entity sets becomes the primary key.
• For a binary one-to-one relationship set, the primary
key of either entity set can be chosen as the primary
key. The choice can be made arbitrarily.
• For a binary many-to-one or one-to-many relationship
set, the primary key of the entity set on the “many”
side of the relationship set serves as the primary key.
• For an n-ary relationship set without any arrows on
its edges, the union of the primary key-attributes from
the participating entity sets becomes the primary key.
• For an n-ary relationship set with an arrow on one of
its edges, the primary keys of the entity sets not on the
“arrow” side of the relationship set serve as the
DBMS PPT © Dr. D. SUDHEER 79
primary key for the schema.
We also create foreign-key constraints on the relation
schema R as follows:
For each entity set in relation R, we can create foreign
key constraint with attributes which are derived from
primary key attributes.

DBMS PPT © Dr. D. SUDHEER 80


Alternative ER notations

DBMS PPT © Dr. D. SUDHEER 81


DBMS PPT © Dr. D. SUDHEER 82
Extended ER Features

Specialization/generalization

Specialization: A means of identifying sub-groups within an entity


set which have attributes that are not shared by all the entities (top-
down).
Generalization: Multiple entity sets are synthesized into a higher-
level entity set, based on common features (bottom-up).

DBMS PPT © Dr. D. SUDHEER 83


Constraints on specialization/generalization

Disjoint: The disjoint constraint only applies when a superclass has


more than one subclass. If the subclasses are disjoint, then an entity
occurrence can be a member of only one of the subclasses, e.g.
postgrads or undergrads – you cannot be both.

DBMS PPT © Dr. D. SUDHEER 84


Overlapping: This applies when an entity occurrence may be a
member of more than one subclass, e.g. student and staff – some
people are both. ‘And’ is used to represent the overlapping
specialization/generalization relationship in the ER diagram.

DBMS PPT © Dr. D. SUDHEER 85


Total: Each superclass (higher-level entity) must belong to
subclasses (lower-level entity sets), e.g. a student must be
postgrad or undergrad. To represent completeness in the
specialization/generalization relationship, the keyword
‘Mandatory’ is used.

DBMS PPT © Dr. D. SUDHEER 86


Partial: Some superclasses may not belong to subclasses (lower-
level entity sets), e.g. some people at UCT are neither student nor
staff. The keyword ‘Optional’ is used to represent a partial
specialization/generalization relationship.

DBMS PPT © Dr. D. SUDHEER 87


DBMS PPT © Dr. D. SUDHEER 88
DBMS PPT © Dr. D. SUDHEER 89
Data Types in Oracle:

DBMS PPT © Dr. D. SUDHEER 90


Basic Structure of SQL Query

The basic structure of an SQL query consists of three


clauses: select, from, and where.

The query takes as its input the relations listed in the


from clause, operates on them as specified in the
where and select clauses, and then produces a
relation as the result.

We can eliminate the duplicates in results by insert


the keyword distinct after select.

DBMS PPT © Dr. D. SUDHEER 91

You might also like