Importing a CSV file into a database table

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

Importing a CSV file into a database table

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. When you import a CSV file into a new database table, what does the first row usually become?
A The field names (headings)
B The first record of data
2. A CSV file has the first row: Name,Age,Year. Which fields will the new table have?
A Field1, Field2 and Field3
B Name, Age and Year
3. After importing a CSV file, what should you do with each field's data type?
A Ignore it, because every field is always correct
B Choose it and check it, such as text or number
4. A field called Score holds numbers like 12, 18 and 20. Which data type suits it best?
A Number
B Text
5. A field called Phone has values like 0412 345 678. Which data type is the better choice?
A Text
B Number

Match the Pairs

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

Left columnRight column
1name,age,score Amy,12,85 Aid,name,year_level 1,Sam,7
2score: Number BAge was left as Text, so it will sort like words (10 before 9) and cannot be used for number calculations or range rules.
3The first row of the CSV file becomes the field names of the new table CThe data type chosen for the score field so it can be used in calculations, sorting and range checks
4After importing, check each field's data type, such as a phone number that should be Text, not Number Dphone: Text
5Import CSV with no heading row, so the first record is used as the field names EThe first row of the file is used for field names, so if a real record is in row one, its data becomes the headings and is lost as a record. The file needs a heading row first.
6age: Text (imported without checking the types) FA small CSV file: the first row holds the field names (name, age, score) and the next row is a record

Definitions

Import CSV

Fill in the Blanks

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

1.
IMPORT ___ "pets.csv" INTO NEW TABLE
2.
Row 1: Name,Age,Pet Row 1 becomes the ___________
3.
Row 2: Milo,7,Dog Set Age data type: ______
4.
Step 3: _____ the data types after import
5.
Values in a CSV row are split by ______

Spot the Error

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

Question 1
A Import file: pets.csv
B Field PetName type: Number
C Check types after import
Question 2
A Name Age Year
B Mia,13,8
C Sam,12,7
Question 3
A Import scores.csv
B Field Name type: Text
C Field Score type: Text
D Check types after import
Question 4
A Open the database
B Import books.csv to new table
C Use first row as field names
D Skip checking the data types
Question 5
A Item,Price,Stock
B Pen,1.50,20
C Book,4.95,eight
D Ruler,2.00,15

Answer Key

Importing a CSV file into a database table
Section A: Quick Questions
Q1
A — The field names (headings)
Q2
B — Name, Age and Year
Q3
B — Choose it and check it, such as text or number
Q4
A — Number
Q5
A — Text
Section B: Match the Pairs
Q1
name,age,score Amy,12,85 → A small CSV file: the first row holds the field names (name, age, score) and the next row is a record
Q2
score: Number → The data type chosen for the score field so it can be used in calculations, sorting and range checks
Q3
The first row of the CSV file becomes the field names of the new table → id,name,year_level 1,Sam,7
Q4
After importing, check each field's data type, such as a phone number that should be Text, not Number → phone: Text
Q5
Import CSV with no heading row, so the first record is used as the field names → The first row of the file is used for field names, so if a real record is in row one, its data becomes the headings and is lost as a record. The file needs a heading row first.
Q6
age: Text (imported without checking the types) → Age was left as Text, so it will sort like words (10 before 9) and cannot be used for number calculations or range rules.
Section C: Definitions
Q1
Import CSV — Fills a new database table from a CSV file. The first row becomes the field names, and you choose a data type for each field, such as text or number, and check them after the import.
Section D: Fill in the Blanks
Q1
IMPORT CSV "pets.csv" INTO NEW TABLE
Q2
Row 1: Name,Age,Pet Row 1 becomes the field names
Q3
Row 2: Milo,7,Dog Set Age data type: Number
Q4
Step 3: Check the data types after import
Q5
Values in a CSV row are split by commas
Section E: Spot the Error
Q1
B — A pet's name is made of letters, so the field type should be Text, not Number.
Q2
A — In a CSV file the values on a row are separated by commas. The heading row should be Name,Age,Year.
Q3
C — Scores are numbers you may want to sort or add up, so the Score field should be type Number, not Text.
Q4
D — After an import you should check that each field has the right data type. Skipping the check can leave numbers stored as text.
Q5
C — The Stock field holds numbers. The word eight would make the import treat the field as Text. It should be 8.