E-Note SS Two 1st Term Data Processing
E-Note SS Two 1st Term Data Processing
SCHEME OF WORK
7 Mid-Term Break
10 Revision
11 - 13 Examination
Reference Book
Data models define how data is connected to each other and how they are processed and stored
inside the system.
A data model is an abstract model that organizes elements of data and standardizes how they relate to
one another and to properties of the real world entities.
For instance, a data model may specify that the data element representing a car be composed of a
number of other elements which, in turn, represent the color and size of the car and define its owner.
Conceptual Data Model: is a technology independent specification of the data to be held in the
database. It is the focus of communication between the data modeler and business stakeholders, and
it is usually presented as a diagram with supporting documentation.
Logical Data Model: is the translation of the conceptual model into structure that can be
implemented using a database management system (DBMS).
This model specifies tables and columns. These are the basic building blocks of relational databases,
which are implemented using a relational database management system (RDBMS)
Physical Data Model: this incorporates any changes necessary to achieve adequate performance and
is also presented in terms of tables and columns, together with a specification of physical storage and
access mechanisms.
EVALUATION:
i. What is conceptual data model?
ii. What does data model focus on?
iii. What is logical data model?
Sub-topic 2
ii. Hierarchical model: The hierarchical model is similar to the network model except that links
in the hierarchical model form a tree structure, while the network model allows arbitrary graph.
iii. Network model: This model organizes data using two fundamental constructs, called
records and sets. Records contain fields, and sets define one-to-many relationships
between records: one owner, many members. The network data model is an
abstraction of the design concept used in the implementation of databases.
iv. Relational model: is a database model based on first-order predicate logic. Its core
idea is to describe a database as a collection of predicates over a finite set of
predicate variables, describing constraints on the possible values and combinations of
values. The power of the relational data model lies in its mathematical foundations
and a simple user-level paradigm.
vi. Star Schema: The simplest style of data warehouse schema. The star schema consists
of a few "fact tables" (possibly only one, justifying the name) referencing any number
of "dimension tables". The star schema is considered an important special case of
the snowflake schema.
Entity-relationship model
An entity-relationship model (ERM), sometimes referred to as an entity-relationship diagram
(ERD), is an abstract conceptual data model (or semantic data model) used in software
engineering to represent structured data. There are several notations used for ERMs
Teacher CLASS
Teacher
s
READING ASSIGNMENT:
Study the topic ‘Data modelling” using students’ textbook
WEEKEND ASSIGNMENT:
OBJECTIVE TEST:
1. In a database data is organized into simple (a) tables (b) rows (c) columns (d) type
2. A data model is a ___ representation of the data structure that are required by a
database. (a) logical (b) conceptual (c) physical (d) dynamic
3. The following is not a step of design process: (a) planning logical design (c) survey
(d) implementation
WEEK THREE
DATE: .........................................
TOPIC: Data Modelling
CONTENT:
1. Creating Tables, Forms, Queries and Reports
2. Significance of data model
Data modeling is the process of developing data model for the data to be stored in a
Database.
Data Modelling in software engineering is the process of creating a data model by applying
formal data model descriptions using data modeling techniques.
Data modeling is a method used to define and analyze data requirements needed to support
the business processes of an organization. The data requirements are recorded as a
conceptual data model with associated data definitions. Actual implementation of the
conceptual model is called a logical data model.
1. In the database window, click on tables in the object bar. Double click create table in
design view. Table design view opens.
2. Type a field name on the first empty line of the Field Name column. Then press Tab to
move to the data Type column.
3. When you move to the Data Type column, an arrow appears for a drop down list.
Open the Data Type drop-down list and select field type.
4. Press Tab to move to Description column and type a description of the field.
(Optional)
5. In the bottom half of the dialog box, you see Filed Properties for the field type you
selected. Make any changes to them that you want.
6. If you have more fields to enter, repeat steps 2 through 5
7. Click the Table Design window’s Close (x) button
8. When you are asked if you want to save your changes to the table, click Yes. The Save
As dialog box appears.
9. Type a name for the table in the Table Name text box, and then click OK
Creating Query
The easiest way to create a query is with the Simple Query wizard, which enable you to
select fields you want to display.
1. Open the database you want to work with and click the Queries tab
2. Double-click Create Query by Using wizard. The first dialog box of the simple query
wizard appears. This dialog box might look familiar, it is similar to the first screen of
the Table Wizard described earlier.
3. Choose the table from which you want to select field from the Table/Queries drop-
down list.
4. Click a field name in the Available Fields list: then click the > button to move it to the
Selected Fields list. Repeat to move all the fields you want. Or move them all at once
with the >> button. Then click on Next.
5. Select type of Query whether Detailed (showing every field of the every record) or
Summary (showing selected SUM, AVG, MIN OR MAX of the selected fields) and click
on NEXT
6. Enter a title for the Query in the What Title Do You want for your Query? Text box. I
will call it Student’s record.
7. Click Finish to view the query results.
Designing Report
Report wizard offers a good compromise between ease-of use and flexibility. With the
Report Wizard, you can use multiple tables and queries and choose a layout and format for
your report.
1. Open the database containing the table or query on which you want to report
2. Click the Reports tab in the Database window.
3. Double click Create Report by using wizard to start the Report wizard.
4. From the Table/Queries drop-down list, select a table or query from which you want
to include fields.
5. Click a field in the Available Fields list, and then click the > button to move it to the
Selected Fields list.
6. If desired, select another table or query from the Table/Queries list and repeat step
5.
7. If you want the records grouped by any of the fields you selected, click the field, and
then click the > button. You can select several grouping levels in order you want then.
8. The wizard asks you what sort order you want to use. If you want sorted records,
open the top drop-down list and select a field by which to sort.
9. In the next dialog box, choose a layout option from the Layout section. When you
click an option button, the sample in the box changes to show your selection.
10. Choose the orientation for your printed report: Portrait (across the narrow edge of
the paper) or Landscape
11. In the next wizard dialog box, choose a report style.
12. You are asked for a report title. Enter one in the Report textbox and click Finish to see
your report in Print Preview.
Sub-topic 2
Significance of data model
1. Data Organization
2. Data Integrity
3. Data Integration
4. Data Security
5. Scalability
6. Application Development
7. Data Documentation
8. Data Analysis
9. Data Standardization
10. Communication .
EVALUATION:
i. What is data modeling?
ii. What is the significance of data modeling?
iii. What is importance of data modeling?
EVALUATION:
i. What are the example of standard data model
ii. Explain standard data model.
READING ASSIGNMENT:
Study the topic ‘Data modelling” using students’ textbook
WEEKEND ASSIGNMENT:
OBJECTIVE TEST:
1. In a database data is organized into simple (a) tables (b) rows (c) columns (d) type
2. A data model is a ___ representation of the data structure that are required by a
database. (a) logical (b) conceptual (c) physical (d) dynamic
3. The following is not a step of design process: (a) planning logical design (c) survey
(d) implementation
4. Creating a Query, choose the following from New Query dialog box. (a) creating
query wizard (b) design view (c) simple query wizard (d) none of the above
5. To select all fields to be added to a generated form click (a) >> (b) < (c) > (d) <<
WEEK FOUR
DATE:.........................................
TOPIC: NORMAL FORMS
CONTENT:
1. Examples of tables in first normal forms
2. Tables in second and third normal forms
Sub-topic 1
Without Normalization, it becomes difficult to handle and update the database, without
facing data loss. Insertion, Updation and Deletion Anamolies are very frequent if Database is
not Normalized. To understand these anomalies let us take an example of Student table.
Updation Anomaly: To update address of a student who occurs twice or more than
twice in a table, we will have to update S_Address column in all the rows, else data
will become inconsistent.
Insertion Anomaly: Suppose for a new admission, we have a Student id(S_id), name
and address of a student but if student has not opted for any subjects yet then we
have to insert NULL there, leading to Insertion Anomaly. To insert redundant data for
every new row is a data insertion problem or anomaly.
Deletion Anomaly: If (S_id) 401 has only one subject and temporarily he drops it,
when we delete that row, entire student record will be deleted along with it.
Normalization Rule
As per First Normal Form, no two Rows of data must contain repeating group of
information i.e. each set of columns must have a unique value, such that multiple columns
cannot be used to fetch the same row. Each table should be organized into rows, and each
row should have a primary key that distinguishes it as unique.
The Primary key is usually a single column, but sometimes more than one column can be
combined to create a single primary key. For example consider a table which is not in First
normal form
Student Table:
In First Normal Form, any row must not have a column in which more than one value is
saved, like separated with commas. Rather than that, we must separate such data into
multiple rows.
Using the First Normal Form, data redundancy increases, as there will be many columns with
same data in multiple rows but each row as a whole will be unique.
Criteria
Each cell to be single valued.
Entries in a column are same type.
Rows uniquely identified – Add Unique ID
Each column should have a unique name.
Order in which data is saved doesn’t matter.
Using SQL query, you can easily fetch data in any order from a table.
Sub-topic 2
As per the Second Normal Form, there must not be any partial dependency of any column
on primary key. It means that for a table that has concatenated primary key, each column in
the table that is not part of the primary key must depend upon the entire concatenated key
for its existence. If any column depends only on one part of the concatenated key, then the
table fails Second normal form.
In example of First Normal Form there are two rows for Adam, to include multiple subjects
that he has opted for. While this is searchable, and follows First normal form, it is an
inefficient use of space. Also in the above Table in First Normal Form, while the candidate
key is {Student, Subject}, Age of Student only depends on Student column, which is incorrect
as per Second Normal Form. To achieve second normal form, it would be helpful to split out
the subjects into an independent table, and match them up using the student names as
foreign keys.
Student Age
Adam 15
Alex 14
Stuart 17
In Student Table the candidate key will be Student column, because all other column i.e. Age
is dependent on it.
Studen Subject
t
Adam Biology
Adam Maths
Alex Maths
Stuart Maths
In Subject Table the candidate key will be {Student, Subject} column. Now, both the above
tables qualify for Second Normal Form and will never suffer from Update Anomalies.
Although there are a few complex cases in which table in Second Normal Form suffers
Update Anomalies, and to handle those scenarios Third Normal Form is there.
Criteria
Third Normal form applies that every non-prime attribute of table must be dependent on
primary key, or we can say that, there should not be the case that a non-prime attribute is
determined by another non-prime attribute. So this transitive functional dependency should
be removed from the table and also the table must be in Second Normal form. For example,
consider a table with following fields.
Student_Detail Table :
Student_i Student_nam DO Stree cit Stat Zi
d e B t y e p
In this table Student_id is Primary key, but street, city and state depends upon Zip. The
dependency between zip and other fields is called transitive dependency. Hence to apply
3NF, we need to move the street, city and state to new table, with Zip as primary key.
Address Table :
Zip Street city state
EVALUATION:
i. What is normalization?
ii. What is 1NF?
READING ASSIGNMENT:
Study the topic ‘Normal Forms” using students’ textbook
WEEKEND ASSIGNMENT:
OBJECTIVE TEST:
1. A table always meets the requirement of its ____ form.
2. The normal forms are applicable to individual ______
WEEK FIVE
DATE:.........................................
TOPIC: NORMAL FORMS
CONTENT:
1. Problems of table in first normal form
2. Determinant of normal forms
Sub-topic 1
Problems of table in first normal form
The basic problem is that department names and addresses are really data about
departments rather than employees, and belong to a separate Department table. We
therefore establish a third table for department data, resulting in the three-table model
below:
Employee Employee Dept.
Employee table
Number Name Number
01287 Clark 05
22617 Walsh 05
70964 Smith 12
50607 Black 05
Department Table
05 Auditing HQ
12 Legal MS
Qualification Table
We leave Department number in the Employee table to serve as a cross-reference, in the same way
that we retained Employee Number in the Qualification table. Our data now normalized.
Sub-topic 2
Determinant of normal forms
It is important to understand that this whole procedure of separating hospital data relied on
the fact that for a given hospital number there could be only one hospital name, contact
person, hospital type and teaching status. In fact we could look at the dependency of
hospital data on hospital number as the cause of the problem. Every time a particular
hospital number appeared in the Operation table, the hospital name, contact person,
hospital type and teaching status were the same.
OPERATION (Hospital Number, Operation Number, Hospital name, Hospital Type,
Teaching Status, contact Person, operation Name, Operation code, Procedure
Group, Surgeon Number, Surgeon Specialty)
Formally, we say Hospital Number is a determinant of the other four columns. We can show this as:
Hospital Number Hospital Name, Contact Person, Hospital Type, Teaching Status
Where we read “ “ as “determines” or “is a determinant of”.
Determinants need not consist of only one column; they can be a combination of two or more
columns, in which case we can use a + sign to indicate such a combination.
E.g. Hospital Number + Operation Number Surgeon Number.
This leads us to a more formal description of the procedure:
1. Identify any determinants, other than the primary key, and the columns they determine.
2. Establish a separate table for each determinant and the columns it determines. The
determinant becomes the key of the new table.
3. Name the new tables.
4. Remove the determined columns from the original table. Leave the determinants to provide
links between tables.
Primary Keys
A primary key is a nominated column or combination of columns that has a different value for every
row in the table. Each table has one (and only one) primary key. When checking this with a business
person, we would say, “if I nominated, say, a particular account number, would you be able to
guarantee that there was never more than one account with that number?”
Candidate Keys
Sometimes more than one column or combination of columns could serve as a primary key. E.g, we
could have chosen Drug Name rather than Drug Short Name as the primary key of the Drug table
(assuming, of course, that no two drugs could have the same name). we refer to such possible
primary keys, whether chosen or not, as candidate keys. From the point of view of normalization, the
important thing is that candidate keys that have not been chosen as the primary key, such as Drug
Name, will be determinants of every column in the table, just as the primary key is.
Foreign Keys
Recall that when we removed repeating groups to a new table, we carried the primary key of the
original table with us, to cross-reference or “point back” to the source. In moving from first to third
normal form, we left determinants behind as cross-reference to the relevant rows in the new tables.
These cross-referencing columns are called foreign keys, and they are our principal means of linking
data from different tables.
EVALUATION:
i. What is primary key?
ii. What is the use of foreign keys?
iii. What are candidate keys?
READING ASSIGNMENT:
Study the topic ‘Entity Relational Model” using students’ textbook
WEEKEND ASSIGNMENT:
OBJECTIVE TEST:
1. Foreign key is a field in a relational table that matches a ___ of another table.
(a) candidate key (b) row (c) field (d) none of the above
2. Each value of the primary key uniquely identifies one ___ of the table. (a) column
(b) row (c) field (d) none of the above
3. The ___ the normal form applicable to a table, the less vulnerable it is to
inconsistencies and anomalies. (a) better (b) lower (c) higher (d) none of the
above
WEEK SIX
DATE:.........................................
TOPIC: ENTITY RELATIONSHIP MODEL
CONTENT:
1. Entities, attributes and relationship
2. Additional features of entity model
Sub-topic 1
Entities, attributes and relationship
Unit price
Attributes
Name
SUPPLIER
Customer
Address
The rectangle in the diagram above are called entity type and the ovals are called attributes. The
entities are the ‘things’ in business environment about which we want to store data. The attributes
provide us with a means of organizing and structuring the data.
Entities
Entities are drawn as rectangular boxes containing a noun in singular form.
You will see later that each entity you draw ultimately becomes a table in your database. You might
want to keep this transformation from entity to table in mind when selecting the names of your
entities. E.g. your entity names should be short but descriptive.
Relationship
A relationship between entities is drawn as a line bisected by a diamond. The diamond contains a
verb (or short verb phrase) that describes the nature of the relationship between the entities.
Named relationship are used to make the ERDs more readable. However, unlike entity names,
relationship names never show up in the final database.
buys
Attributes
Attributes are properties or characteristics of a particular entity about which we wish to collect and
store data. In addition, there is typically one attribute that uniquely identifies particular instances of
the entity. E.g. each of your customers may have a unique customer ID. Such attributes are known as
Key attributes.
Name
e Phone No
CustID
Sub-topic 2
Additional features of entity model
Associative entities
Given the number and importance of the attributes attached to the ‘buys’ relationship, it makes
sense to treat the relationship as an entity as an entity in its own right. To transform a relationship
into an entity on an ERD, we use a special symbol called an associative entity. The notation for an
associative entity is a relationship diamond nested inside of an entity rectangle.
Name
Phone No.
CustID
Contact person
Product
Sale
EVALUATION:
i. What are entities?
ii. What are attributes?
iii. What are associative entities?
READING ASSIGNMENT:
Study the topic ‘Relational Model” using students’ textbook
WEEKEND ASSIGNMENT:
OBJECTIVE TEST:
1. The ___ provide us with a means of organizing and structuring the data.
2. A set of tools and procedures for applying the tools that specifies the notation used
within the organization is called ______
3. To transform a relationship into an entity on an ERD, we use a special symbol called
an (a) Entity (b) Attribute (c) associative entity (d) none of the above
WEEK SEVEN : MID TERM BREAK
WEEK EIGHT
DATE:.........................................
TOPIC: RELATIONAL MODEL
CONTENT:
1. Creating and modifying relations using SQL
2. Integrity constraints over relations
Sub-topic 1
The relational model for database management is a database model based on first –order predicate
logic, first formulated and proposed in 1969 by E.F. Codd.
Activity Activity
Code
23 Patching
24 Overlay
Activity Date
25 Crack Code Route No
24 01/12/01 1-95
26 Sealing
24 02/08/01 1-66
Date Activity
Code Route No
01/12/01 24 1-95
01/15/01 23 1-495
02/08/01 24 1-66
The purpose of the relational model is to provide a declarative method for specifying data and
queries.
SQL (often referred to as Structured Query Language) is a programming language designed for
managing data in relational database management system (RDBMS). It is used for data insert, query,
update and delete, schema creation and modification, and data access control.
KEYWORD USE
SELECT Extract data from a database
UPDATE Updates data in a database
DELETE Deletes data from a database
INSERT Insert new data into a database
DDL part of SQL permits creating and deleting of Databases and database tables.
KEYWORDS USE
CREATE DATABASE Creates a new database
ALTER DATABASE Modifies a database
CREATE TABLE Creates a new table
ALTER TABLE Modifies a table
DROP DATABASE Deletes a database
DROP TABLE Deletes a table
CREATE INDEX Creates an index(search key)it is always an
integer
DROP INDEX Deletes an index
ADD Add a column or a constraint to a table
Example:
SOLUTION:
CREATE DATABASE shsdb
2. The CREATE TABLE Statement: This is used to create a table in a database. The
syntax(command) is as follows:
CREATE TABLE table_name
(That is, type CREATE then a spacebar, TABLE then another spacebar then types the table
name then hit Enter).
The only required elements of a CREATE TABLE command are the CREATE TABLE command itself and
the name of the table, but usually you will want to define some fields or other aspects of the table.
Consider this simple example.
Example:
Suppose that you want to create a table called student to store the names, age, class and the scores
of students offering ICT in your school.
SOLUTION
CREATE TABLE student
(
Student_id,
FirstName,
LastName,
Age,
Class,
Scores
)
The empty table can now be filled with INSERT INTO statement.
1. Go to all program and navigate to Microsoft Access
2. Click on blank Database
3. Enter the name shs on the column for database name
4. On the main menu click on Create tab
5. On the Create tab, in the Macros & Code group, click Query Design.
6. Close the Show Table dialog box.
7. On the Design tab, in the Query Type group, click Data Definition.
The design grid is hidden, and the SQL view object tab is displayed.
4. Type the following SQL statement:
5. CREATE TABLE student (student_id int(10), FirstName varchar(40), LastName varchar(40), Age int(10),
Class varchar(40), Scores int(5))
6. On the Design tab, in the Results group, click Run.
MODIFY A TABLE
To modify a table, you use an ALTER TABLE command. You can use an ALTER TABLE command to add,
modify, or drop (remove) columns or constraints. An ALTER TABLE command has the following
syntax:
ALTER TABLE table_name predicate
SUB-TOPIC 2:
INTEGRITY CONSTRAINTS OVER RELATIONS
Create a constraint or a relationship
A constraint establishes a logical condition that a field or combination of fields must meet when
values are inserted. Constraints are used to limit the type of data that can go into a table or a
particular field. For example, a UNIQUE constraint prevents the constrained field from accepting a
value that would duplicate an existing value for the field.
A relationship is a type of constraint that refers to the values of a field or combination of fields in
another table to determine whether a value can be inserted in the constrained field or combination
of fields. You do not use a special keyword to indicate that a constraint is a relationship.
To create a constraint, you use a CONSTRAINT clause in a CREATE TABLE or ALTER TABLE command.
There are two kinds of CONSTRAINT clauses: one for creating a constraint on a single field, and
another for creating a constraint on multiple fields.
Single-field constraints
A single-field CONSTRAINT clause immediately follows the definition of the field that it constrains,
and has the following syntax:
Multiple-field constraints
A multiple-field CONSTRAINT clause can be used only outside a field-definition clause, and has the
following syntax:
CONSTRAINT constraint_name
{PRIMARY KEY (pk_field1[, pk_field2[, ...]]) |
UNIQUE (unique1[, unique2[, ...]]) |
NOT NULL (notnull1[, notnull2[, ...]]) |
FOREIGN KEY [NO INDEX] (ref_field1[, ref_field2[, ...]])
REFERENCES foreign_table
[(fk_field1[, fk_field2[, ...]])] |
[ON UPDATE {CASCADE | SET NULL}]
[ON DELETE {CASCADE | SET NULL}]}
EVALUATION:
i. What is a constraint?
ii. What is Data manipulation Language (DML)?
iii. What does Data Definition Language (DDL) mean?
READING ASSIGNMENT:
Study the topic ‘Integrity constraint” using students’ textbook
WEEK NINE
DATE:.........................................
TOPIC: RELATIONAL MODEL
CONTENT:
1. Enforcing integrity constraints
2. Querying relational data
Sub-topic 1
Constraints Meaning
NOT NULL Enforces a column not to accept NULL
values, that is the field cannot be empty.
UNIQUE KEY Prevents duplicate data
PRIMARY KEY This constraint uniquely identifies each
record in a database table. It always carries a
unique value
FOREIGN KEY This enforces a constraint that prevents
actions that would destroy links between
tables, and prevents invalid data being
inserted.
CHECK If you define a CHECK constraint on a single
column it allows only certain values for this
column. If you define a CHECK constraint on
a table it can limit the values in certain
columns based on values in other columns in
the row.
DEFAULT allow you to specify a value that
the database will use to populate fields that
are left blank in the input source.
(
teacher_id int NOT NULL,
LastName,
Age,
email_address,
SUB-TOPIC 2:
Definition: Queries are the primary mechanism for retrieving information from a database and
consist of questions presented to the database in a predefined format. Many database management
systems use the Structured Query Language (SQL) standard query format.
There are various SQL query statements which we will look at briefly and what they are meant for.
A SQL SELECT statement can be broken down into numerous elements, each beginning with a
keyword. Although it is not necessary, common convention is to write these keywords in all capital
letters. We will focus on the most fundamental and common elements of a SELECT statement,
namely
SELECT
FROM
WHERE
ORDER BY
Result
Explicitly specifying the desired fields also allows us to control the order in which the fields
are returned, so that if we wanted the last name to appear before the first name, we could
write it this way:
We can continue with our previous query, and limit it to only those students in ss1:
Only students in ss1 will be echoed. If you want to get other classes you declare it in the query and
the result will be displayed.
ORDER BY Class
The result of the query will arrange the student in order of their class.
EVALUATION:
i. Define Query.
ii. What elements can we break SELECT statement into?
iii. Differentiate between The WHERE Clause and The ORDER BY Clause
Prepare a student database with the following fields, Firstname, Lastname, Class, scores and run
queries on it.