Fundamentals of databases Flashcards

1
Q

Shown below is the design of a database used to store data about TV channels and their owners (e.g. BBC1 and BBC2 are both owned by the BBC. ITV1 and ITV2 are both owned by ITV).

Channel (OwnerID, ChannelID, ChannelNumber, Name)

Programme (ProgrammeID, Title, Genre, ChannelID)

Owner (OwnerID, Name, Country)

State the name of one relation from the design.

A

Channel

OR

Programme

OR

Owner (1)

(Refuse if any other detail (e.g. attributes) included.)

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

Shown below is the design of a database used to store data about TV channels and their owners (e.g. BBC1 and BBC2 are both owned by the BBC. ITV1 and ITV2 are both owned by ITV).

Channel (OwnerID, ChannelID, ChannelNumber, Name)

Programme (ProgrammeID, Title, Genre, ChannelID)

Owner (OwnerID, Name, Country)

State the name of one attribure from the design.

A
  • OwnerID
  • ChannelID
  • ChannelNumber
  • Name
  • ProgrammeID
  • Title
  • Genre
  • Country

(Allow in the format Channel.ChannelID but otherwise refuse if any other detail included.)

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

Shown below is the design of a database used to store data about TV channels and their owners (e.g. BBC1 and BBC2 are both owned by the BBC. ITV1 and ITV2 are both owned by ITV).

Channel (OwnerID, ChannelID, ChannelNumber, Name)

Programme (ProgrammeID, Title, Genre, ChannelID)

Owner (OwnerID, Name, Country)

State the name(s) of the most suitable attribute(s) for a primary key in the Channel relation.

A

ChannelID

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

Shown below is the design of a database used to store data about TV channels and their owners (e.g. BBC1 and BBC2 are both owned by the BBC. ITV1 and ITV2 are both owned by ITV).

Channel (OwnerID, ChannelID, ChannelNumber, Name)

Programme (ProgrammeID, Title, Genre, ChannelID)

Owner (OwnerID, Name, Country)

State the name of an attribute which is acting as a foreign key and the name of the relation in which it has been used as a foreign key.

A

Channel.OwnerID OR Programme.ChannelID (2)

1 mark for identification of foreign key

1 mark for correct identification of relation

(Longer, written answers are more likely than the shorter format used here and are perfectly acceptable.)

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

A letting agent uses a database to keep track of its landlords along with the properties and tenants. A tenancy is agreed when a tenant has a contract to stay at a particular property. Historic records of tenancies are also stored in the database.

The definition of four relations in the database are show below:

Landlord (LandlordID, FirstName, LastName, ContactNumber, Email)

Property (HouseNum, StreetName, Town, PostCode, PropertyType, LandlordID)

Tenant (FirstName, LastName, ContactNumber, Email)

Tenancy (TentancyID, TenantFirstName, TenantLastName, StartDate, Duration, MonthlyRent, SecurityBondAmt)

The Tenant relation uses a composite key. Explain what is meant by a ‘composite key’ and why it had been used in this case. (3 marks)

A

Two or more attributes/fields (1) used together to uniquely identify a record (1)

Used here because it is possible for two different tenants to have the same first name or same last name (1)

NB: It is still possible for two different tenants to have the same first AND last names, so this does not represent the most ideal solution.

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

A letting agent uses a database to keep track of its landlords along with the properties and tenants. A tenancy is agreed when a tenant has a contract to stay at a particular property. Historic records of tenancies are also stored in the database.

The definition of four relations in the database are show below:

Landlord (LandlordID, FirstName, LastName, ContactNumber, Email)

Property (HouseNum, StreetName, Town, PostCode, PropertyType, LandlordID)

Tenant (FirstName, LastName, ContactNumber, Email)

Tenancy (TentancyID, TenantFirstName, TenantLastName, StartDate, Duration, MonthlyRent, SecurityBondAmt)

It has been suggested that the database is not fully normalised and that a new relation, Postcode, could be introduced to solve the problem.

Explain what is meant by the term ‘normalised’. (2-5 marks)

A
  • The data is atomic.
  • No attribute depends on a partial element of a composite key.
  • No dependencies other than on the key field(s).
  • Every attribute is dependent on the key.
  • Every determinant is a candidate key.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A letting agent uses a database to keep track of its landlords along with the properties and tenants. A tenancy is agreed when a tenant has a contract to stay at a particular property. Historic records of tenancies are also stored in the database.

The definition of four relations in the database are show below:

Landlord (LandlordID, FirstName, LastName, ContactNumber, Email)

Property (HouseNum, StreetName, Town, PostCode, PropertyType, LandlordID)

Tenant (FirstName, LastName, ContactNumber, Email)

Tenancy (TentancyID, TenantFirstName, TenantLastName, StartDate, Duration, MonthlyRent, SecurityBondAmt)

It has been suggested that the database is not fully normalised and that a new relation, Postcode, could be introduced to solve the problem.

Describe the changes that would need t be made to the database in order to incorporate the new relation. User the same notation that has been used in the design above. (3 marks)

A

Create a new relation, Postcode:

Postcode(Postcode, StreetName, Town)

Edit relation Property:

Property(HouseNum, Postcode, PropertyType, LandlordID)

Purpose of Postcode relation is clear (can be inferred from the attributes used even if not exactly correct) (1)

Attributes of Postcode, including primary key, correct (1)

Attributes remaining in Property, including composite key, correct (1)

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

Shown below is the design of part of a database used to manage an online audiobook subscription in which customers can ‘purchase’ on free audiobook per month as long as their subscription is still valid. Each book, purchase and author is identified using a unique numeric code.

Customer (Email, FirstName, LastName, EndDate)

Purchase (PurchaseID, CustomerEmail, BookID, Date)

Audiobook (BookID, Title, AuthorID, Reader, Length)

Author (AuthorID, FistName, LastName)

The length of the Audiobook Alice in Wonderland has been incorrectly entered as 1 hour 59 minutes when it should say 2 hours 59 minutes.

Write the SQL commsnds that are required to record this change in the database.

A

UPDATE Audiobook (1)

SET Length = 2:59 (1)

WHERE Title = “Alice in Wonderland” (1)

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

Shown below is the design of part of a database used to manage an online audiobook subscription in which customers can ‘purchase’ on free audiobook per month as long as their subscription is still valid. Each book, purchase and author is identified using a unique numeric code.

Customer (Email, FirstName, LastName, EndDate)

Purchase (PurchaseID, CustomerEmail, BookID, Date)

Audiobook (BookID, Title, AuthorID, Reader, Length)

Author (AuthorID, FistName, LastName)

Write the SQL commsnds that are required to find the title and reader for all of the books by Terry Pratchett.

A

SELECT Title, Reader

FROM Audiobook

INNER JOIN Author ON Audiobook.AuthorID = Author.AuthorID

WHERE FirstName = “Terry”

AND LastName = “Pratchett”

Analysis (3)

Identifying the tables and attributes needed (1)

Identifying the foreign key relationship as part of the WHERE clause (1)

Identifying the correct condition (FirstName and LastName) (1)

SQL (2)

Correct SQL syntax in 2 or 3 of the four SQL clauses (SELECT, FROM, WHERE, AND) (1)

Fully correct SQL (1)

Refuse answers that include other tables.

Accept answers that use INNERJOIN or OUTERJOIN as correct.

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

Shown below is the design of part of a database used to manage an online audiobook subscription in which customers can ‘purchase’ on free audiobook per month as long as their subscription is still valid. Each book, purchase and author is identified using a unique numeric code.

Customer (Email, FirstName, LastName, EndDate)

Purchase (PurchaseID, CustomerEmail, BookID, Date)

Audiobook (BookID, Title, AuthorID, Reader, Length)

Author (AuthorID, FistName, LastName)

Write the SQL commsnds that are required to find the title and author’s full name for every book downloaded in Junt 2018, sorted in ascending order by the author’s last name. (7 marks)

A

SELECT Title, FirstName, LastName

FROM Purchase

INNER JOIN Audiobook Purchase.bookID = Audiobook.bookID

INNER JOIN Author ON Audiobook.AuthorID = Author.AuthorID

WHEREDate BETWEEN 1/6/18 AND 30/6/18

ORDER BY LastName

Analysis (4)

Identifying the tables and attributes needed (1)

Identifying one foreign key relationship as part of the WHERE clause (1)

Identifying the correct condition (Date in June 2018) (1)

Identifying need to sort the results by last name (1)

SQL (3)

Correct SQL syntax in 2 of the five SQL clauses (SELECT, FROM, WHERE, AND, ORDER BY) (1)

Correct SQL syntax in 3 or 4 of the five SQL clauses (SELECT, FROM, WHERE, AND, ORDER BY) (1)

Fully correct SQL (1)

Accept answers that include the Student table, even though this is not necessary.

Accept other forms of selecting a valid date, e.g. Date >= 1/4/18 AND Date <= 30/4/18, use of DATEPART, MONTH or LIKE, as long as they are valid.

Refuse overly simplistic attempts to identify the date, e.g. Date = “May 2018” Q1.

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

A data set has been classified as Big Data.

Describe the three characteristics that might classify a data set as Big Data. (3 marks)

A
  • Volume: data that is too big to fit on a single server (1)
  • Velocity: the speed at which data is generated (1)
  • Variety: the differences in the structure OR format/types of data (1)

NB: The 3Vs are excellent to aid recall but answer MUST go into more detail.

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

A data set has been classified as Big Data.

In order to help process the data effectively, a distributed computer architecutre is used. State the most suitable programming paradigm for handling BigData in a distributed system.

A

Functional programming

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

A data set has been classified as Big Data.

State two features support by functional programming that make it easier to process Big Data.

A
  • Data is immutable OR stateless OR one part of a program cannot change the data and therefore impact another part of the program.
  • High-order functions OR functions such as Map/Reduce/Fold/Filter can be easily parallelised (to run as part of a distributed system).
  • Order of execution is less important/not as strictly defined (due to the immutable nature of the data, which makes it easier to process the data in a distributed system).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

Complete tjhe following DDL statement to create the Booking relation, including the key field.

CREATE TABLE Booking (

A

CREATE TABLE Booking(

BookingID INT

ActName VARCHAR (60)

StageName VARCHAR (20)

Day VARCHAR(8)

StartTime TIME

PRIMARY KEY (BookingID)

FOREIGN KEY (ActName) REFERENCES Act(Name)

FOREIGN KEY (StageName) REFERENCES Stage(Name))

OR

BookingID INT PRIMARY KEY

ActName FOREIGN KEY REFERENCES Act(Name)

StageName FOREIGN KEY REFERENCES Stage(Name)

Defining BookingID with a valid data type and as primary key (1)

Defining ActName with a valid data type and as a foreign key, with correct reference (1)

Defining StageName with a valid data type and as a foreign key, with correct reference (1)

Two other valid fields with sensible data types and lengths (if included) (1)

All fields with sensible data types and lengths and no additional fields (1)

Valid data types for BookingID: INT, SMALLINT, MEDIUMINT, INTEGER, any text type

Valid data types for text fields: VARCHAR, CHAR, NCHAR, NVARCHAR, VARCHAR2, NVARCHAR2, TEXT, LONGTEXT, NTEXT, TINYTEXT, MEDIUMTEXT

Day: text field, but also allow DATE, DATETIME, DATETIME2, DATE/TIME, SMALLDATETIME

StartTime: TIME, DATETIME, DATETIME2, DATE/TIME, SMALLDATETIME

Text lengths not necessary but must be sensible if included.

NOTNULL not necessary but allow.

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

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

State the name of a pimary key use within the database

A
  • Name
  • BookingID
  • AgentID

(Accept answers in the form Act.Name)

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

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

State the name of a foreign key used within the database and name the relation in which it takes the role of a foreign key,

A
  • Booking.ActName
  • Booking.StageName
  • Act.Agent
17
Q

Our database is fully normalised. Explain what this means. ( 2-5 marks)

A

every non key attribute is dependant on the key, the whole key and nothing but the key

  • The data is atomic.
  • No attribute depends on a partial element of a composite key.
  • No dependencies other than on the key field(s).
  • Every attribute is dependent on the key.
  • Every determinant is a candidate key.
18
Q

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

A new stage, the ‘Trapezoid’ stage is to be added. This is to be a comedy stage and has a curfew of 11pm. Write the SQL commands that are required to record the new stage details in the database.

A

INSERT INTO Stage (1)

VALUES (“Trapezoid”, “Comedy”, 23:00) (1)

OR

INSERT INTO Stage(Name, StageType, Curfew) (1)

VALUES (“Trapezoid”, “Comedy”, 23:00) (1)

19
Q

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

In light of a recent health and safety review, all acts of type ‘first eater’ are to be cancelled. Write the SQL commands that are required to remove their details from the database.

A

DELETE FROM Act (1)

WHERE ActType = “fire eater” (1)

20
Q

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

The agent Paul Scott is threatening to cancel all bookings for his act. Write the SQL commands that are required to find the act name, act type and the day of their scheduled performance. Display the results grouped by day, with Friday first and Sunday last. (7 marks)

A

SELECT Name, ActType, Day

FROM Act

INNER JOIN Booking ON Booking.ActName = Act.Name

INNER JOIN Agent ON Act.Agent = Agent.AgentID

WHERE FirstName = “Paul”

AND LastName = “Scott”

ORDER BY Day

Analysis (4)

Identifying the tables and attributes needed (1)

Identifying the foreign key relationships as part of the WHERE clause (1)

Identifying the correct condition (FirstName and LastName) (1)

Identifying need to sort the results by Day (1)

SQL (3)

Correct SQL syntax in 2 of the five SQL clauses (SELECT, FROM, WHERE, AND, ORDER BY) (1)

Correct SQL syntax in 3 or 4 of the five SQL clauses (SELECT, FROM, WHERE, AND, ORDER BY) (1)

Fully correct SQL (1)

Refuse answers that include other tables.

21
Q

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

There are restrictions on which acts can appear on which kind of stage. For example the:

  • ‘Trapezoid’ stage type is ‘comedy’ and only allows acts that the type ‘stand up’ or ‘comedy play’
  • ‘Little Top’ stage type is ‘acoustic’ and only allows acts that have the type ‘folk’ or ‘classical’

The information about which types of act can perform on which type of stage would be very helpful to the festival organisers.

Explain how the database could be modified to represent which act types can perform on which stage type. (3 marks)

A

New relation: AllowedActs(StageType, ActType) // AllowedActs(AA_ID, StageType, ActType)

Identification of a new relation to store the information about what act types can be matched with stage types. (1)

Valid primary / composite key. (1)

No extra fields included (other than an optional primary key). (1)

(Allow any meaningful name for the relation. Allow responses that explain the new design rather than the table design.)

Alternative response given the wording of the question may be to add two fields to an existing table, e.g. Stage(Name, StageType, Curfew, ActType1, ActType2).

(Allow max. 1 mark for this response.)

22
Q

Shown below is the design of part of a database used to manage the acts and stages at a music festival. Acts include music, comedy and a range of other entertainment types and may perform multiple times across the fetstival. Different stages have different curfew times dependent onthe type of acts due to perform there and their location withing the festival. Because the festival runs over several days, each booking includes the dat of the week (Friday, Saturday or Sunday). The BookinID and AgentID are made up of unique numeric codes.

Act (Name, ActType, Requirements, SetLength, Agent)

Stage (Name, StageType, Curfew)

Booking (BookingID, ActName, StageName, Day, StartTime)

Agent (AgentID, FirstName, LastName, Mobile, Email)

If two members of the organising team attempt to edit a record at the same time then this could cause a problem for the integrity of the database. Explain how this problem could be prevented. (2 marks)

A

Add each edit/update to a queue (1) and process each one in order. (1)

(Allow any sensible mention of FIFO processing.)

23
Q

State what is meant by immutable data structures and explain why a programming paradigm that enforces the use of immutable data strucutres is preferable when processing Big Data. (3 marks)

A

Immutable means unchangeable. (1)

The data structure cannot be made larger/smaller OR the data itself cannot be changed/must be copied if it needs to be altered (1) which means that in a distributed/parallel architecture, each process is unaffected by other processes. (1)

24
Q

Below is a SQL statement that is intended to make a table to represent the Athlete relation. The statement contains some errors.

CREATE TABLE Athlete (

PRIMARY KEY AthleteID,

VARCHAR(50) Surname,

VARCHAR(30) Forename,

DATE DateOfBirth,

VARCHAR(6) Gender,

VARCHAR(30) TeamName

)

You may assume that all of the data types used are valid and the field lengths are appropriate.

State TWO errors that have been made. [3 marks]

A
  • There is no data type for the primary key/AthleteID // The primary key/AthleteID needs a data type (1)
  • The data type is specified before the fieldname // fieldname should precede the data type // PRIMARY KEY is specified before the fieldname; A. an example of a specific field and data type which are the wrong way around (1)
  • There is a semi-colon missing at the end (1)
25
Q

State TWO reasons why database designs are usually normalised. [2 marks]

A
  • Minimise data duplication // no unnecessary repeated data
  • Eliminate data inconsistency // improve consistency // avoid inconsistency problems;
    • Eliminate update anomalies
    • Eliminate insertion anomalies
    • Eliminate deletion anomalies
26
Q

What is the most common mistake when filling in a fact-model diagram?

A

Forgetting the label the relationships