Vous êtes sur la page 1sur 44

CS490 – Database Management System

CS490
Database Management System

Section 1 : Company Information


Section 2 : Database
Section 3 : Interface
Section 4 : Coding
Section 5 : Advanced Queries
Section 6 : Form & Report
Section 7 : Triggers & Cursors & Functions

Prepared by: Dr. Saatchi, Seyed Mohsen 1/44


Section 1 2 3 4 5 6 7

Section 1: Introduction
State three points showing database design benefit:
• Makes it easy to create database diagrams
• Saves data in central location, so changes can be made from almost
any computer
• Provides immediate detailed feedback on the design

Mention four Data types:


• Text (character)
• Numeric
• Date/Time
• Image

The CHAR or NCHAR is a text data type. (True)

The VARCHAR2 & NVARCAHR2 is a text data type. (True)

The LONG is a text data type. (True)

The Byte is a numeric data type and its 8 bit. (True)

What meant by Data base?


A collection of data stored in a standardized format, designed to be shared
by multiple users.

What meant by Database Management System?


Software that defines a database, stores the data, supports a query language,
produces reports, and creates data entry screens.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

What do you need in Application Development?


• Feasibility
• Analysis
• Design
• Development
• Implementation

Mention four steps for database design:


• Identify business rules.
• Define tables and relationships.
• Create input forms and reports.
• Combine as applications for users.

Mention the components of a DBMS?


Database engine
The heart of the DBMS. It responsible for storing, retrieving, and
updating the data.

Data dictionary
Holds the definitions of all of the data tables.

Query Processor
It enables developers and users to store and retrieve data.

Report writer
Enables you to set up the report on the screen to specify how items will
be displayed or calculated.

Forms generator (input screens)


Helps the developer create input forms (enter data).

Application generator

A collection of forms and reports designed for a specific user task.


A good DBMS contains an application generator.

Prepared by: Dr. Saatchi, Seyed Mohsen 3/44


Section 1 2 3 4 5 6 7

Communications
Security & other Utilities

Mention the Advantages of Database Approach:


• Minimal data redundancy.
• Data consistency.
• Integration of data.
• Sharing of data.
• Enforcement of standards.
• Ease of application development.
• Uniform security, privacy and integrity.
• Data independence.

Database Management Approach


• Data is most important
• Data defined first
• Standard format
• Access through DBMS
• Queries, Reports, Forms
• Application Programs
• 3GL Interface
• Data independence
• Change data definition without changing code
• Alter code without changing data
• Move/split data without changing code

Mention some drawback problems


• Uncontrolled Duplication
• Inconsistent data
• Inflexibility
• Limited data sharing
• Poor enforcement of standards
• Poor programmer productivity
• Excessive program maintenance
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Mention some of Database Types:


• Hierarchical Database: To retrieve data, you must start at the top &
retrieve all nested data
• Network Database
• Relational Database
• Object-Oriented DBMS

__________________A DBMS tool that assists the developer in creating a


complete application package. Common tools include menu and toolbar
generators and an integrated context-sensitive Help system.
Application generator

__________________ A collection of data stored in a standardized format,


designed to be shared by multiple users. A collection of tables for a
particular business situation.
Database

__________________ the heart of the DBMS. It is responsible for storing,


retrieving, and updating the data.
Database Engine

_________________Software that defines a database, stores the data,


supports a query language, produces reports, and creates data entry screens.
Database Management System (DBMS)

___________________holds the definitions of all of the data tables and


describes the type of data that is being stored.
Data Dictionary

___________________ separates the data from the programs, which often


enables the data definition to be changed without altering the program.
Data independence

Prepared by: Dr. Saatchi, Seyed Mohsen 5/44


Section 1 2 3 4 5 6 7

___________________ a quick examination of the problems, goals, and


expected costs of a proposed system. The objective is to determine whether
the problem can reasonably be solved with a computer system.
Feasibility study

___________________ A DBMS tool that enables you to set up input forms


on the screen.
Forms Generator

___________________An older DBMS type that organizes data in


hierarchies that can be rapidly searched from top to bottom, e.g., Customer
—Order—Order Item.
Hierarchical Database

_________________An older DBMS type that expanded the hierarchical


database by supporting multiple connections between entities. A network
database is characterized by the requirement that all connections had to be
supported by an index.
Network Database

__________________A database system that holds objects, including


properties and methods. It supports links between objects, including
inheritance.
Object-oriented (OO) database

__________________The use of a database for data analysis. The focus is


on retrieval of the data. The primary goals are to provide acceptable
response times, maintain security, and make it easy for users to find the data
they need.
Online Analytical Processing (OLAP)
CS490 – Database Management System

Section 1 2 3 4 5 6 7

____________________In object-oriented programming, the ability to store


objects (in a file or database) so that they can be retrieved at a later
Data.
Persistent Objects

_________________In SQL-99 a proposed method for storing methods


associated with objects. The module code would be stored and retrieved
automatically by the DBMS.
Persistent stored modules

__________________The most popular type of DBMS. All data is stored in


tables (sometimes called relations). Tables are logically connected by the
data they hold (e.g., through the key values). Relational databases should be
designed through data normalization.
Relational Database

_________________A DBMS tool that enables you to set up reports on the


screen to specify how items will be displayed or calculated. Most of these
tasks are performed by dragging data onto the screen.
Report writer

_________________I inherits all of the columns from a base table. It


provides inheritance similar to that of the abstract data types; however, all
data is stored in separate columns.
Sub Title

Prepared by: Dr. Saatchi, Seyed Mohsen 7/44


Section 1 2 3 4 5 6 7

Section 2: Data Design

Organizations are particularly interested in evaluating benefits in three key


areas:
• Reduction of costs.
• Increase in sales or revenue.
• Competitive advantage.

Three common types of models used to design system:


• Process models.
• Class or object models.
• Event models.

Initial steps in database design:


• Identify the exact goals of the system.
• Talk with the users to identify the basic forms and reports.
• Identify the data items to be stored.
• Design the classes (tables) and relationships.
• Identify any business constraints.
• Verify the design matches the business rules.

For the initial design you need three basic pieces of information:
• The data that needs to be collected.
• The data type.
• The amount of data involved.

What is an Entity?
Some item in the real world that you wish to track.
Entity i.e. described by attributes or properties.

What is a Class?
Entity listed with its properties.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

What is a Method?
A function that is performed by the class.

What is a Class diagram?


Displays each class as box containing the list of properties for the class.

Association:
A relationship between two or more classes.

Relational database:
A collection of tables.

Table:
A collection of columns (attributes) describing an entity.

Two important aspects to a relational database are:


1- All data must be stored in tables.
2- All tables must be carefully defined tp provide flexiplity and minimize
problems.

Data normalization:
The process of defining tables properly to provide flexibility, minimizes
redundancy, and ensure data integrity.
Note: The aim of Data normalization is to produce a list of nicely behaved tables.

Primary Key:
Is a column or set of columns that identifies a particular row?

Note: In most cases separate keys will be created to ensure they are unique.

Note: The relationship between the primary key and the rest of the data is
one to one.

State there types of relationships:


• One-to-One
• One-to-many
• Many-to-many

Prepared by: Dr. Saatchi, Seyed Mohsen 9/44


Section 1 2 3 4 5 6 7

Sample Association Rules (Multiplicity)


There is a problem with relation many to many, how can we solve it?
By make all many to many relationships be converted to a set of one to
many relationships by adding new entity.

Association Details: Aggregation


The Sale consists of a set of Items being sold.

Note: If order did matter, you would simply put the notation (ordered)
underneath the association.

Association Details: Composition


Is a stronger aggregate association that does arise more often?
Aggregation where the components become the new object.

Association Details: Generalization

What meant by Inheritance?


Means that the object in the derived classes have all of the properties
from the higher classes, as well as those defined in their own class.

Class hierarchy:
Which shows how classes are derived from each other, and highlights which
properties and functions are inherited?

What meant by Reflexive association:


A relationship from one class back to itself.

Data type:
Text – Numbers – Dates & Times

Event Examples
• Business Even
• Data Event
• User Event
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Design Importance: Large Projects


Design is harder on large projects.

Communication with multiple users.


Communication between IT workers.

Need to divide project into pieces for teams.


• Finding data/components.
• Staff turnover--retraining.
• Need to monitor design process.

Evaluation.
Build systems that can be modified later.

Documentation.
Communication/underlying assumptions and model.

Aggregation
The generic name for several SQL functions that operate across the selected rows. Common
examples include SUM, COUNT, and AVERAGE.

Association
Connections between classes or entities.

Association role
In UML, the point where an association attaches to a class. It can be named, and generally
shows multiplicity, aggregation, or composition.

Binary large object


(BLOB) A data domain for undefined, large chunks of data. A BLOB (or simple object) type can
hold any type of data, but the programmer is often responsible for displaying, manipulating,
and searching the data.

Class diagram
A graph of classes connected through relationships. It is designed to show the static structure
of the model. Similar to the entity relationship diagram.

Class hierarchy
A graph that highlights the inheritance relationships between classes.

Collaboration diagram
A UML diagram to display interactions among objects. It does not show time as a separate
dimension. It is used to model processes.

Section 1 2 3 4 5 6 7

Prepared by: Dr. Saatchi, Seyed Mohsen 11/44


Data normalization
The process of creating a well-behaved set of tables to efficiently store data, minimize
redundancy, and ensure data integrity. See first, second, and third normal form.

Data type
A type of data that can be held by a column. Each DBMS has predefined system domains
(integer, float, string, etc.). Some systems support user-defined domains that are named
combinations of other data types.

Derived class
A class that is created as an extension of another class. The programmer need only define the
new attributes and methods. All others are inherited from the higher level classes. See
inheritance.

Encapsulation
In object-oriented programming, the technique of defining attributes and methods within a
common class. For example, all features and capabilities of an Employee class would be
located together. Other code objects can use the properties and methods but only by
referencing the Employee object.

Composition association
A relationship in which an object is composed of a collection of other objects. For example, a
bicycle is built from components. In UML, it is indicated with a small filled diamond on the
association end.
CS490 – Database Management System

Section 1 2 3 4 5 6 7
Section 3: Data Normalization

By designing database tables carefully it will:


• Save space.
• Minimize duplication.
• Protect the data to ensure its consistency.
• Provide faster transactions by sending less data.

Type of keys:
Primary key:
• Every table (object) must have a primary key.
• Uniquely identifies a row (One-to-One).

Composite keys:
• Tables that will use more than one column as part of the
primary key.
• We need it when the table contains a one-to-one or many-to-
many relationship with another table.

Foreign key:
• It is a primary key but in other table.
• Customer ID is a primary key within the customer table. It is
known as a foreign key.

Surrogate keys:
• Are often hidden.

What happens if two users attempt to generate a new key at the same time?
A good DBMS handles these problems automatically.
• In Microsoft Access they use the auto number data type. But if
there is a new value to generate the process is not automatic.
• In SQL Server: Identity data type.
• In Oracle: SEQUENCES command (but require additional
programming)
Note:
A detailed class diagram can describe each table and include all properties.

Prepared by: Dr. Saatchi, Seyed Mohsen 13/44


Section 1 2 3 4 5 6 7

Drawback:
Numbers are not related to any business data, so the application needs to
hide them and provide other look up mechanisms.

Note: There are problems with repeating data known as an insertion anomaly
and a deletion anomaly. These problems arise because you tried to add or
delete all the data in one table.
First Normal Form
When a table has no repeating groups, it is said to be in first normal form.

Remove repeating sections


• Split into two tables
• Bring key from main and repeating section
There is a problem with the first normal form, which is:
• Replication
• Hidden dependency
Second Normal Form
• Each non-key column must depend on the entire key.
Dependence (definition)
If given a value for the key you always know the value of the property in
question, then that property is said to depend on the key.
If you change part of a key and the questionable property does not
change, then the table is not in 2NF.

There is a problem with the second normal form


Replication
Hidden dependency and the solution here is to split table.
Third Normal Form
To be in 3NF a table must already be in 2NF, and every non-key
column must depend on nothing but the key.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

There is a problem in this example:


RentalForm2(TransID, RentDate, CustomerID, Phone, Name, Address, City,
State, ZipCode), so there are two solutions:
• make CustomerID part of the key.
• Split the table (if the tablr is already in 2NF this will be the only
choice that work).

Dependence (definition)
• If given a value for the key you always know the value of the
property in question, then that property is said to depend on the
key.
• If you change the key and the questionable property does not
change, then the table is not in 3NF.

3NF Rules/Procedure
Split out repeating sections
Be sure to include a key from the parent section in the new piece so the two
parts can be recombined.

Verify that the keys are correct


Is each row uniquely identified by the primary key?
Are one-to-many and many-to-many relationships correct?
Check “many” for keys columns and “one” for non-key columns.
Note: Make sure that each non-key column depends on the whole key and nothing
but the key.

No hidden dependencies.

To check your tables, you essentially repeat the steps in normalization:


• First: Make sure that you have pulled out every repeating group.
• Second: Look at each non-key column and ask your self if it depends
on the whole key and nothing but the key.
• Third: Verify that the tables can be reconnected.
• Fourth: Ask your self if each table represents a single object.
• Finally: Enter sample data for each table and make sure that you are
not entering duplicate rows.

Prepared by: Dr. Saatchi, Seyed Mohsen 15/44


Section 1 2 3 4 5 6 7

Boyce-Code Normal Form (BCNF)


There are an a problem which is Hidden dependency

Fourth Normal Form


Technically, if you keyed every column, any table would be in 3NF, which
does not solve any problems.

Note: In some cases, there are hidden relationships between key properties.

Domain-Key Normal Form (DKNF)


If a table is in DKNF, Fagin proved that it must also be in 4NF, 3NF and all
of the other normal forms.

The goal of DKNF:


• To have each table represent one topic and for all the business rules to
be expressed in terms of domain constraints and key relationships.
• Table will always be in 4NF.

Drawbacks
• No mechanical method to get to DKNF
• No guarantee a table can be converted to DKNF

Rules
• Table => one topic
• All business rules explicitly written as domain constraints and key
relationships.
• No hidden relationships.

Data Rules and Integrity


Note: One of the goals of a database designer is to ensure that the data remains
accurate.

Type of data integrity:


• Type of constraint is to choose data from a set of predefined options.
• Type of data integrity is a bit more complicated but crucial in a relational
database.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Referential integrity
Exists when a value for a foreign key can be entered only if the
corresponding value already exists in the originating table.
Auto number
A type of data domain where the DBMS automatically assigns a unique identification number
for each new row of data. Useful for generating primary keys.

Boyce-Code normal form


(BCNF) All dependencies must be explicitly shown through keys. There cannot be a hidden
dependency between non-key and key columns.

Cascading delete
When tables are linked by data, if you delete a row in a higher level table, matching rows in
other tables are deleted automatically. For example, if you delete Customer 1173, all orders
placed by that customer are also deleted.

Composite key
A primary key that consists of more than one column. Indicates a many-to-many relationship
between the columns.

Data dictionary
Holds the definitions of all of the data tables and describes the type of data that is being
stored.

Data integrity
Keeping accurate data, which means few errors and means that the data reflects the true
state of the business. A DBMS enables you to specify constraints or rules that help maintain
integrity, such as prices must always be greater than 0.

Data volume
The estimated size of the database. Computed for each table by multiplying the estimated
number of rows times the average data length of each row.

Default values
Values that are displayed and entered automatically. Used to save time at data entry.

Deletion anomaly
Problems that arise when you delete data from a table that is not in third normal form. For
example, if all customer data is stored with each order, when you delete an order, you could
lose all associated customer data.

Dependence
An issue in data normalization. An attribute A depends on another attribute B if the values of A
change in response to changes in B. For example, a customer's name depends on the
Customer ID (each employee has a specific name). On the other hand, a customer's name
does not depend on the Order ID. Customers do not change their names each time they place
an order.

Domain-key normal form


(DKNF) The ultimate goal in designing a database. Each table represents one topic, and all of
the business rules are expressed in terms of domain constraints and key relationships. That is,
all of the business rules are explicitly described by the table rules.

Section 1 2 3 4 5 6 7

Prepared by: Dr. Saatchi, Seyed Mohsen 17/44


First normal form
(1NF) A table is in 1NF when there are no repeating groups within it. Each cell can contain
only one value. For example, how may items can be placed in one Order table? The items
repeat, so they must be split into a separate table.

Foreign key
A column in one table that is a primary key in a second table. It does not need to be a key in
the first table. For example, in an Order table, Customer ID is a foreign key because it is a
primary key in the Customer table.

Fourth normal form


(4NF) There cannot be hidden dependencies between key columns. A multi valued dependency
exists when a key determines two separate but independent attributes. Split the table to make
the two dependencies explicit.

Hidden dependency
A dependency specified by business rules that is not shown in the table structure. It generally
indicates that the table needs to be normalized further and is an issue with Boyce-Code or
fourth normal form.

Insertion anomaly
Problems that arise when you try to insert data into a table that is not in third normal form.
For example, if you find yourself repeatedly entering the same data (e.g., a customer's
address), the table probably needs to be redefined.

Master-detail
A common one-to-many relationship often found on business forms, where the main form
(e.g., Order) displays data for the master component, and a sub form (e.g., Order Items)
displays detail data. Sometimes called a parent-child relationship.

Metadata
Data about data, or the description of the data tables and columns. Usually held in the data
dictionary.

Referential integrity
A data integrity constraint where data can be entered into a foreign key column only if the
data value already exists in the base table. For example, clerks should not be able to enter an
Order for Customer ID 1173 if Customer ID 1173 is not in the Customer table.

Repeating groups
Groups of data that repeat, such as items being ordered by a customer, multiple phone
numbers for a client, and tasks assigned to a worker.

Second normal form


(2NF) A table is in 2NF if every non key column depends on the entire key (not just part of it).
This issue arises only if there is a concatenated key (with multiple columns).

Third normal form


(3NF) A table is in third normal form (3NF) if each non key column depends on the whole key
and nothing but the key.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Section 4: Introduction to Queries

Note: Query system is becoming more standardized, so that developers and


users can learn one language and use it on a variety of different system.

What meant by SQL?


Is the standard database query language.

Note: Most database system provides a query by example (QBE) method to


help beginners create SQL queries.

Three tasks of a query language:


• define the database (DDL)
• Change the data.
• Retrieve data.

Note: The SELECT command is used to retrieve data.


SELECT command is to retrieve specified columns of data for rows that
meet some criteria.

Four Questions to Create a Query:


• What output do you want to see?
• What do you already know (or what constraints are given)?
• What tables are involved?
• How are the tables joined together?

Prepared by: Dr. Saatchi, Seyed Mohsen 19/44


Section 1 2 3 4 5 6 7

Section 5: Advanced Queries

Note: One of the most powerful features of the SQL SELECT command.

Two key points will help you learn how to use sub queries:
1- SQL was designed to work with sets of data avoid thinking in terms
of individual rows
2- You can split nested queries into their separate parts and deal with
the parts individually.

Note: Some special SQL operators (IN, ALL, ANY, EXISTS)

Sub query with ANY and ALL


• The ANY and ALL operators combine comparison of numbers with
subsets.
• Word SOME can be used in place of the word ANY.

OUTER JOINS
The INNER JOIN command instructs the DBMS to match every entry in the
Sel-Animal table with a corresponding Animal ID in the Animal table.

Note: The OUTER JOIN describes what should happen when values in one
table do not exist in the second table.

In joining two tables, you have to consider two basic situations:


1- A value might exist in the left table with no matching value in the
right table.
2- A value might exist in the right table with no matching value in the
left table.

Correlated Sub query are Dangerous


Correlated Sub query a type of queries known to run for several days
without finishing.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

UNION, INTERSECT, EXCEPT


UNION: to combines rows of data.
INTERSECT: Retrieves only the rows that are in both tables.
EXCEPT: Retrieves rows that exist in only one table.

Multiple JOIN Columns


Sometimes need to JOIN tables on more than one column.

Reflexive Join
Need to connect a table to itself.

Inequality Join
Where the comparison is made with inequality operators (less than, greater
than) instead of an equals sign.

Note: Queries with “Every” Need EXISTS

CREATE TABLE
Defines a new table

Constraints:
Are rules that are enforced by the database system?

SQL Data Manipulation Commands

INSERT
To insert one row of data at a time.

DELETE
To remove the older data

UPDATE
To update the record on the specific table.

Prepared by: Dr. Saatchi, Seyed Mohsen 21/44


Section 1 2 3 4 5 6 7

ALL
A SQL SELECT clause often used with sub queries. Used in a WHERE
clause to match all of the items in a list. For example, Price > All (. . .)
means that the row matches only if Price is greater than the largest value in
the list.
ALTER TABLE
A SQL data definition command that changes the structure of a table. To
improve performance, some systems limit the changes to adding new
columns. In these situations, to make major changes, you have to create a
new table and copy the old data.

ANY
A SQL SELECT clause often used with sub queries. Used in a WHERE
clause to match at least one of the items in a list. For example, Price > ANY
(. . .) means that the row matches as long as Price is greater than at least one
item in the list.

CASE
A SQL operator supported by some systems. It examines multiple conditions
(cases) and takes the appropriate action when it finds a match.

Concatenate
A programming operation that appends one string on the end of a second
string. For example, Last Name & "," & First Name could yield "Smith,
John".

Constraint
In SQL, a constraint is a rule that is enforced on the data. For example, there
can be primary-key and foreign-key constraints that limit the data that can be
entered into the declared columns. Other business rules can form constraints,
such as Price 0.

Correlated sub query


A sub query that must be reevaluated for each row of the main query. Can be
extremely slow. Can often be avoided by creating a temporary table and
using that in the sub query instead.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

CREATE DOMAIN
A SQL data definition command to create a new logical grouping of tables.
With some systems it is equivalent to creating a new database. This
command is not available in Oracle or SQL Server.

CREATE TABLE
A SQL data definition command to create a new table. The command is
often generated with a program.

CREATE VIEW
A SQL command to create a new view or saved query.

Data type
A type of data that can be held by a column. Each DBMS has predefined
system domains (integer, float, string, etc.). Some systems support user-
defined domains that are named combinations of other data types.

DELETE
A SQL data manipulation command that deletes rows of data. It is always
used with a WHERE clause to specify which rows should be deleted.
DROP
A SQL data definition command that completely removes a table from the
database- including the definition. Use it sparingly.
Equi-join
A SQL equality JOIN condition. Rows from two tables are joined if the
columns match exactly. Equi-join is the most common JOIN condition.
Rows that have no match in the other table are not displayed.

EXCEPT
A SQL operator that examines rows from two SELECT statements. It
returns all rows from one statement except those that would be returned by
the second statement. Sometimes implemented as a SUBTRACT command.
See UNION.
EXISTS
A SQL keyword used to determine if sub queries return any rows of data.

Prepared by: Dr. Saatchi, Seyed Mohsen 23/44


Section 1 2 3 4 5 6 7

FULL JOIN
A JOIN that matches all rows from both tables if they match, plus all rows
from the left table that do not match, and all rows from the right table that do
not match. Rarely used and rarely available. See LEFT JOIN and RIGHT
JOIN.
IN
A SQL WHERE clause operator typically used with sub queries. It returns a
match if the selected item matches one of the items in the list. For example,
WHERE Item ID IN (115, 235, 536) returns a match for any of the items
specified. Typically, another SELECT statement is inserted in the
parentheses.
Inequality join
A SQL JOIN where the comparison is made with an inequality (greater than
or less than) instead of an equality operator. Useful for placing data into
categories based on ranges of data.

INSERT
Two SQL commands that insert data into a table. One version inserts a
single row at a time. The other variation copies selected data from one query
and appends it as new rows in a different table.

INTERSECT
A set operation on rows of data from two SELECT statements. Only rows
that are in both statements will be retrieved. See UNION.

LEFT JOIN
An OUTER JOIN that includes all of the rows from the "left" table, even if
there are no matching rows in the "right" table. The missing values are
indicated by Nulls. See RIGHT JOIN and INNER JOIN. Left and right are
defined by the order the tables are listed; left is first.

OUTER JOIN
A generic term that represents a left join or a right join. It returns rows from
a table, even if there is no matching row in the other table.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Reflexive join
A situation that exists when a table is joined to itself through a second
column. For example, the table Employee (Employee ID. . . Manager ID)
could have a join from Manager ID to Employee ID.

Reflexive join
A situation that exists when a table is joined to itself through a second
column. For example, the table Employee (Employee ID. . . Manager ID)
could have a join from Manager ID to Employee ID.

RIGHT JOIN
An OUTER JOIN that includes all the rows from the "right" table, even if
there are no matching rows in the "left" table. The missing values are
indicated by NULLS. See RIGHT JOIN and INNER JOIN. Left and right
are defined by the order the tables are listed; left is first.
Schema
A collection of tables that are grouped together for a common purpose.
Self-join
A table joined to itself. See reflexive join.

Sub query
Using a second query to retrieve additional data within the main query. For
example, to retrieve all sales where price was greater than the average, the
WHERE clause could use a sub query to compute the average price.

UNION
An SQL clause to combine rows from two SELECT statements. Both
queries must have the same number of columns with the same domains.
Most systems also support INTERSECT and EXCEPT (or SUBTRACT)
operators.

UPDATE
A SQL data manipulation command that changes the values in specified
columns. A WHERE clause specifies which rows will be affected

Prepared by: Dr. Saatchi, Seyed Mohsen 25/44


Section 1 2 3 4 5 6 7

Section 6: Form & Report


Human Factors Design

• User Control
• Consistency
• Clarity
• Aesthetics
• Feedback
• Forgiveness

Windows Interface Standards

• The Windows Interface: An Application Design Guide (Microsoft)


• Navigation and Choices
• Selections from a list
• Focus
• Manipulation
• Feedback

Windows Interface:
Window components
• Frame (sizing)
• Title bar

Control-menu box
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Buttons
1. Minimize
2. Maximize
3. Close
4. Scroll box (thumb)
5. Scroll bar

Windows Menus
Drop-down
• Short Cut Keys
• Mnemonic character

Pop-up (as needed)


Message Boxes
1. Title
2. Message
3. Simple buttons
4. Icons
5. Modal (required)

Interface / Accessibility
1. Multiple Input Methods
2. Keyboard
3. Mouse
4. Voice
5. Multiple Outputs
6. Visual
7. Sound
8. Color

Prepared by: Dr. Saatchi, Seyed Mohsen 27/44


Section 1 2 3 4 5 6 7

Types of Forms
1- Tabular
• Single Row
• Sub-forms (one-to-many)
• Switchboard

2- Tabular Form

Tabular

1. Single table.
2. Designer can control data entry sequence
3. May have Buttons for sorting.

Single Row (Columnar) Form

• Data for only one row


• Can set optimal layout.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Paper forms.

• Can use color, graphics, and command buttons to make the form
• Easier to use
• Note the importance of the navigation buttons.
• Find command
• Can include Sub forms

Sub-Forms

One-to-many relationship

Switchboard Form:

• Blank Form
• Graphics/Picture/Background
• Identify User
• Choose Task.
• Contains copyright and usage notes

Prepared by: Dr. Saatchi, Seyed Mohsen 29/44


Section 1 2 3 4 5 6 7

Menu Design

• Setup Choices
• Data Input
• Print Reports
• DOS Utilities
• Backups
• Form Properties
• Data
• Integrity (Edit, Delete)
• Format (color)
• Other (Pop-up menus, Help menu)
• Controls on Forms (Complex)
• Tab
• Grid
• Calendar
• Gauge
• Slider
• Spin Box

Charts

• Build a query that generates the data to be graphed.


• Multiple Forms
• Using data on other forms
CS490 – Database Management System

Section 1 2 3 4 5 6 7
Subtotals and sub forms
Multi-page v Separate forms
• Same record set
• Screen size
• Side-by-side

Integrity in Forms

• Avoid relying on forms


• Use forms to make it easy to enter quality data
• Controls
• Selectivity
• User assistance

Large Projects & Forms:


Sometimes it’s called “International Attributes”

1Language
2Character sets and punctuation marks
3Sorting
4Data formats

Date- Time- Metric v English- Currency symbol and format- Separators


(decimal . . .) - Phone numbers
1Postal codes
2National ID Numbers

Creating a Graphical Approach


1Get the hardware.
2Add an object column to your table definition.
2Design the screens.
1. Be creative.
2. Get user input.
3. Make the user’s job easier.
4. Avoid using graphics just for show.
5. Double-click
6. Drag-and-drop
7. Programming

Prepared by: Dr. Saatchi, Seyed Mohsen 31/44


Section 1 2 3 4 5 6 7

Report Why?
• To collect data
• Summarize data

Report strength
• Easily handled
• Combine both detailed & summary data

Report Design

• Report usage/user needs.


• Report layout choices.
• Paper sizes.
• Printer constraints.
• How often is it generated?
• Events that trigger report?
• How large is the report?
• Number of copies?
• Colors?
• Security controls
• Output concerns

Report Graphs
• Separate query.
• Detail
1Locate in detail or group footer section.
2Avoid aggregation and groups in query.
3Include column that links to detail query in report.

• Subtotals and totals


1Typically located in report footer or header.
2Compare group totals
3Relies on Group By and aggregation.
4Be sure query groups match report groups
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Application
Application Features

• Application organization
• Menu
• Toolbar
• Help
• Transactions
• Improving forms
• Customized reports
• Distributing Applications

Bad poor & better design

1Bad design:
Enter data twice.
2Poor design:
Memorize data (ID) on one form to enter on second.
3Better design:
Automatically transfer data across forms.

Application Importance:
1- User interface
2- Ensure data integrity
3- Decision Support
4- Expert Systems & Intelligence

Application Organization:
Organized by user needs.
• Direct users to tasks
• Drawbacks
• Build forms and reports.
• Use menu stubs for incomplete and future work

Prepared by: Dr. Saatchi, Seyed Mohsen 33/44


Section 1 2 3 4 5 6 7

Help
On-line help replaces manuals Hypertext links to related topics defined as:
Sequential topics
1Descriptions
2Examples

Definitions / Glossary
Contents / overview
Index / keywords
Full-text search

Accessibility
A design goal to make the application usable by as many users as possible

Aesthetics
An application design goal, where layout, colors, and artwork are used to
improve the appearance

Bound control
A control on a form that is tied to a column in the database. When data is
entered or changed, the changes are automatically saved to the data table.

Check box
A square button that signifies a choice.

Clarity
The goal of making an application easier to use through elegant design and
organization that matches user tasks so that the purpose and use of the
application is clear to the user.

Combo box
A combination of a list box and a text box that is used to enter new data or to
select from a list of items.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Command button
A button on a form that is designed to be clicked. The designer writes the
code that is activated when the button is clicked.

Consistency
The transaction requirement that specifies all data must remain internally
consistent when changes are committed and can be validated by application
checks.

Context-sensitive menu
A menu that changes depending on the object selected by the user.

Controls
The generic term for an item placed on a form. Typical controls consist of
text boxes, combo boxes, and labels.

Direct manipulation of objects


A graphical interface method that is designed to mimic real world actions.

Dock able toolbar


A toolbar that users can drag to any location on the application window..

Drag-and-drop
A graphical interface technique where actions are defined by holding down a
mouse key, dragging an icon, and dropping the icon on a new object.

Feedback
A design feature where the application provides information to the user as
tasks are accomplished or errors arise.

Focus
In a window environment, a form or control has focus when it is the one that
will receive keystrokes. It is usually highlighted.

Group break
A report that splits data into groups. The split-point is called a break. Also
known as a control break.

Prepared by: Dr. Saatchi, Seyed Mohsen 35/44


Section 1 2 3 4 5 6 7

Heads-down data entry


Touch typists concentrate on entering data without looking at the screen.
Forms for this task should minimize keystrokes and use audio cues.

Help system
A method for displaying, sequencing, and searching help documentation.
Developers need to write the Help files in a specific format and then use a
Help compiler to generate the final Help file.

Human factors design


An attempt to design computer systems that best accommodate human users.

Hypertext markup language


(HTML) A display standard that is used to create documents to be shared on
the Internet. Several generators will create HTML documents from standard
word processor files.

List box
A control on a form that displays a list of choices. The list is always
displayed and takes up a fixed amount of space on the screen.

Menu
A set of application commands grouped together—usually on a toolbar. It
provides an easy reference for commonly used commands and highlights the
structure of the application.

Modal form
A form that takes priority on the screen and forces the user to deal with it
before continuing. It should be avoided because it interrupts the user.

Option button
A round button that is used to indicate a choice. By the design guide, option
buttons signify mutually exclusive choices, as opposed to check boxes.

Page footer
A report element that appears at the bottom of every page. Often used for
page numbers.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Report footer
A report element that appears at the end of the report. Often used for
summary statistics or graphs.

Report header
A report element that appears only at the start of the report. Often used for
title pages and overviews.

Scroll bars
A common graphical interface feature used to move material horizontally or
vertically.

Single-row form
An input form that displays data from one row of a table at a time. The most
common input form, since the designer has full control over the layout of the
form.

Style sheet
A special file that describes the desired layout, fonts, and styles for a set of
Web pages. It is a powerful method to establish and change styles on many
Web pages through making minor changes to one file.

Sub form
A form that is displayed inside another (main) form. The data in the sub
form is generally linked to the row currently being displayed on the main
form.

Switchboard form
A form that is used to direct users to different parts of the application. Often
used as the first form to appear. Options on the form should match the tasks
of the users.

Tab order
The sequence of controls followed on a form when the user presses the tab
or return keys.

Prepared by: Dr. Saatchi, Seyed Mohsen 37/44


Section 1 2 3 4 5 6 7

Tabular form
An input form that displays data in columns and rows. It is used when there
are few columns of data or when the user needs to see multiple rows at the
same time.

Toolbar
A small object in applications that can hold buttons and text menus. Users
can execute commands with one or two mouse clicks. Used to hold
frequently used commands, and commands that are used across the entire
application, such as printing.

Tool tip
A small object in applications that can hold buttons and text menus. Users
can execute commands with one or two mouse clicks. Used to hold
frequently used commands, and commands that are used across the entire
application, such as printing.

Unicode
A standard method of storing and displaying a variety of character sets.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Section 7: Triggers & Cursors & Functions


Procedural Languages
A traditional programming language, where you specify the sequence of a
set of commands.

SQL commands
Rae not procedural language because you tell the DBMS only what you
want done, not how to do it.

Create code
1- Within the query system
2- In forms and reports
3- Hosted in external programs

Looking Up Data
Obtaining data from a single row is straightforward with the SELECT INFO.
- It gets to the variable.
- It has one row.

Data triggers
Code that is executed when some data element is modified.
Procedures that are executed when some event arises within the database.

Event: Any process happens.

Note: The common events are Update, Insert, and Delete.

Note: The main data trigger on the row and columns each have two
attributes: BEFORE and AFTER.

Statement versus Row Triggers


The SQL defines two levels of triggers:
1- Triggers may be assigned to the overall table.
2- Triggers may be assigned to fire for each row of data being modified.

Prepared by: Dr. Saatchi, Seyed Mohsen 39/44


Section 1 2 3 4 5 6 7

Cascading Triggers

Arise when a change that fire a trigger on one table cause a change in the
second table, that triggers a change in third table, and so on.

Transactions
A set of changes that must all be made together.

The computer needs to be told which changes must be grouped into a


transaction.
1. Turn on transaction processing.
2. Signify a transaction start.
3. Signify the end.
• Success: save all changes
• Failure: cancel all changes

Must be set in module code


• Commit
• Rollback

SAVEPOINT
Divides transaction procedures into multiple pieces.

Concurrent Access
When two people try to change the same data at the same time.
In this case Final data will be wrong

Pessimistic Locks: Serialization


Serialization
Process forces transactions to run separately so that a second process cannot
even read the data being modified by the first process.

Note: One answer to concurrent access is to prevent it.


When a transaction needs to alter data, it places a SERIALIZABLE lock on
the data used, so no other transactions can even read the data until the first
transaction is completed.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Deadlock
Arises when two (or more) processes have placed locks on data and are
waiting for the other’s data.

Many solutions:
- Random wait time
- Global lock manager
- Two-phase commit – messages

Optimistic Locks
Begins by assuming that collisions are rare and unlikely to arise.
Improved performance, fewer resources allow all code to read any data (no
locks).

When code tries to write a new value


- Check to see if the existing value is different from the one you were
given earlier
- If it is different, someone changed the database before you finished,
so it is a collision--raise an error
- Reread the value and try again

Atomicity: all changes succeed or fail together.

Consistency: all data remain internally consistent (when committed) and can
be validated by application checks.

Isolation: The system gives each transaction the perception that it is running
in isolation. There are no concurrent access issues.

Durability: When a transaction is committed, all changes are permanently


saved even if there is a hardware or system failure.

Logically, generated keys could be created through two primary methods:


1- By automatic method when a new row is added to a table.
2- By separate key generation routine.

Prepared by: Dr. Saatchi, Seyed Mohsen 41/44


Section 1 2 3 4 5 6 7

Database Cursors
• Defines a SELECT statement and then point to one row at a time.
• A Loop statement enables you to move the cursor to the next row and
repeat your code to examine each row returned by query.

Purpose
• Track through table or query one row at a time.
• Data cursor is a pointer to active row.
Why?
Performance.
SQL cannot do everything.
• Complex calculations.
• Compare multiple rows.

Atomicity
The transaction element that specifies that all changes in a transaction must
succeed or fail together.

Cascading triggers
Multiple events that arise when a change that fires a trigger on one table
causes a change in a second table, that triggers a change in a third table and
so on.

Concurrent access
Performing two (or more) operations on the same data at the same time. The
DBMS must sequence the operations so that some of the changes are not
lost.

consistency, application
The goal of making an application easier to use by using the same features,
colors, and commands throughout. Modern applications also strive for
consistency with a common design guide.
CS490 – Database Management System

Section 1 2 3 4 5 6 7

Database cursor
A variable created within a programming language that defines a SELECT
statement and points to one row of data at a time. Data on that row can be
retrieved or edited using the programming language.

Deadlock
A situation that exists when two (or more) processes each has a lock on a
piece of data that the other one needs.

Durability
The transaction element that specifies that when a transaction is committed,
all changes are permanently saved even if there is a hardware or system
failure.

Isolation
The transaction requirement that says the system must give each transaction
.the perception that it is running in isolation with no concurrent access issues
Isolation level
Used to assign locking properties in transactions. At a minimum, it is used to
specify optimistic or pessimistic locks. Some systems support intermediate
levels.

Optimistic lock
A transaction lock that does not block other processes. If the data is changed
between read and write steps, the system generates an error that must be
handled by code.

Persistent stored modules


(PSM) In SQL-99 a proposed method for storing methods associated with
objects. The module code would be stored and retrieved automatically by the
DBMS.

Pessimistic lock
A complete isolation level that blocks other processes from reading a locked
piece of data until the transaction is complete. Program code will receive an
error message if the data element is locked.

Prepared by: Dr. Saatchi, Seyed Mohsen 43/44


Section 1 2 3 4 5 6 7
Procedural language
A traditional programming language that is based on following procedures
and is typically executed one statement at a time. Compared to SQL, which
operates on sets of data with one command.

Serialization
A transaction requirement that specifies that each transaction is treated
completely separately and run as if there were no other transactions.

Transaction
In a database application a transaction is a set of changes that must all be
made together. Transactions must be identified to the DBMS and then
committed or rolled back (if there is an error). For example, a transfer of
money from one bank account to another requires two changes to the
database—both must succeed or fail together.
Trigger
An event that causes a procedure to be executed. For example, clicking a
button can be a trigger, as can a change in a data value.