3.7 Databases real Flashcards

1
Q

What is a flat file database

A

A flat file database stores a single table of data inside a single text file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are flat file databases recorded (3)

A

Flat file databases are often stored using a CSV (comma separated values) format
Each record appears on a separate line
Each field is separated by a comma

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Ease of flat file database?

A

This format is very easy to set up, however, it is hard to manage for anything but the simplest of data sets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Create a design for a flat file database that will store a contact book with names and mobile telephone numbers

For each field name, include the data type required
Create two lines of a CSV file with sample data

A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Primary key define

A

A primary key is a field that stores unique data for each record in a table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Label parts of flat file database

A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What can be used as a primary key? And its data type

A

An ID number can be introduced that is unique for each record

The data type will be an int or autonumber

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Flat file database issues (2)

A

Flat files mean that we often have to repeat data in each record.

This leads to inconsistencies in the data – these make it hard to search or sort the data
This also causes redundant data – so the database uses more memory or storage than it needs to, it may also take longer to search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Table-
Record-
Field-
Primary key-

A

Table – stores records and fields in an organised manner
Record – an individual collection of data for one person/object, a row in a table
Field – one item of data, a column in a table
Primary key – field containing unique values for all records

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Integer-
Real-
Date,time,datetime-
Char-
Varchar-
Text-

A

Integer (whole number)
Real, Float, Decimal (number with a decimal component)
Date, Time, Datetime (to store a dates and times)
Char (fixed length string up to 8,000 characters)
Varchar (variable length string up to 8,000 characters)
Text (variable length string up to 2 GB of data)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a relational database (3)

A

A relational database contains multiple tables
These tables will have links known as relationships
Each table is also known as a relation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why are relational databases good

A

Relational databases allow us to design tables that reduce inconsistencies and eliminate data redundancy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Primary key?

A

A primary key is a field, where every value stored in it will be unique

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Foreign key?

A

A foreign key is a field in a table that references the primary key of another table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

3 different relationships between tables

A

.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A ______________ makes use of ______________, also known as relations. These are linked by ______________.
Each table has a ______________ which is used to uniquely identify each record. A second table can refer to information in the first table by referring to its primary key. In this case it is referred to as a ______________.
Using relational databases and multiple tables allows the elimination of ______________ and reduces data inconsistency.
Data redundancy Relational database Relationships Foreign key Multiple tables Primary key

A

A relational database makes use of multiple tables, also known as relations. These are linked by relationships.
Each table has a primary key which is used to uniquely identify each record. A second table can refer to information in the first table by referring to its primary key. In this case it is referred to as a foreign key.
Using relational databases and multiple tables allows the elimination of data redundancy and reduces data inconsistency

17
Q

SQL?

A

SQL stands for Structured Query Language
It is a language which allows you to create, query, update and delete data to and from databases

18
Q

The SQL syntax for querying a database is:

A

The SQL syntax for querying a database is:
SELECT … (list the fields to be displayed)
FROM … (specify the table name)
WHERE … (list the search criteria)

19
Q

How to select all in sql

A

* — wildcards

SELECT *
FROM members
WHERE Surname LIKE ‘H*’

20
Q

SQL search between and starting letters

A

BETWEEN between an inclusive range
LIKE search for a pattern

SELECT *
FROM members
WHERE Surname LIKE ‘H*’

21
Q

Write SQL queries to find:
All the names and breeds of female dogs
All fields for dogs older than four (including those aged four)

A

All the names and breeds of female dogs
SELECT Name, Breed FROM Dogs WHERE Gender = ‘F’
All fields for dogs older than four (including those aged four)
SELECT * FROM Dogs WHERE Age >= 4

22
Q

How to sort data in ascending or descending order?

A

ORDER BY allows a query to sort data by ascending or descending order

For ascending order
SELECT * FROM members
ORDER BY Surname ASC

For descending order
SELECT * FROM members
ORDER BY Surname DESC

23
Q

How could you change all 3 year old pets to be 4?

A

UPDATE Dogs SET Age = 4 WHERE Age = 3

24
Q

To change the age of Milly from 5 to 6 use:

A

UPDATE Dogs SET Age = 6 WHERE DogID = 2

25
Q

The WHERE criteria allows?

A

The WHERE criteria allow more than one record to be deleted/added at a time

26
Q

How could you delete all Brown Labradors from the table ‘Dogs’?

A

DELETE FROM Dogs WHERE Breed = ‘Labrador’ AND Colour = ‘Brown’

27
Q

A query can be made which selects information from two tables
How do you think you select the owner and dog names for all four year old dogs using the keywords SELECT, FROM, WHERE and AND?
Tables ‘Owners’ + ‘Dogs’

A

SELECT Owners.Firstname, Owners.Lastname, Dogs.Breed

FROM Owners, Dogs

WHERE Owners.DogsID = Dogs.DogsID AND Dogs.Age = 4

28
Q

In pairs create SQL statements for the following:
Find all animal names in alphabetical order
Find all animal names and weights that are over 1000 kg
Find all animals, including all fields that are over 2 m
Change the Giraffe height from 5.5 to 5.6
Remove the record for the Sealion

A

All animal names in alphabetical order
SELECT Animal FROM AnimalsORDER BY Animal ASC

All animal names and weights that are over 1000 kg
SELECT Animal, Weight_kg FROM Animals WHERE Weight_kg > 1000

All animals, including all fields that are over 2 m
SELECT * FROM Animal WHERE Height_m > 2

Change the Giraffe height from 5.5 to 5.
6UPDATE Animals SET Height_m = 5.6 WHERE Animal = ‘Giraffe’

Remove the record for the Sealion
DELETE FROM Animals WHERE Animal = ‘Sealion’