Introduction To Data Base
Introduction To Data Base
- 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.
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.
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.
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.
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.
8
[Image: ER Model]
Entity
Relationship
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]
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]
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
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.
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.
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
Entity-Set and
Keys
Key is an attribute or collection of attributes that uniquely identifies an entity
among entity set.
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.
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.
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.
ER-DIAGRAM REPRESENTATION
Entit
y
Entities are represented by means of rectangles. Rectangles are named with the
18
entity set they represent.
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).
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
20
DBMS
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.
21
DBMS
[Image: One-to-one]
22
DBMS
[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.
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 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
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.
25
DBMS
in a relation with a key attribute, no two tuples can have identical values
for key attributes.
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.
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
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 #)
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.
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.
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.
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.
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.
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:
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').
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).
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
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.
34
35