0% found this document useful (0 votes)
9 views13 pages

SME Database Notes

The document outlines the structure and components of a database, including tables, fields, records, and the use of relational databases with primary and foreign keys. It also discusses data types, validation methods, sorting, searching techniques, and outputs such as reports. The information is aimed at providing a comprehensive understanding of database organization and management.

Uploaded by

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

SME Database Notes

The document outlines the structure and components of a database, including tables, fields, records, and the use of relational databases with primary and foreign keys. It also discusses data types, validation methods, sorting, searching techniques, and outputs such as reports. The information is aimed at providing a comprehensive understanding of database organization and management.

Uploaded by

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

Database Structure

Database structure

What is the structure of a database?

 A database is an organised collection of data

 A database is made up of either one or multiple tables which are made up


of fields and records to organise how it stores data

 It allows easy storage, retrieval, and management of information

 A database is useful when working with large amounts of data

 A database can be stored on remote servers so multiple users can access it at the same time,
useful for online systems

Fields, records and tables

 A field is a single piece of data in a table (column)

car_id make model colour price

1 Peugeot 2008 Red 24950

2 Mazda MX5 Blue 17995

3 Citroen DS4 Black 21450

4 Ford Puma White 19500

 An example of a field in the cars table is 'make'

 A record is complete set of fields on a single entity in a table (row)

car_id make model colour price

1 Peugeot 2008 Red 24950

2 Mazda MX5 Blue 17995

3 Citroen DS4 Black 21450

4 Ford Puma White 19500

 An example of a record in the cars table is '2, Mazda, MX5, Blue, 17995'

 A table is a complete set of records about the same subject/topic in a database

car_id make model colour price

1 Peugeot 2008 Red 24950


2 Mazda MX5 Blue 17995

3 Citroen DS4 Black 21450

4 Ford Puma White 19500

Relational databases

 A relational database is one that organises data into multiple tables

 It uses keys to connect related data which:

o reduces data redundancy

o makes efficient use of storage

o is easier to maintain

Primary & foreign keys

 A primary key is a unique field that can be used to identify a record in a table

 order_id is the primary key for the orders table

 customer_id is the primary key for the customers table

 A foreign key is a field in a table that refers to the primary key in another table.
 A foreign key is used to link tables and create relationships

 In the orders table customer_id is a foreign key - it links an order back to the customer that
made the order in the customer table

Data Types & Validation


Data types
What is a data type?
 A data type is the type of data that can be held in a field and is defined when
designing a table in a database

 Examples of common datatypes are:

o Numerical/number - whole/decimal numbers

o Alphanumerical - contains letters & numbers

o Date/Time

o Boolean - true or false values

o Currency

 In the car table below, the following datatypes would be used:

o car_id: numerical

o make: alphanumerical

o model: alphanumerical

o colour: alphanumerical

o price: currency

cars

car_id make model colour price


1 Peugeot 2008 Red 24950
2 Mazda MX5 Blue 17995
3 Citroen DS4 Black 21450
4 Ford Puma White 19500
Validation
What is validation?
 Validation is used to check that an input from a user is acceptable and that it
matches the requirements of the database

 There are 5 main categories of validation which can be carried out


on fields and data types, these are:

o Length check

o Type check

o Range check

o Presence check

 There can be occasions where more than one type of validation will be used
on a field

 An example of this could be a password field which could have a length,


presence and type check on it
Length check
 Checks the length of an input

 An example is ensuring that a password is 8 or more characters in length

Type check
 Check the data type of a field

 An example is checking a user's age has been entered as an integer

Range check
 Ensures the data entered as a number falls within a particular range

 An example is checking a user's age has been entered and falls between the
digits of 0-100

Presence check
 Looks to see if any data has been entered in a field
 An example is checking that a user has entered a name when registering for a
website

Sorting & Searching


Sorting

What is sorting?

 Sorting is a crucial function in databases that helps organise and present data in a meaningful
way

Using a single criterion to sort data

 You can sort data based on a single criterion - such as by name, date, or numerical value

 For example, you might sort a list of customers in ascending order by their last names

 To sort the customer's table by LastName in either ascending or descending order:

o Open the table in 'Datasheet View'

o Click on the column header for the field to be sorted

o For example, a table of customers to be sorted by LastName, click on


the LastName column header

o Click on the "Sort Ascending" or "Sort Descending" button in the toolbar at the top of
the screen

Sorting a table of information using only one criterion

Using multiple criteria to sort data


 You can also sort data based on multiple criteria

 For instance, you might want to sort a list of customers first by LastName (ascending), and
within each LastName, by City (descending)

 To sort the customer's table first by City, and then by LastName within each city:

o Open the table in 'Datasheet View'

o Click on the 'Advanced' button in the Sort & Filter section above

o Select 'Advanced Filter/Sort'

o Add the first column to sort data by, by dragging in to the QBE grid and from the sort
row choose ascending or descending

o Repeat for second criteria

o Selecting 'Advanced' again and choose 'Apply Filter/Sort'

Sorting a table of information using more than one criterion

Ascending and descending order

 Ascending Order - Data is sorted from smallest to largest (e.g., from A to Z, or from 1 to 100)

 Descending Order - Data is sorted from largest to smallest (e.g., from Z to A, or from 100 to 1)

Searching

What is searching?
 Searching is the process of using keywords, phrases or criteria to find specific
information within a database

 Searching in databases is typically done using queries

 Queries can be based on a single criterion or multiple criteria

Using a single criterion to select subsets of data

 You can use a single criterion to select specific data

 For example, you might want to select all customers from a specific county

 E.g. to return all customers from Devon:

o Open the 'Query Design View'

o Add the table you want to query

o Drag the field you want to query to the QBE grid

o For instance, if you're looking for customers from a specific county, drag
the County field

o In the Criteria row under this field, type the value you're looking for (e.g., 'Devon')

Creating a search within a database using one criterion

Using multiple criteria to select subsets of data

 You can also use multiple criteria to select data


 For instance, you might want to select all customers from a specific city who have
also purchased in the last month

 E.g. to return all customers from London who purchased in the last 30 days:

o Follow the steps above to start a new query and add the City field with 'London' as the
criteria

o Drag another field you want to query to the QBE grid

o For example, if you're looking for customers who purchased in the last month, drag
the LastPurchaseDate field

o In the Criteria row under this field, type Date()-30

o Hit run

Using operators to perform searches

 AND - Returns true if both conditions are met

 OR - Returns true if at least one condition is met

 NOT - Returns true if the condition is not met

 LIKE - Returns true if the value matches a pattern (used with wildcards)

 >, <, =, >=, <=, <> - These are comparison operators, they return true if the comparison between
the values is correct

Using wildcards to perform searches

 Wildcards are used with the LIKE operator to search for patterns

 The most common wildcard characters are:

o % - Represents zero, one, or multiple characters

o _ - Represents a single character

o * - Represents all

 E.g. to return all customers whose names start with 'L':

o Start a new query and drag the field you want to query to the QBE grid

o For example, if you're looking for customers whose names start with 'L', drag
the LastName field

o In the Criteria row under this field, type L*

o Hit run
Searching a database using a wildcard function

Outputs
Database outputs
What is a database output?
 A database output is often done through reports

 Reports can be formatted and customised to display data in a user-


friendly manner

 Reports should display all the required data and labels in full

 For example, if you're creating a sales report, it should include all relevant fields,
like product name, quantity sold, and total sales

Using appropriate headers and footers


 Report header

o This appears at the beginning of the report

o This is typically where you would put the report title and other introductory
information

 Report footer
o This appears at the end of the report

o This is where you might put summary or conclusion information

 Page header

o Appears at the top of each page

o This might contain the page number and the date

 Page footer

o Appears at the bottom of each page

o This might also contain the page number and the date

Producing different output layouts


 You can control the display of data and labels in your report

 For example, you might choose a tabular format, where data is arranged in rows
and columns, or a columnar format, where each data field is listed vertically

Simple report layout with data in rows


Simple report layout with data shown in columns
Aligning data and labels
 Data and labels should be aligned appropriately
 For example, numeric data is often right-aligned, and decimal points should be
aligned for easy comparison

Controlling the display format of numeric data


 You can control the number of decimal places displayed, the use of a currency
symbol, and the display of percentages

 For example, a total sales field might be displayed with two decimal places and a
currency symbol

You might also like