10 Database and File Concepts
10 Database and File Concepts
10 Database and File Concepts
• A relational database stores the data in more than one linked table, within the file
• It is designed so that the same data isn’t stored many times
• Each table with in a relational database will have a key field.
• Most tables will have a primary key field which holds unique data and is the field used to
identify that record
• Some tables will have one or more foreign key fields
• A foreign key in one table will point to a primary key in another table
Many-to-Many Relationship
• A many-to-many relationship has to be broken down into several one-to-many
relationships using a third table, a “join table” where each record in the “join table”
would have the foreign key fields linked to the primary keys of the tables it is joining
together
Primary Key
• A primary key is a field in a table which is unique and enables you to identify every
record in that table
• It must not contain null values and must contain unique value for each row of data
• A table in a relational database must always have one and only one primary key
• It optimizes the storage of table records within the database and helps to provide
quicker research
Compound Key
• A compound key is a primary key that combines more than one foreign key to make a
unique value/primary key
• It consists of more than one field
Foreign Key
• A foreign key is a primary key field in one table that is linked to the primary key in
another table
• It is used to form a relationship between the two tables
• Referential integrity is usually implemented through the use of foreign keys
• There can be many foreign keys in a table and can contain duplicate values
10.5 Normalisation
• Normalisation is a method of organizing data tables which involves breaking down a flat-
file
• It attempts to avoid data loss
• It attempts to avoid data redundancy (duplication)
• It attempts to improved data base efficiency
• This technique is a multi-step process, where each step has a rule that improves the
efficiency of the database
• These rules are called Normal Forms such as 1NF, 2NF and 3NF.
Advantages of Normalisation
• Any change to one record which is needed an instantly be made to any related records
• The database doesn’t have redundant data making the file size smaller so less money
needs to be spent on storage
• There is no data duplication so there are fewer errors in the data
• There is no data duplication so there is less chance of storing incorrect copies of the data
• There is no data duplication making the file size smaller so less money needs to be spent
on storage
• Modifying a table is easier as there is less data to modify
Disadvantages of Normalisation
• A large number of tables requires ore relationships to be designed taking more time
• Making data atomic may not always be the best solution such as date of birth can be
separated into day, month and year but this may serve no purpose
• Data may be stored as odes rather than meaningful data making it difficult for humans
to interpret it
• With more tables, setting up queries can become more difficult, the complex the query
the longer it can take to run
• You can end up with more tables than an unnormalized database making it difficult to
keep track of data
• May require greater expertise which may need to come from outside and be paid for,
creating extra expense
Dynamic Query
• Dynamic parameter query is a query that prompts the user for input to search for
different values each time it is run
• The input is then used by the query as the value in an expression or criteria
• Every time the query is run a dialogue box would appear asking the user to type in the
value
• It is used when different values need to be searched each time or when the data has to
be entered by the user
Compare and contrast static parameter query with dynamic parameter query [5]
• Both search for the data that matches the search criteria
• Both return records containing the data
• Both can be used with complex queries
• A dynamic query can be used to search for different values each time it is run
• In a static query every time that the query is run it will search for the same values
• Dynamic query needs a value to be entered every time
• Static query has the criteria hard coded hence doesn’t need to be added each time
• Dynamic query would save the time of designing the query every time a different criteria
was used
• Dynamic query requires more technical knowledge of the user and hence is more
complicated to create
Simple Query
• Simple query is one that searches using a single criterion only
• Simple query is used only on one field
Complex Query
• A complex query is one that searches using more than one criterion
• It often uses Boolean operands
• It is made up of AND, OR or NOT operands or a mixture of these
• It is used on more than one field
Nested Query
• A nested query is a query within another query, often referred to as a subquery
• Nested queries help you to use the result of one query as an input parameter of another
• Innermost subquery is executed first, then next level, until the main query is reached
• It is used when data from one query needs to be used for a different type of query such
as producing a query to summarize data based upon the results from a simple or
complex query
Summary Query
• Summary queries are used to summarize the contents of a table
• Also called Group-By queries/aggregate queries and use aggregate functions
• Uses functions such SUM, AVERAGE, MIN, MAX, COUNT
• A crosstab query is a type of summary query which displays results in a similar format to
a pivot table in a spreadsheet
13
Program files
• Program files are saved with .exe file extension, they are often opened by clicking on a
program icon
• Comma separated values: These files have a .csv file extension, it takes data in the form
of tables and saves it in text format, separating data with commas
• Text: These files have a .txt file extension, a text file isn’t formatted and can be opened
in any word processor software
• Rich text format: These files have an .rtf file extension, this is a text file type that saves
some of the formatting within the text
Common generic image files include:
• Graphics interchange format (GIF): These files have a .gif file extension that stores still
or moving images, it is an efficient method of storing images using a smaller file size
where there are large areas of solid color, mostly used in webpages
• Joint photographic expert group (JPEG): These files have a .jpg or .jpeg file extension
which stores still images but not moving ones, it is an efficient method of storing images
using a smaller file size and is used in web pages
• Portable document format (PDF): These files have a .pdf extension. This is a document
which has been converted into an image format, it allows documents to be seen as
image so they can be read on most computers, the pages look kusti ke they would if they
were printed but can contain clickable links and buttons, form fields, video and audio. In
pdf format, you can protect a document to stop others from editing it
• Portable network graphics (PNG): these files have a .png file extension, it is a format
that compresses graphics files (image) without any loss of image quality, it is the most
used lossless image compression format on the internet
• Moving pictures experts group layer-4 (MPEG-4): these files have an .mp4 file
extension, its not a single file format, it’s a multimedia container which is used for
storing video files, still images, audio files, subtitles and so on. It is used to transfer video
files on the internet
• Moving pictures experts group layer-3 (MPEG-3): These files have an .mp3 file
extension, it’s a compressed file format used for storing audio files, it cant store still or
moving images. File sizes are relatively small but have high quality, which makes it
suitable for use on the internet.
• Cascading style sheet: These files have a .css file extension, this is a stylesheet which is
saved in a cascading stylesheet format and is attached to one or more webpages (usually
HTML) o define the age’s color, scheme, fonts and so on.
• Hypertext markup language (HTML): These files have an .html or .htm file extension.
This is a text-based language used to create makeup that a web browser will be able to
interpret to display information on a webpage
• Roshal archive (RAR): these files have .rar file extension, which can hold almost any file
type in a compressed format. Used to reduce the number of bytes needed to save a file,
either to save storage space or to reduce transmission time.
• Zip: These files have a .zip file extension which can hold almost any file type in a
compressed format, it is used to reduce the number of bytes needed to save a file,
either to save storage space or to reduce transmission time