0% found this document useful (0 votes)
40 views35 pages

Introduction To Data Base

The document provides an introduction to databases, including definitions of key terms like database, database management system, and data hierarchy. It describes characteristics of DBMS like using real-world entities, normalization to reduce redundancy, support for queries, and security features. It also outlines different types of users that interact with a DBMS.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views35 pages

Introduction To Data Base

The document provides an introduction to databases, including definitions of key terms like database, database management system, and data hierarchy. It describes characteristics of DBMS like using real-world entities, normalization to reduce redundancy, support for queries, and security features. It also outlines different types of users that interact with a DBMS.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

INTRODUCTION TO DATABASE

- Specific objectives:
The module will enable the student to:
Master general notions about banking information systems, databases,
database
management systems, the relational model, implement a data base in MS
Access,
-Master and use the functionalities of a spreadsheet, master the methods
and transactions used in ebanking, etc.

I. DEFINTIONs

The term database refers to a collection of related data from which the users can efficiently
retrieve the desired information. It can also be defined as a shared collection of related data
used to support the activities of a particular organization. In addition to the storage and retrieval
of data, certain other operations can also be performed on a database. These operations include
adding, updating and deleting data. All these operations on a database are performed using a
database management system (DBMS).
A database management system stores data in such a way that it becomes
easier to retrieve, manipulate, and produce information

Database Management System (DBMS): a collection of programs that enables users to create,
manage and maintain databases and control all access to them. Eg MS ACCESS , MYSQL,POSQRET,
ORACLE etc.

the Hierarchy of Data

Data is generally organized in a hierarchy that begins with the smallest piece of data used by
computers (a bit) and progresses through the hierarchy to a database. A bit (a binary digit) represents a
circuit that is either on or off. Bits can be organized into units called bytes. A byte is typically eight bits.
Each byte represents a character, which is the basic building block of information. A character can be
an uppercase letter (A, B, C… Z), lowercase letter (a, b, c… z), numeric digit (0, 1, 2… 9), or special
symbol (., !, [+], [-]…).

Characters can be combined to form a field. A fieldis typically a name, number, or combination of
characters that describes an aspect of a business object (such as an employee, a location) or activity
(such as a sale). In addition to being entered into a database, fields can be computed from other fields.
Computed fields include the total, average, maxi mum, and minimum values. A collection of related
data fields is a record. By combining descriptions of the characteristics of an object or activity, a record
can provide a complete description of the object or activity. For instance, an employee record is a
collection of fields about one employee. One field includes the employee’s name, another field
contains the address, and still others the phone number, pay rate, earnings made to date, and so forth.

1
A collection of related records is a file—for example; an employee file is a collection of all company
employee records. Likewise, an inventory file is a collection of all inventory records for a particular
company or organization. Some database software refers to files as tables.

At the highest level of this hierarchy is a database, a collection of integrated and related files. Together,
bits, characters, fields, records, files, and databases form the hierarchy of data (see Figure 5.1).
Characters are combined to make a field, fields are combined to make a record, records are combined
to make a file, and files are combined to make a database. A database houses not only all these levels
of data but also the relationships among them.

Characteristics OF DBMS
Traditionally, data was organized in file formats. DBMS was a new concept then,
and all the research was done to make it overcome the deficiencies in traditional
style of data management. A modern DBMS has the following characteristics:
Real-world entity: A modern DBMS is more realistic and uses real-world
entities to design its architecture. It uses the behavior and attributes too.
For example, a school database may use students as an entity and their
age as an attribute.
Relation-based tables: DBMS allows entities and relations among them
to form tables. A user can understand the architecture of a database just
by looking at the table names.
Isolation of data and application: A database system is entirely
different than its data. A database is an active entity, whereas data is said
to be passive, on which the database works and organizes. DBMS also
stores metadata, which is data about data, to ease its own process.

2
Less redundancy: DBMS follows the rules of normalization, which splits
a relation when any of its attributes is having redundancy in values.
Normalization is a mathematically rich and scientific process that reduces
data redundancy.
Consistency: Consistency is a state where every relation in a database
remains consistent. There exist methods and techniques, which can detect
attempt of leaving database in inconsistent state. A DBMS can provide
greater consistency as compared to earlier forms of data storing
applications like file-processing systems.
Query Language: DBMS is equipped with query language, which makes
it more efficient to retrieve and manipulate data. A user can apply as
many and as different filtering options as required to retrieve a set of data.
Traditionally it was not possible where file-processing system was
used.
ACID Properties: DBMS follows the concepts of Atomicity ( Means transaction
should take place completely), Consistency,
Isolation, and Durability (normally shortened as ACID). These concepts
are applied on transactions, which manipulate data in a database. ACID
properties help the database stay healthy in multi-transactional
environments and in case of failure.
Multiuser and Concurrent Access: DBMS supports multi-user
environment and allows them to access and manipulate data in parallel.
Though there are restrictions on transactions when users attempt to
handle the same data item, but users are always unaware of them.
Multiple views: DBMS offers multiple views for different users. A user
who is in the Sales department will have a different view of database than
a person working in the Production department. This feature enables the
users to have a concentrate view of the database according to their
requirements.
Security: Features like multiple views offer security to some extent
where users are unable to access data of other users and departments.
DBMS offers methods to impose constraints while entering data into the
database and retrieving the same at a later stage. DBMS offers many
different levels of security features, which enables multiple users to have
different views with different features. For example, a user in the Sales
department cannot see the data that belongs to the Purchase department.
Additionally, it can also be managed how much data of the Sales
department should be displayed to the user. Since a DBMS is not saved on
the disk as traditional file systems, it is very hard for miscreants to break
the code.

Users
A typical DBMS has users with different rights and permissions who use it for
different purposes. Some users retrieve data and some back it up. The users of
a DBMS can be broadly categorized as follows.

3
I. DATABASE MANAGEMENT SYSTEM

V.1 Definition
To carry out operations like insertion, deletion and retrieval, the database needs to be managed
by a software package. This software is called a database management system (DBMS).
Hence, DBMS can be defined as a collection of interrelated data and a set of programs to
access that data.
Database system: Database system is a general term that refers to the combination of a
database, a database management system and a data model. This system is responsible for the
following data manipulation acts; data controlling, data retrieving, data maintenance and data
definition.

Figure 11: a database system

V.2 Advantages and Limitations of a DBMS


A good database management system (DBMS) should provide the following advantages over a
conventional system:
Advantages
→ Reduction in Data Redundancy: Data redundancy refers to duplication of data. In
database systems, each application has its own separate files. This can often lead to
redundancy in stored data, which results in wastage of space.
→ Reduction in data Inconsistency: Data inconsistency is when different versions of the
same data appear in different places in a database. This causes unreliable information,
because it is difficult to determine which version of the information is correct.
→ Sharing of Data: Sharing of data allows the existing applications to use the data in the
database simultaneously.
→ Improvement in Data Security: DBMS can ensure that the only means of accessing
the database is through the authorized channel. Hence, data security checks can be
carried out whenever access is attempted to sensitive data. To ensure security, DBMS
provides security tools such as user codes and passwords.
→ Maintenance of Data Integrity: Data integrity means the consistency and accuracy of
the data in the database.

4
→ Better Interaction with Users: Centralizing the data in a database also means that users
can obtain new and combined information that would have been impossible to obtain
otherwise. In addition, use of a DBMS allows the users, who do not know programming,
to interact with the data more easily.

However, the following can be viewed as some of the limitations of a database:


Disadvantages
→ Database systems are complex, difficult, and time-consuming to design
→ Substantial hardware and software start-up costs
→ Damage to database affects virtually all applications programs
→ Extensive conversion costs in moving form a file-based system to a database system
→ Initial training required for all programmers and users

V.3 examples of Database Management System (DBMS)


Some of the database management systems are:
1) Microsoft Access : This is the database management system developed by Microsoft.
2) MySQL : MySQL is open source database management system, one of the most
popular dbms on the web. It is reliable, fast and also flexible.
3) Oracle : Developed by Oracle corporation. It is object relational database management
system. The original version of Oracle software was developed by Software
Development Laboratories (SDL). Oracle is regarded to be one of the safe DBMS.
4) Microsoft SQL Server : Microsoft developed this relational database server. The
primary function of this software is to store and retrieve the data as requested by other
applications, whether those applications are on the same computer or running on other
computers across the network (including internet).
5) Filemaker : Filemaker began as a MS-DOS based computer program named nutshell. It
is a cross platform RDBMS developed by Filemaker Inc.

II. DATABASE MODELS

A database model or simply a data model is an abstract model that describes how the data are
organized and represented. A data model consists of two parts, which are as follows:
• A mathematical notation for describing the data and relationships
• A set of operations used to manipulate that data

Every database and DBMS is based on a particular database model. There are four basic types
of database models—hierarchical, network, relational and object-oriented. These models
provide different conceptualizations of the database and they have different outlooks and
perspectives.

5
Administrators: Administrators maintain the DBMS and are responsible
for administrating the database. They are responsible to look after its
usage and by whom it should be used. They create access profiles for
users and apply limitations to maintain isolation and force security.
Administrators also look after DBMS resources like system license,
required tools, and other software and hardware related maintenance.
Designers: Designers are the group of people who actually work on the
designing part of the database. They keep a close watch on what data
should be kept and in what format. They identify and design the whole set
of entities, relations, constraints, and views.
End Users: End users are those who actually reap the benefits of having
a DBMS. End users can range from simple viewers who pay attention to
the logs or market rates to sophisticated users such as business analysts.

2. ARCHITECTU 2.
ARCHITEC
. D. DATA MODELS
ATA MODELS
. DATA MODELS

6
DBMS Architecture
The design of a DBMS depends on its architecture. It can be centralized or
decentralized or hierarchical. The architecture of a DBMS can be seen as either
single tier or multi-tier. An n-tier architecture divides the whole system into
related but independent n modules, which can be independently modified,
altered, changed, or replaced.
In 1-tier architecture, the DBMS is the only entity where the user directly sits on
the DBMS and uses it. Any changes done here will directly be done on the DBMS
itself. It does not provide handy tools for end-users. Database designers and
programmers normally prefer to use single-tier architecture.
If the architecture of DBMS is 2-tier, then it must have an application through
which the DBMS can be accessed. Programmers use 2-tier architecture where
they access the DBMS by means of an application. Here the application tier is
entirely independent of the database in terms of operation, design, and
programming.

3-tier
Architecture
A 3-tier architecture separates its tiers from each other based on the complexity
of the users and how they use the data present in the database. It is the most
widely used architecture to design a DBMS.

[Image: 3-tier DBMS architecture]

 Database (Data) Tier: At this tier, the database resides along with its
query processing languages. We also have the relations that define the
data and their constraints at this level.

7
 Application (Middle) Tier: At this tier reside the application server and
the programs that access the database. For a user, this application tier
presents an abstracted view of the database. End-users are unaware of
any existence of the database beyond the application. At the other end,
the database tier is not aware of any other user beyond the application
tier. Hence, the application layer sits in the middle and acts as a mediator
between the end-user and the database.

 User (Presentation) Tier: End-users operate on this tier and they know
nothing about any existence of the database beyond this layer. At this
layer, multiple views of the database can be provided by the application.
All views are generated by applications that reside in the application tier.
Multiple-tier database architecture is highly modifiable, as
almost all its components are independent and can be changed
independently.

DATA MODELS

Data models define how the logical structure of a database is modeled. Data
Models are fundamental entities to introduce abstraction in a DBMS. Data
models define how data is connected to each other and how they are processed
and stored inside the system.

The very first data model could be flat data-models, where all the data used are
to be kept in the same plane. Earlier data models were not so scientific, hence
they were prone to introduce lots of duplication and update anomalies.

Entity-Relationship
Model
Entity-Relationship (ER) Model is based on the notion of real-world entities and
relationships among them. While formulating real-world scenario into the
database model, the ER Model creates entity set, relationship set, general
attributes, and constraints.

ER Model is best used for the conceptual design of a database.

ER Model is based on:

 Entities and their attributes.

 Relationships among entities.

These concepts are explained below.

8
[Image: ER Model]

 Entity

An entity in an ER Model is a real-world entity having properties called


attributes. Every attribute is defined by its set of values called domain.

For example, in a school database, a student is considered as an entity.


Student has various attributes like name, age, class, etc.

 Relationship

The logical association among entitiesis called relationship.


Relationships are mapped with entities in various ways. Mapping
cardinalities define the number of association between two entities.

Mapping cardinalities:

o one to one

o one to many

o many to one

o many to many

Relational
Model
The most popular data model in DBMS is the Relational Model. It is more
scientific a model than others. This model is based on first-order predicate logic
and defines a table as an n-ary relation.

9
[Image: Table in relational Model]

The main highlights of this model are:

 Data is stored in tables called relations.

 Relations can be normalized.

 In normalized relations, values saved are atomic values.

 Each row in a relation contains a unique value.

Database
Schema
A database schema is the skeleton structure that represents the logical view of
the entire database. It defines how the data is organized and how the relations
among them are associated. It formulates all the constraints that are to be
applied on the data.

A database schema defines its entities and the relationship among them. It
contains a descriptive detail of the database, which can be depicted by means of
schema diagrams. It’s the database designers who design the schema to help
programmers understand the database and make it useful.

10
[Image: Database Schemas]

A database schema can be divided broadly into three


categories:

11
External models
 represent the user’s view of the database
 Contain multiple different external views
 Are closely related to the real world as perceived by each user

 Physical Database Schema: This schema pertains to the actual storage


of data and its form of storage like files, indices, etc. It defines how the
data will be stored in a secondary storage.

 Logical Database Schema: This schema defines all the logical


constraints that need to be applied on the data stored. It defines tables,
views, and integrity constraints.

If a database system is not multi-layered, then it becomes difficult to make any


changes in the database system. Database systems are designed in multi-layers
as we learnt earlier.

Data
Independence
A database system normally contains a lot of data in addition to users’ data. For
example, it stores data about data, known as metadata, to locate and retrieve
data easily. It is rather difficult to modify or update a set of metadata once it is
stored in the database. But as a DBMS expands, it needs to change over time to
satisfy the requirements of the users. If the entire data is dependent, it would
become a tedious and highly complex job.

[Image: Data independence]

Metadata itself follows a layered architecture, so that when we change data at


one layer, it does not affect the data at another level. This data is independent
but mapped to each other.

12
Logical Data
Independence
Logical data is data about database, that is, it stores information about how data
is managed inside. For example, a table (relation) stored in the database and all
its constraints applied on that relation.
Logical data independence is a kind of mechanism, which liberalizes itself from
actual data stored on the disk. If we do some changes on table format, it should
not change the data residing on the disk.

Physical Data
Independence
All the schemas are logical, and the actual data is stored in bit format on the
disk. Physical data independence is the power to change the physical data
without impacting the schema or logical data.

For example, in case we want to change or upgrade the storage system itself —
suppose we want to replace hard-disks with SSD — it should not have any
impact on the logical data or schemas.

The ER model
The ER model defines the conceptual view of a database. It works around real-
world entities and the associations among them. At view level, the ER model is
considered a good option for designing databases.

Entit
y
An entity can be a real-world object, either animate or inanimate, that can be
easily identifiable. For example, in a school database, students, teachers,
classes, and courses offered can be considered as entities. All these entities
have some attributes or properties that give them their identity.

An entity set is a collection of similar types of entities. An entity set may contain
entities with attribute sharing similar values. For example, a Students set may
contain all the students of a school; likewise a Teachers set may contain all the
teachers of a school from all faculties. Entity sets need not be disjoint.

Attribute
s
Entities are represented by means of their properties called attributes. All
attributes have values. For example, a student entity may have name, class, and
age as attributes.

13
There exists a domain or range of values that can be assigned to attributes. For
example, a student's name cannot be a numeric value. It has to be alphabetic. A
student's age cannot be negative, etc.

Types of
Attributes
 Simple attribute: Simple attributes are atomic values, which cannot be
divided further. For example, a student's phone number is an atomic
value of 10 digits.

 Composite attribute: Composite attributes are made of more than one


simple attribute. For example, a student's complete name may have
first_name and last_name.

 Derived attribute: Derived attributes are the attributes that do not exist
in the physical database, but their values are derived from other
attributes present in the database. For example, average_salary in a
department should not be saved directly in the database, instead it can be
derived. For another example, age can be derived from data_of_birth.

14
DBMS

 Single-value attribute: Single-value attributes contain single value. For


example: Social_Security_Number.

 Multi-value attribute: Multi-value attributes may contain more than one


values. For example, a person can have more than one phone number,
email_address, etc.

These attribute types can come together in a way like:

 simple single-valued attributes

 simple multi-valued attributes

 composite single-valued attributes

 composite multi-valued attributes

Entity-Set and
Keys
Key is an attribute or collection of attributes that uniquely identifies an entity
among entity set.

For example, the roll_number of a student makes him/her identifiable among


students.

 Super Key: A set of attributes (one or more) that collectively identifies


an entity in an entity set.

 Candidate Key: A minimal super key is called a candidate key. An entity


set may have more than one candidate key.

 Primary Key: A primary key is one of the candidate keys chosen by the
database designer to uniquely identify the entity set.

Relationshi
p
The association among entities is called a relationship. For example, an
employee works_at a department, a student enrolls in a course. Here,
Works_at and Enrolls are called relationships.

Relationship
Set
A set of relationships of similar type is called a relationship set. Like entities, a
relationship too can have attributes. These attributes are called descriptive
attributes.

Degree of

15
DBMS
Relationship
The number of participating entities in a relationship defines the degree of the
relationship.

16
DBMS

 Binary = degree 2

 Ternary = degree 3

 n-ary = degree

Mapping Cardinalities
Cardinality defines the number of entities in one entity set, which can be
associated with the number of entities of other set via relationship set.

 One-to-one: One entity from entity set A can be associated with at most
one entity of entity set B and vice versa.

[Image: One-to-one relation]

 One-to-many: One entity from entity set A can be associated with more
than one entities of entity set B, however an entity from entity set B can
be associated with at most one entity.

[Image: One-to-many relation]

 Many-to-one: More than one entities from entity set A can be associated
with at most one entity of entity set B, however an entity from entity set
B can be associated with more than one entity from entity set A.

17
[Image: Many-to-one relation]

 Many-to-many: One entity from A can be associated with more than one
entity from B and vice versa.

[Image: Many-to-many relation]

ER-DIAGRAM REPRESENTATION

Let us now learn how the ER Model is represented by means of an ER diagram.


Any object, for example, entities, attributes of an entity, relationship sets, and
attributes of relationship sets, can be represented with the help of an ER
diagram.

Entit
y
Entities are represented by means of rectangles. Rectangles are named with the

18
entity set they represent.

[Image: Entities in a school database]

Attribute
s
Attributes are the properties of entities. Attributes are represented by means of
ellipses. Every ellipse represents one attribute and is directly connected to its
entity (rectangle).

[Image: Simple Attributes]

If the attributes are composite, they are further divided in a tree like structure.
Every node is then connected to its attribute. That is, composite attributes are
represented by ellipses that are connected with an ellipse.

19
DBMS

[Image: Composite Attributes]

Multivalued attributes are depicted by double ellipse.

[Image: Multivalued Attributes]

Derived attributes are depicted by dashed ellipse.

20
DBMS

[Image: Derived Attributes]

Relationshi
p
Relationships are represented by diamond-shaped box. Name of the relationship
is written inside the diamond-box. All the entities (rectangles) participating in a
relationship are connected to it by a line.

Binary Relationship and


Cardinality
A relationship where two entities are participating is called a binary
relationship. Cardinality is the number of instance of an entity from a relation
that can be associated with the relation.

 One-to-one: When only one instance of an entity is associated with the


relationship, it is marked as '1:1'. The following image reflects that only
one instance of each entity should be associated with the relationship. It
depicts one-to-one relationship.

21
DBMS
[Image: One-to-one]

22
DBMS

 One-to-many: When more than one instance of an entity is associated


with a relationship, it is marked as '1:N'. The following image reflects that
only one instance of entity on the left and more than one instance of an
entity on the right can be associated with the relationship. It depicts one-
to-many relationship.

[Image: One-to-many]
 Many-to-one: When more than one instance of entity is associated with
the relationship, it is marked as 'N:1'. The following image reflects that
more than one instance of an entity on the left and only one instance of
an entity on the right can be associated with the relationship. It depicts
many-to-one relationship.

[Image: Many-to-one]
 Many-to-many: The following image reflects that more than one instance
of an entity on the left and more than one instance of an entity on the
right can be associated with the relationship. It depicts many-to-many
relationship.

[Image: Many-to-many]

23
Participation Constraints
 Total Participation: Each entity is involved in the relationship. Total
participation is represented by double lines.

 Partial participation: Not all entities are involved in the relationship.


Partial participation is represented by single lines.

[Image: Participation Constraints

RELATIONAL MODEL DATA MODEL

Relational data model is the primary data model, which is used widely around
the world for data storage and processing. This model is simple and it has all the
properties and capabilities required to process data with storage efficiency.

Concept
s
Tables: In relational data model, relations are saved in the format of Tables.
This format stores the relation among entities. A table has rows and columns,
where rows represent records and columns represent the attributes.

Tuple: A single row of a table, which contains a single record for that relation is
called a tuple.

Relation instance: A finite set of tuples in the relational database system


represents relation instance. Relation instances do not have duplicate tuples.

Relation schema: A relation schema describes the relation name (table name),
attributes, and their names.

Relation key: Each row has one or more attributes, known as relation key,
which can identify the row in the relation (table) uniquely.

Attribute domain: Every attribute has some predefined value scope, known as
attribute domain.

24
Constraint
s
Every relation has some conditions that must hold for it to be a valid relation.
These conditions are called Relational Integrity Constraints. There are three
main integrity constraints:

 Key constraints

 Domain constraints

 Referential integrity constraints

Key
Constraints
There must be at least one minimal subset of attributes in the relation, which
can identify a tuple uniquely. This minimal subset of attributes is called key for
that relation. If there are more than one such minimal subsets, these are
called candidate keys.

Key constraints force that:

25
DBMS

 in a relation with a key attribute, no two tuples can have identical values
for key attributes.

 a key attribute cannot have NULL values.

Key constraints are also referred to as Entity Constraints.

Domain
Constraints
Attributes have specific values in real-world scenario. For example, age can only
be a positive integer. The same constraints have been tried to employ on the
attributes of a relation. Every attribute is bound to have a specific range of
values. For example, age cannot be less than zero and telephone numbers
cannot contain a digit outside 0-9.

Referential Integrity
Constraints
Referential integrity constraints work on the concept of Foreign Keys. A foreign
key is a key attribute of a relation that can be referred in other relation.

Referential integrity constraint states that if a relation refers to a key attribute of


a different or same relation, then that key element must exist

A) The transition from CDM to LDM


1) Relations

The Data Logic Model (LDM) is composed only of so-called relations. These relations come
from both MCD entities and associations in some cases. These relations will allow us to create
our tables at the physical level.

A relation is composed of attributes. These attributes are elementary data coming from the
properties of the various entities but also from the identifiers and the data carried by certain
associations.

A relation has a name that usually corresponds to that of the entity or association that
corresponds to it. It also has a primary key that unambiguously identifies each occurrence of
this relation. The primary key can be composed of one or more attributes, it is an
implementation of the notion of identifier of the entities and associations which is reflected at
the relational level.

Here is a first example of a relationship (from the "Edit" entity of our previous MCD):
Edition (id_ed, name_ed)

26
Notes:

This first MLD is represented textually. It is this representation that is found in many higher
education courses. However, there is an equivalent graphical representation.
It is important to accompany a textual MLD with a legend (the latter having no standardized
formalism). This is also required in some formations.

There is another type of key called foreign key. The foreign key is an attribute of a relation that refers
to the primary key of another relation (these two keys will have to have the same type of data).

Let's complete our first example with another relationship where a foreign key appears:
Edition (id_ed, name_ed)
Exemplaire (ref_e, id_ed#)

At the relational level, we should rather speak of a candidate key that unambiguously identifies an
occurrence of the relationship for the primary keys. Similarly, we should designate a foreign key by an
inclusion constraint to a candidate key. For the sake of simplicity, we will keep the terms of primary
and foreign keys.
By convention, we precede or follow the foreign key of the symbol #. This is not an obligation from
the moment the legends are sufficiently precise.
Here the foreign key present in the relation "Copy" refers to the primary key of the relation
"Edition".
A relationship may have none, one or more foreign keys but always has one and only one primary
key.

Finally, you can also meet the term cardinality of the relation which means here the number of
occurrences of a relation (or number of entries in the corresponding table) and the term of degree of
the relation which corresponds to the number of attributes of a relationship.
2) Conversion rules
As already mentioned, the relations of the LDM come from the entities of the MCD and certain
associations. We will now discuss these conversion rules more precisely.
Rule 1 - Conversion of an Entity
As a general rule, any MCD entity becomes a relationship whose key is the identifier of that entity. Each
property of the entity becomes an attribute of the corresponding relationship.
There are, however, some special cases that you will see in the paragraph.
Rule 2 - conversion of associations having only cardinalities of type 0/1, N

Write (id_a #, id_l #)

In the case of associations carrying data, the carried data become attributes of the corresponding
relation. If we take this example again:

27
Rule 3 - conversion of associations having at least one type 1.1 cardinality
Several possibilities are available to us for this case. The most common conversion rule today is to add
a foreign key in the relation that corresponds to the entity on the side of this cardinality 1,1. This
foreign key will therefore refer to the key of the relation corresponding to the second entity linked by
the association.

Let's take an example from the association "to be from" and from the entities "Author" and "Country":

Country (p_name)
Author (id_a, name_a, firstname_a, date_birth_a, name_p #)

III. INTRODUCTION TO QUERIES

When referring to a database, a query is an option used to locate information within a database.
For example you could query a database to find all related tables that match the state of "Utah"
in the United States. The database could then return all people logged in the database that live
in Utah. The most known and most used query language is SQL (Structured Query Language).
A form is a page that contains a listing of fields that are required to be filled out.
A report is a file or view of data formatted in a way that allows the user to see a large amount
of data from documents or a database. This helps the user get a quick overview of their data or
allows them to present a lot of data easily.

VIII.1 Introduction to SQL


SQL (Structured Query Language) is a database query language developed by IBM in the 1970s
as a way of getting information into and out of relational DBMSs. A fundamental difference
between SQL and standard programming languages is that SQL is declarative, that is, the user
has to specify what kind of data are required from the database and the RDBMS is responsible
for figuring out the way to retrieve it.

VIII.2 Basic operations in a RDB


In a relational database, three basic operations are used to develop useful sets of data: selection,
projection and join.
 The selection operation retrieves certain records from a relation based on the user-
specified criteria.
 The projection operation extracts fields from a relation, permitting the user to create
new relations that contain only the required information.
 The join operation combines the data from the two relations based on a common
column, providing the user with more information than is available in individual
relations.

Together, these three operations are part of relational algebra. Relational database systems use a
query language called Structured Query Language (SQL) to implement relational algebra
operations.

VIII.3 SQL Data Types

28
When the table is defined every field in it is assigned a data type. The type of a data value both
defines and constrains the kinds of operations, which may be performed on it. Some of the most
commonly used SQL data types are as follows:
• CHAR(size): It defines a fixed size-length character string (can contain letters, numbers
and special characters), where size can be a maximum of 255.
• VARCHAR(size): It defines a variable length character string (can contain letters,
numbers and special characters) of up to size characters.
• NUMBER(size): It defines an integer-type data with maximum number of digits up to
size specified in parenthesis.
• DATE: This type of data is used to store date. By default, the format is YYYY-MM-
DD.
• NUMBER(size, decimal): It holds numbers with fractions. The maximum numbers of
digits are specified in size. The maximum number of digits to the right of the decimal is
specified in decimal.

VIII.4 SQL Basic Commands


SQL commands can be divided into two main sublanguages—DDL and DML
• Data Definition Language: DDL is used to create and delete database and its objects.
These commands are primarily used by the DBA during the building and removal
phases of a database project. The most important DDL statements in SQL are as
follows:
- CREATE TABLE: To create a new table.
- ALTER TABLE: To modify the structure of a table.
- DROP TABLE: To delete a table.
• Data Manipulation Language: DML is used to retrieve, insert, modify and delete
database information. These commands will be used by all database users during the
routine operation of the database. The most important DML statements in SQL are the
following:
- INSERT: To insert data into a table.
- UPDATE: To update data in a table.
- DELETE: To delete data from a table.
- SELECT: To retrieve data from a table.

NOTE: All SQL queries must be terminated by a semicolon (;) even if the statement extends
over many lines.
VIII.4.1 CREATE TABLE Command
The CREATE TABLE command is used to define the structure of the table.
Syntax: Example:
CREATE TABLE <tablename> ( CREATE TABLE EMPLOYEE(
<field1> <data type>, Code NUMBER(5),
< field2> <data type>, Deptt CHAR(10),
... ... ... ... ... Name CHAR(20),
< fieldN> <data type>); Address CHAR(100),
Telephone CHAR(8)

29
Salary NUMBER(8,2));

• The table and column names must start with a letter followed by letters, numbers or
underscores.
• Avoid using SQL keywords as names for tables or columns (such as SELECT,
CREATE, and INSERT).
• For each column, a name and a data type must be specified and the column name must
be unique within the table definition.
• Each column definition should be separated with a comma.

VIII.4.2 ALTER TABLE Command


The ALTER TABLE command allows a user to change the structure of an existing table.
• New columns can be added with the ADD clause.
• Existing columns can be modified with the MODIFY clause.
• Columns can be removed from a table by using the DROP clause.

Syntax:
ALTER TABLE <tablename>
<ADD | MODIFY | DROP column(s)>;

Examples: Explanation
1 ALTER TABLE EMPLOYEE command will add a new column, named Email,
ADD Email CHAR(25); having a maximum width of 25
characters in the EMPLOYEE table.
2 ALTER TABLE EMPLOYEE command will change the maximum width of the
MODIFY Name CHAR(25); Name column to 25 characters in the EMPLOYEE
table.
3 ALTER TABLE EMPLOYEE command will delete the Deptt column from the
DROP Deptt; EMPLOYEE table.

VIII.4.3 DROP TABLE Command


The DROP TABLE command removes the table definition (with all records).
• Columns can be removed from a table by using the DROP clause.

Syntax: Examples:
DROP TABLE <tablename>; DROP TABLE EMPLOYEE;
The above SQL command will delete the EMPLOYEE table.
VIII.4.4 INSERT Command
The INSERT command is used to insert or add rows (records) into the specified table.
Syntax:

INSERT INTO <tablename> (


column1, column2, ..., columnN)
VALUES (value1, value2, ..., valueN);
Examples Explanation

30
1 INSERT INTO EMPLOYEE ( example 1 will add a new record at the
Code, Deptt, Name, Address, Salary) bottom of the EMPLOYEE table
VALUES (101, 'RD01', 'Prince', 'Park Way', consisting of the values in parenthesis.
15000);
2 INSERT INTO EMPLOYEE
VALUES (102, 'RD01', 'Pankaj', 'Pitampura',
26062700, 8000);
Note that for each of the listed columns, a matching value must be specified. In case no column
list is specified, then a value must be given for each column and in the same order as specified
in the CREATE TABLE command.
VIII.4.5 UPDATE Command
The UPDATE command is used for modifying attribute values of records in a table.
Syntax:
UPDATE <tablename>
SET column1 = value1
[, column2 = value2]
... ... ... ... ...
[, columnN = valueN]
[WHERE <condition>];
Note that components specified inside the square brackets [] are optional.

Examples Explanation
1 UPDATE EMPLOYEE example 1 command will update (in our case,
SET Salary = Salary + 1000; increments) the Salary field with 1000 for all the records.
2 UPDATE EMPLOYEE Example 2 command will increment the Salary column
SET Salary = Salary + 1000 with 1000 for only those rows that comply with
WHERE Deptt = 'RD01'; condition specified in WHERE clause (Deptt = 'RD01').

VIII.4.6 DELETE Command


The DELETE command is used to delete all or selected records from the specified table.
Syntax: Example:
DELETE FROM <tablename> DELETE FROM EMPLOYEE
[WHERE <condition>]; WHERE Salary > 8000;

NOTE: If WHERE condition is not used in the DELETE command, then all the records from
the specified table will be deleted.
VIII.4.7 SELECT command
The SELECT statement is used to query the database and retrieve selected data.
Syntax:
SELECT <column1, column2, column3,...., columnN>
FROM <tablename>
[WHERE <condition>]
[GROUP BY <column1, column2, column3,...., columnN>]
[HAVING <condition>]

31
[ORDER BY <column1, column2, column3,...., columnN [ASC|DESC]>];

To select all the columns of a table, use * instead of column list with SELECT.
Examples Explanation
1 SELECT Code, Name, Salary The SELECT statement selects the values of the three
FROM EMPLOYEE; specified columns from the EMPLOYEE table. This
operation is called projection.
2 SELECT * The SELECT statement selects all those columns from
FROM EMPLOYEE EMPLOYEE table in which the Salary column contains a
WHERE Salary > 7500; value greater than 7500. This operation is called selection.
SELECT * the SELECT statement displays the result in a descending
FROM EMPLOYEE order by the attribute Name.
WHERE Salary > 7500
ORDER BY Name DESC;

The ORDER BY clause specifies a sorting order in which the result tuples of a query are to be
displayed; DESC specifies a descending order. By default, ORDER BY arranges the result set
in ascending order (whether one uses ASC or not).

VIII.5 SQL Joins


An SQL JOIN clause is used to combine rows from two or more tables, based on a common
field between them. SQL specifies two main types of JOIN: Inner Join and Outer Join
VIII.5.1 Inner Join
The INNER JOIN creates a new result table by combining column values of two tables (table1
and table2) based upon the join-predicate. The query compares each row of table1 with each
row of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate
is satisfied, column values for each matched pair of rows of A and B are combined into a result
row.
Syntax:
The basic syntax of INNER JOIN is as follows:

SELECT table1.column1, table2.column2...


FROM table1
INNER JOIN table2
ON table1.common_filed = table2.common_field;

REVIEW QUESTIONS
1. What is an attribute? How is it related to an entity?
2. Define the term database. How is it different from a database management system?

32
3. What is the hierarchy of data in a database?
4. What is a flat file?
5. What is the purpose of a primary key? How can it be useful in controlling data redundancy?
The manager of a supermarket decides to keep track of his customers and
their transactions in the supermarket. A customer is identified by the name,
an address, the city and the telephone number. An item is identified by a
name, the quality and the unit price, A customer can order one or more items
and an item can be ordered by one or many customer, since there is a certain
quantity of each item. For an item ordered, the date and quantity ordered is
stored.
a) Draw the Entity-Relation Diagram corresponding to the above
situation and precise the different cardinalities.
b) Deduce the relational model from the Entity-Relation Diagram. The
primary key of each relation should be underlined
A bakery accepts catering orders from customers. Most of them are regular
customers and each one is given an ID number. A CUSTOMER is issued
an invoice when he places an ORDER, which indicates each PRODUCT
that the customer has ordered and the date that he can pick up his
products. At the order taking counter the bakery displays a list of
products that it produces.
 At least one customer has placed many orders,
 At least one order contains many order details,
 At least one product appears in many order details.

Details of the order are to be stored in a database using the following four
tables:
 Customer (customer ID, customer Name, Gender, Telephone
Number)
 Product(Product ID, Product Name ,UnitPrice)
 Orders (Order ID ,Order Date ,Customer ID)
 Order Details(Order ID ,Product ID ,Quantity Ordered ,Expiry
Date)
(i) These tables are in THIRD Normal Form.What does this means?
(3marks)
(ii) b) Draw an Entity-Relationship to show the degree of the
relationships that exist between the entities? (10 marks)
(iii) Write a Data Definition Language (DDL) statement to create the
Customer table, including the key field. (3 marks)
(iv) The company wants to send letters to customers to advertise a new
product. The letters must be sent to all customers. A customer’s
ID, name and telephone number must be included in each letter.
Write a SQL query that will find the data needed to produce the
letters. (4 marks)

33
(v) The customer named ‘Atangana Paul’ is to be renamed ‘Atanga
Paul’. Write a SQL statement to update the data in the customer
table to reflect this change.(4 marks)

Exercise 5 (25 marks)


Consider the following information about a university database:
Professors have an SSN, a name, an age, a rank, and a research specialty.
Projects have a project number, a sponsor name (e.g., NSF), a starting date, anending date, and
a budget.
Graduate students have an SSN, a name, an age, and a degree program (e.g., M.S.or Ph.D.).
Each project is managed by one professor (known as the project’s principal investigator).
Each project is worked on by one or more professors (known as the project’sco-investigators).
Professors can manage and/or work on multiple projects.
Each project is worked on by one or more graduate students (known as theproject’s research
assistants).
When graduate students work on a project, a professor must supervise their workon the project.
Graduate students can work on multiple projects, in which casethey will have a (potentially
different) supervisor for each one.
Departments have a department number, a department name, and a main office.
Departments have a professor (known as the chairman) who runs the department.
Professors work in one or more departments, and for each department that they
work in, a time percentage is associated with their job.
Graduate students have one major department in which they are working on theirdegree.
Each graduate student has another, more senior graduate student (known as astudent advisor)
who advises him or her on what courses to take.
A. State the various entities that will be involved in the database of the university(4 marks)
B. Design and draw an ER or the class diagram that captures the information about the
university. (10 marks)
C. Write an SQL query to create any two tables of the database(4 marks)

Exercise 5
A company database needs to store information about employees (identifiedbyssn,withsalary
and phone as attributes), departments (identified by dno, with dname and budget as attributes),
and children of employees (with name and age as attributes). Employees work in departments;
each department is managed by an employee; a child must be identified uniquely by name when
the parent (who is an employee; assume that only one parent works for the company) is known.
We are not interested in information about a child once the parent leaves the company.

Draw an ER diagram that captures this information.(10 marks

34
35

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy