Database Notes-1
Database Notes-1
A database is a collection of data organized in manner that allows access, retrieval, use
and maintenance of that data.
Examples of databases:
1. Inventory management system databases: These contain information about
products, quantities, suppliers, and stock levels.
2. Library catalogs: Databases that organize information about books, authors,
genres, and availability.
3. Student records databases: Storing information about students, including their
grades, courses, attendance, and personal details.
4. Hospital patient databases: Recording patient information such as medical history,
treatments, prescriptions, and appointments.
5. Financial transaction databases: Tracking transactions, accounts, balances, and
financial statements for businesses or individuals.
6. Social media user databases: Holding user profiles, connections, posts, and
interactions on platforms like Facebook, Twitter, or LinkedIn.
7. Geographic information systems (GIS) databases: Storing geographical data like
maps, coordinates, features, and spatial relationships.
8. Online retail databases: Managing product listings, orders, customers, payments,
and shipping details for e-commerce platforms.
9. Human resources management systems (HRMS) databases: Recording employee
information such as salaries, benefits, performance reviews, and training records.
10. Research databases: Compiling academic papers, citations, authors, and research
topics for scholarly purposes.
Characteristics of databases:
Data organization: Information is structured into tables, with columns representing
fields and rows representing records.
Data integrity: Databases enforce constraints to ensure accuracy and consistency
of stored data.
Data relationships: Tables can be related through keys, allowing for efficient
retrieval and manipulation of related information.
Query capabilities: Users can retrieve specific data using queries, which are
commands or statements that extract information based on defined criteria.
Scalability: Databases can accommodate large volumes of data and support
growing needs over time.
Security: Access controls and authentication mechanisms are implemented to
protect sensitive data from unauthorized access or modifications.
Concurrent access: Multiple users can simultaneously access and modify data in
the database without interfering with each other's operations.
Types of databases:
(i) Flat file database:
Consists of a single table.
Suitable for small-scale applications with simple data storage requirements.
1
Easy to design and maintain but lacks flexibility for complex relationships.
(ii) Relational database:
Comprises multiple tables linked through common fields.
Supports complex data relationships through the use of primary and foreign keys.
Offers flexibility, scalability, and robust query capabilities for managing diverse
datasets.
Commonly used in enterprise applications and data-driven environments.
NB: A relationship determines the way in which the details in one table are related to the
details in another table. It can be a one to one relationship, one to many or many to many
relationship.
Data Integration: It allows for the integration of data from multiple sources,
enabling a holistic view of information for analysis and decision-making.
Data Security: Advanced database systems offer robust security features such as
encryption, access controls, and backup mechanisms to safeguard sensitive data
from unauthorized access or loss.
Data Consistency: Databases enforce data integrity constraints to ensure that data
remains consistent and accurate across the system, reducing errors and
inconsistencies.
Automation: Database systems can automate repetitive tasks such as data entry,
validation, and report generation, increasing efficiency and reducing manual
effort.
Scalability: As data volumes grow, electronic databases can scale up to
accommodate increasing storage and processing requirements without significant
disruption.
Accessibility: With the advent of cloud-based database solutions, users can access
and manage data from anywhere with an internet connection, promoting
collaboration and remote work.
Analytics and Insights: Databases support advanced analytics and reporting
capabilities, allowing organizations to derive valuable insights from their data for
strategic planning and decision-making.
Oracle
Lotus Approach
Corel paradox
MYSQL
Informix
Microsoft Access etc
We shall deal much with the basic one which is Microsoft Access
TERMS USED
Common terms used in database management systems
1. Data entry: The process of getting information into a database, usually done by
people
2. Objects: These are the components that makeup a database. Examples of database
objects include, tables, forms, queries, reports, modules, macros
3. An entity: is a person, place, thing, activity, or event for which data is collected
4. A field: is a single piece of information from a record. In a database table every
column represents a field
5. A record: Is a row on a datasheet and is a set of values defined by fields
6. Field name (Field Labels): Is a title of a particular column in a database table e.g.
titles like ID No, Name, Sex, District, Allowance.
5. Field Length: Is the maximum number of characters that can be stored for data in a
3
Particular field.
6. Data type (Field Type): is an attribute which determines the kind of data which
users can store in a field
7. Data redundancy: Is the repeating of data in more than one file.
8. Query: is a database object used to request for specific type of data from a database
table or combination of tables.
9. Form: is a database object that allows you to enter or view data stored in your
tables.
10. Report: is a formatted screen display or printout of the contents of one or more
tables in a database.
11. Design view: This provides the tools for creating fields in a table and other
objects.
12. Datasheet view: Allows one to update, edit and delete information from a table.
13. Attribute: a part of the description of an entity. The entity itself is described by
one or more attributes e.g. the attributes for student can be name, Address, Telephone,
etc.
14. Primary key (key field): is a field in a data file that uniquely identifies each
record. It is also used to connect two or more tables in a database
Characteristics of a primary key
It uniquely identifies each record ie cannot have repeated values
It is never empty or null
15. Foreign key: Is a primary key of one table that also appears in another table
16. Data integrity: Is the degree to which the data in any file is accurate and up-to
date.
17. A string is a data type used to represent text rather than numbers. It is comprised
of a set of characters that can also contain spaces and numbers.
18. Wild cards: Is a special character that represents one or more other characters.
Wild card characters may be used to represent a letter or letters in a word. Wild cards
can be used in access queries to look for specific information
Wildcard Description Example
* Matches any number of characters. You can use the wh* finds what, white, and why,
asterisk (*) anywhere in a character string. but not awhile or watch.
? Matches any single alphabetic character. B?ll finds ball, bell, and bill.
[] Matches any single character within the brackets. B[ae]ll finds ball and bell, but not
bill.
! Matches any character not in the brackets. b[!ae]ll finds bill and bull, but not
ball or bell.
- Matches any one of a range of characters. You must b[a-c]d finds bad, bbd, and bcd.
specify the range in ascending order (A to Z, not Z to
4
A).
# Matches any single numeric character. 1#3 finds 103, 113, and 123.
Database objects
These are the basic components that make up a database and they include:
Tables
Queries
Forms
Reports
macros
Modules etc
Modules:
5
A module is a collection of declarations, statements, and procedures that are stored
together as a unit.
Modules, like macros, are objects you can use to add functionality to your database.
Whereas you create macros in Access by choosing from a list of macro actions, you write
modules in the Visual Basic for Applications (VBA).
6
stored includes both a date
component and a time
component.
Currency Used for storing monetary 8 bytes.
values (currency).
AutoNumber A unique numeric value that 4 bytes or 16 bytes
Office Access automatically when used for
inserts when a record is added. replication ID.
Use for generating unique
values that can be used as a
primary key. Note that
AutoNumber fields can be
incremented sequentially.
Yes/No Boolean values. 1 bit (8 bits = 1 byte).
Use for True/False fields that
can hold one of two possible
values: Yes/No or True/False, for
example.
OLE(Object OLE objects or other binary Up to 1 gigabyte.
Linking and data.
Embedding) Use for storing OLE objects from
Object other Microsoft Windows
applications.
Attachment Pictures, Images, Binary For compressed
files, Office files. attachments, 2
This is the preferred data type gigabytes. For
for storing digital images and uncompressed
any type of binary file. attachments,
Note approximately 700k,
Field name should be written as depending on the
a Caption degree to which the
attachment can be
compressed.
Hyperlink Hyperlinks. Up to 1 gigabyte of
Use for storing hyperlinks to characters, or 2
provide single-click access to gigabytes of storage (2
Web pages through a URL bytes per character), of
(Uniform Resource Locator) or which you can display
files through a name in UNC 65,535 characters in a
(universal naming convention) control.
format. You can also link to
Access objects stored in a
database.
Lookup Wizard Not actually a data type; Table or query based:
instead, this invokes the Lookup The size of the bound
7
Wizard. column.
Use to start the Lookup Wizard Value based: The size
so you can create a field that of the Text field used
uses a combo box to look up a to store the value.
value in another table, query or
list of values.
Note
For phone numbers, part numbers, and other numbers you don’t intend to use for
mathematical calculations, you should select the Text data type, not the Number
data type.
For the Text and Number data types, you can specify the field size or data type
more specifically by setting a value in the FieldSize property box.
Field properties
If you want more space to enter or edit a property setting in the property box,
press SHIFT+F2 to display the Zoom box. If you are entering an input mask
or validation expression and would like help in building it, click next to the
property box to display the appropriate builder
9
An input mask is a set of literal characters and mask characters that control what you
can and cannot enter in a field. For example, an input mask can require users to enter
dates or telephone numbers that follow the conventions for a specific country/region
You use an input mask whenever you want users to enter data in a specific way.
For example, if you want users to enter phone numbers in the British format or
German format, use an input mask.
By default, you can apply input masks to table fields that are set to
the Text,
Number (except ReplicationID),
Currency, and
Date/Time data types.
You can also apply input masks to form controls, such as text boxes, that you
bind to table fields that are set to those data types.
10
& Any character or space. You must enter either a single
character or a space in this position.
! Causes the input mask to fill from left to right instead of from
right to left.
"Literal Encloses any text that you want users to see in double
text" quotation marks.
Password In Design view for tables or forms, setting the Input Mask
property to Password creates a password entry box. When
users type passwords in the box, Access stores the characters
but displays asterisks (*).
(000) 000-0000 (206) 555-0199 In this case, you must must enter an
area code because that section of
the mask (000, enclosed in
parentheses) uses the 0 placeholder.
(999) 000-0000! (206) 555-0199 In this case, the area code section
( ) 555-0199 uses the 9 placeholder, so area
codes are optional. Also, the
exclamation point (!) causes the
mask to fill in from left to right.
(000) AAA-AAAA (206) 555-TELE Allows you to substitute the last four
digits of a U.S. style phone number
with letters. Note the use of the 0
11
placeholder in the area code section,
which makes the area code
mandatory.
Query
Query: is a database object used to request for specific type of data from a database table or
combination of tables.
This is achieved through the use of query criteria
A query criteria is a rule that identifies the records that you want to include in the query result.
Use this criterion Query result
"China" Returns records where the Value in the field is set to
China.
Not "Mexico" Returns records where the Value in the field is set to
12
any other value in the field other than Mexico.
Like A* Returns records for all fields whose values start with
"A",
NOTE When used in an expression, the asterisk (*)
represents any string of characters — it is also called a
wildcard character.
Like "*Korea*" Returns records for all fields that contain the string
"Korea".
K*and*I
*D*
K*or b*
<>john
*E or *I
Not Like U* Returns records for all fields whose names start with a
character other than "U".
Not Like "*Korea*" Returns records for all fields that do not contain the
string "Korea".
Like "*ina" Returns records for all fields whose names end in "ina",
such as China and Argentina.
Not Like "*ina" Returns records for all fields that do not end in "ina",
such as China and Argentina.
Is Null Returns records where there is no value in the the field.
Is Not Null Returns records where the value is not missing in the
field.
"" (a pair of quotes) Returns records where the field is set to a blank (but
not null) value.
Not "" Returns records where the field has a nonblank value.
"" Or Is Null Returns records where there is either no value in the
field, or the field is set to a blank value.
Is Not Null And Not Returns records where the field has a nonblank, non-
"" null value.
>= "Mexico" Returns records of all fields with values beginning with
Mexico and continuing through the end of the alphabet.
Like "[A-D]*" Returns records for fields whose values start with the
letters "A" through "D".
"USA" Or "UK" Returns records for USA and UK.
In("France", "China", Returns records for all fields with values specified in
"Germany", "Japan") the list.
Right([Value in the], Returns records for all fields where the last letter is "y".
13
1) = "y"
Len([Country/ Returns records for countries/regions whose name is
Region]) > 10 more than 10 characters long.
Like "Chi??" Returns records for fields with values, such as China
and Chile, whose names are five characters long and
the first three characters are "Chi".
< 100 Returns records where the value is less than 100
<= 100 (<100).
Displays records where the value is less than or equal
to 100.
>10 and <90 Returns records where the value is between (but not
including) 10 and 90
<50 or >100 Returns records where the value is not between 50 and
100.
In(20, 25, 30) Returns records where the value is either 20, 25, or 30.
Like "*4.99" Returns records where the value ends with "4.99", such
as 4.99, 14.99, 24.99, and so on.
Is Not Null Returns records where the value is not missing in the
field.
14
Remember to surround date values with the #
character so that Access can distinguish
between date values and text strings.
Not #2/2/2006# Returns records that took place on a day other
than Feb 3, 2006.
5/*/* Displays all records on 5th of any month of any
year
5/10/*
*/6/* All records with the month of june
*/*/2012
< #2/2/2006# Returns records that took place before Feb 2,
2006.
> #2/2/2006# Returns records that took place after Feb 2,
2006.
>#2/2/2006# and Returns records took place between Feb 2, 2006
<#2/4/2006# and Feb 4, 2006.
You can also use the Between operator to filter
for a range of values. For example, Between
#2/2/2006# and #2/4/2006# is the same as
>#2/2/2006# and <#2/4/2006# .
<#2/2/2006# or Returns records took place before Feb 2, 2006
>#2/4/2006# or after Feb 4, 2006.
#2/2/2006# or Returns records that took place on either Feb 2,
#2/3/2006# 2006 or Feb 3, 2006.
In (#2/1/2006#, Returns records that took place on Feb 1, 2006,
#3/1/2006#, March 1, 2006, or April 1, 2006.
#4/1/2006#)
DatePart("m", Returns records that took place in December of
[SalesDate]) = 12 any year.
DatePart("q", Returns records that took place in the first
[SalesDate]) = 1 quarter of any year.
Date() Returns records that took place on the current
day. If today's date is 2/2/2006, you see records
where the Date field is set to Feb 2, 2006.
Date()-1 Returns records that took place the day before
the current day. If today's date is 2/2/2006, you
see records for Feb 1, 2006.
Date() + 1 Returns records that took place the day after
the current day. If today's date is 2/2/2006, you
see records for Feb 3, 2006.
15
< Date() Returns records that took place before today.
> Date() Returns records that will take place after today.
Is Null Returns records where the date is missing.
Is Not Null Returns records where the date is known.
DateDiff ("yyyy", This criterion applies to a Date/Time field, such
[BirthDate], Date()) > as BirthDate. Only records where the number
30 of years between a person's birthdate and
today's date is greater than 30 are included
in the query result.
DATA VALIDATION
Validation - Is the process of comparing the data entered with a set of predefined rules
or values to check if the data is acceptable. OR Validation is the name for the checks that
detect incorrect data, display an error message and request another input or just reject the
data.
Data Validation - is the checking of input data for errors (e.g., of the correct data type)
before processing.
Validation checks used in a database
Alphabetic check: ensures that only alphabetic characters are entered into the
field
Numeric checks: ensures that only numeric data is entered into the field
Consistency check: test Checks fields to ensure data in these fields corresponds,
e.g., If Title = "Mr.", then Gender = "M".
Check digits: this confirms the accuracy of a primary key value. It is usually
appended to or inserted into a primary check
Cross-system consistency checks: Compares data in different systems to ensure
it is consistent, e.g., the address for the customer with the same id is the same in
both systems.
Data type checks: Checks the data type of the input and give an error message if
the input data does not match with the chosen data type, e.g., In an input box
accepting numeric data, if the letter 'O' was typed instead of the number zero, an
error message would appear.
Range check: Checks that the data lie within a specified range of values, e.g., the
month of a person's date of birth should lie between 1 and 12.
Spelling and grammar check: Looks for spelling and grammatical errors.
Validation rules
This prevent bad data from being saved in your table. Basically, they look like
criteria in a query.
Validation rule Validation text
<>0 Enter a nonzero value.
>=0 Value must be zero or greater.
-or-
You must enter a positive number.
0 or >100 Value must be either 0 or greater than 100.
BETWEEN 0 AND 1 Enter a value with a percent sign. (For use with a
field that stores number values as percentages).
<#01/01/2007# Enter a date before 2007.
17
>=#01/01/2007# AND Date must occur in 2007.
<#01/01/2008#
<Date() Birth date cannot be in the future.
M Or F Enter M for male or F for female.
END
18