Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views6 pages

Chapter 9 Databases Handout

The document provides an overview of databases, including definitions of key terms such as database, database software, tables, fields, records, and primary keys. It explains how to define a single-table database and introduces SQL commands for data manipulation, including selection, ordering, and aggregation functions. Additionally, it discusses data validation and verification methods to ensure data accuracy and integrity.

Uploaded by

maimumamujahith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Chapter 9 Databases Handout

The document provides an overview of databases, including definitions of key terms such as database, database software, tables, fields, records, and primary keys. It explains how to define a single-table database and introduces SQL commands for data manipulation, including selection, ordering, and aggregation functions. Additionally, it discusses data validation and verification methods to ensure data accuracy and integrity.

Uploaded by

maimumamujahith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Databases

Database: A database is a structured collection of data that allows people to extract information in a way
that meets their needs.

Database Software: A database software is an example of application software to store and manipulate
data. Ex: MS Access

Single-table Database: A single-table database contains only one table.

Table: A set of data about one type of object. Ex: Students, Products

Field: An individual piece of data. Ex: DOB

Record: A collection of fields that describe one item

• This table has 5 fields and 3 records.

Format of a database table

In tables, data is logically organized in a row-and-column format. Each row represents a unique record,
and each column represents a field in the record.

Data Types

Compiled by Reema Rifkhan


Primary Key

• It is a unique identifier for a record.

Characteristics:

o It must contain a unique value for each row of data.


o It cannot contain null values (Cannot be empty).
o Every row must have a primary key value.

Defining a single-table database

1. Define the fields


2. Select the appropriate data types
3. Define the primary key

Ex:

Sample Scenario
A database table, SHEEP, is used to keep a record of the sheep on a farm. Each sheep has a unique ear
tag, EARnnnn; n is a single digit. The farmer keeps a record of the date of birth, the gender and the
current weight of each sheep in kilograms.

1. Fields
o EarTag
o DOB
o Gender
o CurrentWeight

2. Data Types
o EarTag: Text (EAR0001)
o DOB: Date/time (22/07/2022)
o Gender: Character (F)
o CurrentWeight: Real (6.2)

3. Primary Key
EarTag

SQL

• It stands for Structured Query Language and is a standard language that can be used across most
databases.
• Most database software use SQL for
o Defining tables
o Change tables
o Adding data to a table
o Searching for data from tables (query)
o Performing calculations using data from tables

Compiled by Reema Rifkhan


SQL commands, syntax and output
1. SELECT…FROM

SQL Command Function Syntax Example Output


SELECT BookName Picking daisies
To select a field SELECT field FROM Books Night stars
from the table FROM table Dreaming of the sun
Cooking for fun
SELECT BookName, Genre Picking daisies Gardening
FROM Books Night stars Si-fi books
SELECT…FROM
Dreaming of the sun Si-fi books
To select a set of
SELECT field Cooking for fun Cookery
fields from the
FROM table SELECT Genre, BookName Gardening Picking daisies
table
FROM Books Si-fi books Night stars
Si-fi books Dreaming of the sun
Cookery Cooking for fun

2. SELECT…FROM…WHERE

Compiled by Reema Rifkhan


SQL Command Function Syntax Example Output
To select SELECT field SELECT FirstName, Posted Simon Yes
Specific data FROM table FROM Orders Mei Yes
(One WHERE condition WHERE Posted=Yes
condition)
SELECT OrderID, NumberItems, Posted 1B 2 Yes
SELECT field FROM Orders
To select
FROM table WHERE NumberItems>1 AND
SELECT…FROM…WHERE Specific data
WHERE condition1 Posted=Yes
(Multiple
logical operator SELECT FirstName, TotalCost, Posted Qirat 21.99 No
conditions)
condition2 FROM Orders Simon 3.99 Yes
WHERE TotalCost<5 OR Posted=No Jenny 59.65 No
Select fields SELECT field SELECT FirstName, LastName Simon Tong
not in FROM table FROM Orders Mei Liu
condition WHERE condition WHERE Posted=Yes

3. ORDER BY

SQL Command Function Syntax Example Output


SELECT field SELECT OrderID, NumberItems 1C 1
To order results 1B 2
FROM table FROM Orders
in ascending 1A 20
ORDER BY ORDER BY NumberItems ASC
order 1D 29
field ASC
ORDER BY SELECT OrderID, TotalCost, 1C 6.00 Yes
Posted 1B 3.99 Yes
To order data in SELECT field
FROM Orders
descending order FROM table
WHERE Posted=Yes
ORDER BY TotalCost DESC

4. SUM

SQL Command Function Syntax Example Output


SELECT SUM(field) SELECT SUM(NumberItems) 52
To add up total FROM table FROM Orders
SUM of the field SELECT SUM(field) SELECT SUM(TotalCost) 81.64
written after it FROM table FROM Orders
WHERE condition WHERE Posted=No

5. COUNT

SQL Command Function Syntax Example Output


To count the SELECT COUNT(field) SELECT COUNT(OrderID) 4
number of fields FROM table FROM Orders
COUNT To count how SELECT COUNT(field) SELECT COUNT(OrderID) 2
many records FROM table FROM Orders
meet the criteria WHERE condition WHERE NumberItems>10

Compiled by Reema Rifkhan


Data Validation & Verification

• Validation is the process of checking if data is reasonable and within set bounds.
• Verification is the checking that data entered is accurate and same as original.

Validation Checks

1. Range Check: A range check checks that the value of a number is between an upper value and a
lower value.

Database/MS Access Example

• If a field stores student marks for a particular subject, a range check can ensure percentage
marks are between 0 and 100 inclusive.

2. Length check: A length check checks that the number of characters is within a set limit.

Database/MS Access Example

• A Sri Lankan phone number should have not more or less than 10 digits.

3. Type Check: A type check checks that the data entered is of a given data type.

Database/MS Access Example

• By defining the data type in databases, type check is validated automatically. When a number or
text is added to the DOB field, MS Access will display an error message.

4. Presence Check: A presence check checks to ensure that some data has been entered and the value
has not been left blank.

Database/MS Access Example


• Email address in the database table cannot be empty. So “Required” attribute has to be changed
to Yes.

Compiled by Reema Rifkhan


5. Format Check: A format check checks that the characters entered conform to a pre-defined pattern.

Database/MS Access Example


• The PatientID of a patient in a hospital follows the 10-character pattern “HHHXXXXXX” where X
represents any 7 digits.

Verification Methods

• Double-entry Verification: For double entry the data is entered twice, sometimes by different
operators. The computer system compares both entries and if they are different outputs an
error message requesting that the data is entered again.

• A Visual check: It is a manual check completed by the user who is entering the data. When the
data entry is complete the data is displayed on the screen and the user is asked to confirm that
it is correct before continuing. The user either checks the data on the screen against a paper
document that is being used as an input form or, confirms whether it is correct from their own
knowledge.

Compiled by Reema Rifkhan

You might also like