You are on page 1of 4

Sorting a Database

Ascending = A Z or 0 - 100

Descending = Z A or 100 - 0

You can sort records into order based on the contents of the field. For example sort on the
surname in field in ascending order.

Key Fields: Primary Key


Imagine what would happen if Mrs Smith telephoned the school to ask the secretary to pass on
a message to her daughter Charlotte.

If there were nothing to uniquely identify the students' records, the secretary would have to
search for all of the 'Charlotte Smiths' in school and then say, 'sorry to keep you waiting Mrs
Smith, could you just tell me if your daughter is in S1, S2, S3, S4, S5 or S6? And if she is in S2,
which one of these five girls is she?'

How about a patient going to have an operation. 'Oh hello Mr Jones, I have 4 Mr Joneses
having an operation today, can you tell me if yours is to remove your tonsils, your arm, put your
leg in a cast or give you a hair transplant? I think that would be one very worried patient!

Therefore, it is important that every single record in a database has something to uniquely
identify it and this is called the 'Primary Key' or sometimes the 'Key Field'.

When you started school, you were given a 'student ID' or an 'office number' (primary key).
Key Fields: Foreign Key
A foreign key is used to link tables together and create a relationship. It is a field in one
table that is linked to the primary key in another table.

= Primary Key

= Foreign Key

Linked Tables
Within a database, tables are linked to prevent duplication of data within a row of a table.
Looking at a basic 2 table database storing information about criminals one criminal may be
arrested a number of times. The first table would store information about the criminal: name,
DOB, height, address etc. The second table would store information about the conviction: date,
arresting officer, crime, location etc. Taking it a step further you may have the following 4 table
structure:
Field
Lengths
When you created your smartphone database
you made the Field Size 20. Twenty is an
appropriate amount as it is unlikely you will
get a manufacturer or model name over 20
characters. This is done to save storage space. If you think about the police database it will be
massive so keeping the file size down.

Validation
Validation is done to ensure data entered is allowable
& sensible. You need to know about these different
types of validation.

Range check
Ensures the data entered in the field is between a
lower and upper limit.
e.g. Cost >0 AND <100
Time >1 min AND <5 mins

Restricted choice
Gives the user a list of options to choose from.
Prevents user typing errors.

Length check
Ensures the data entered in the field has a restricted number of characters;
e.g. PIN = 4 chars
Password >= 6 chars
Comments < 200 chars
Or a combination of the above

Presence check
Ensures the field is not left blank
Unique check Ensures the data entered in the field is different from any other record.

You might also like