Modelling an object as a record

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Modelling an object as a record

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A Pets table has the fields Name, Species and Age. How many records do you need to store 3 pets?
A 3 records, one row for each pet
B 1 record that holds all 3 pets
2. Which one is a record in the Pets table?
A Biscuit, Dog, 4
B Name, Species, Age
3. When we model a pet as a record, what does each attribute of the pet become?
A A field
B A new table
4. Mia stores her cat in the Pets table as: Whiskers, Cat, 2. Which is the correct way to describe this?
A Three records with 1 value each
B One record with 3 field values
5. Every record in the Pets table must use...
A Different fields depending on the pet
B The same fields: Name, Species and Age

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Pets(Name, Species, Age) AINSERT INTO Pets VALUES ('Coco', 'Cat', 2);
2('Milo', 'Dog', 4) BTwo pets are crammed into one record. Each object needs its own record (row), so Milo and Coco should be two separate rows.
3Each pet is one object, so it is stored as one row (record) in the table COne record: one pet stored as a row, with one value for each field
4Every record in the Pets table uses the same fields, so each row has a Name, a Species and an Age DThe record has a value for Age but the table has no Age field. Every attribute of the pet needs its own field, so Age must be added to the table.
5Pets(Name, Species, Age) ('Milo', 'Dog', 4, 'Coco', 'Cat', 2) ESELECT Name, Species, Age FROM Pets;
6Pets(Name, Species) ('Milo', 'Dog', 4) FA Pets table where each attribute of a pet becomes a field: Name, Species and Age

Definitions

record

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
CREATE TABLE ____ (Name, Species, Age);
2.
______ INTO Pets VALUES ('Rex', 'Dog', 3);
3.
SELECT Name, _______, Age FROM Pets;
4.
SELECT Name, Age ____ Pets;
5.
INSERT INTO Pets VALUES ('Rex', 'Dog', 3); INSERT INTO Pets ______ ('Tom', 'Cat', 2);

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A CREATE TABLE Pets (
B Name TEXT,
C Species TEXT
D Age INTEGER
E );
Question 2
A INSERT INTO Pets
B (Name, Species, Age)
C VALUES
D ('Milo', 'Dog');
Question 3
A INSERT INTO Pets
B (Name, Species, Age)
C VALUES ('Luna', 5, 'Cat');
Question 4
A SELECT Name, Species, Age
B FROM Pet
C WHERE Species = 'Dog';
Question 5
A SELECT Name, Species
B FROM Pets
C WHERE Name = Milo;

Answer Key

Modelling an object as a record
Section A: Quick Questions
Q1
A — 3 records, one row for each pet
Q2
A — Biscuit, Dog, 4
Q3
A — A field
Q4
B — One record with 3 field values
Q5
B — The same fields: Name, Species and Age
Section B: Match the Pairs
Q1
Pets(Name, Species, Age) → A Pets table where each attribute of a pet becomes a field: Name, Species and Age
Q2
('Milo', 'Dog', 4) → One record: one pet stored as a row, with one value for each field
Q3
Each pet is one object, so it is stored as one row (record) in the table → INSERT INTO Pets VALUES ('Coco', 'Cat', 2);
Q4
Every record in the Pets table uses the same fields, so each row has a Name, a Species and an Age → SELECT Name, Species, Age FROM Pets;
Q5
Pets(Name, Species, Age) ('Milo', 'Dog', 4, 'Coco', 'Cat', 2) → Two pets are crammed into one record. Each object needs its own record (row), so Milo and Coco should be two separate rows.
Q6
Pets(Name, Species) ('Milo', 'Dog', 4) → The record has a value for Age but the table has no Age field. Every attribute of the pet needs its own field, so Age must be added to the table.
Section C: Definitions
Q1
record — One row in a table that stores one object. Each attribute of the object becomes a field, so one pet's Name, Species and Age fill one record, and every record uses the same fields.
Section D: Fill in the Blanks
Q1
CREATE TABLE Pets (Name, Species, Age);
Q2
INSERT INTO Pets VALUES ('Rex', 'Dog', 3);
Q3
SELECT Name, Species, Age FROM Pets;
Q4
SELECT Name, Age FROM Pets;
Q5
INSERT INTO Pets VALUES ('Rex', 'Dog', 3); INSERT INTO Pets VALUES ('Tom', 'Cat', 2);
Section E: Spot the Error
Q1
C — Each field in CREATE TABLE must be separated from the next by a comma. 'Species TEXT' needs a comma after it so Age can be the next field: ' Species TEXT,'.
Q2
D — A record must fill every field the table uses. This pet has a Name and Species but no Age value. It should be ('Milo', 'Dog', 3);
Q3
C — Values must be in the same order as the fields listed. Species comes before Age, so the values should be ('Luna', 'Cat', 5).
Q4
B — The table is called Pets, not Pet. The query must name the table that stores the pet records: FROM Pets.
Q5
C — Name is a text field, so the value Milo must be in quotes. Without quotes, SQL thinks Milo is a field name. It should be WHERE Name = 'Milo';