← VCE Spreadsheets, SQL & Visualisation

Importing a CSV file into a database table

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.

Understanding Importing a CSV file into a database table in VCE Spreadsheets, SQL & Visualisation

What it does: The first line (id,name,year_level) is the header row, so those three words become the field names. The row below is a record. A phone number starts with 0 and is not used in maths. Setting it to Text keeps the leading 0, so you check types after the import. Numbers stored as a number type can be added, averaged and sorted properly. Text would sort 100 before 20. Without that setting, the heading words are treated as a normal record, which can also cause the wrong data types. Importing a CSV file into a database creates a new table and fills it with the records from the file.

Common mistakes: A pet's name is made of letters, so the field type should be Text, not Number. In a CSV file the values on a row are separated by commas. The heading row should be Name,Age,Year.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 45–54) and word search (Modules 35–54).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
When you import a CSV file into a new database table, what does the first row usually become?
The first record of dataThe field names (headings)
Matches
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.
Applying
Meanings
Term
Import CSV
Meaning
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.
Practice
StudentID,Name,Year,Score
Testing
Gaps
IMPORT "pets.csv" INTO NEW TABLE
Check Answer
Spots
1Import file: pets.csv
2Field PetName type: Number

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Stag' badge — Forest Legend, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

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
The first row of the CSV holds the headings, so the database uses it as the field names. The rows below it become the records.
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 ✓
When the first row is set as headings, the database uses those words as the field names instead of making up generic ones.
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 ✓
The database may guess a type wrongly, so you choose a type for each field and check them after the import.
4. A field called Score holds numbers like 12, 18 and 20. Which data type suits it best?
A. Number ✓
B. Text
Numbers stored as a number type can be added, averaged and sorted properly. Text would sort 100 before 20.
5. A field called Phone has values like 0412 345 678. Which data type is the better choice?
A. Text ✓
B. Number
Phone numbers are not used for maths and can start with 0. A number type would drop the leading 0.

Match the Pairs

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
score: Number → The data type chosen for the score field so it can be used in calculations, sorting and range checks
The first row of the CSV file becomes the field names of the new table → id,name,year_level 1,Sam,7
After importing, check each field's data type, such as a phone number that should be Text, not Number → phone: Text
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.
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.

Key Term

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.

Fill in the Blanks

1. IMPORT CSV "pets.csv" INTO NEW TABLE
Hint: Type the file format name that the import command reads from.
2. Row 1: Name,Age,Pet Row 1 becomes the field names
Hint: Type what the first row of the file turns into in the new table (two words).
3. Row 2: Milo,7,Dog Set Age data type: Number
Hint: Type the data type used for numeric values such as an age.
4. Step 3: Check the data types after import
Hint: Type the action you do after importing to make sure each field has the right type.
5. Values in a CSV row are split by commas
Hint: Type the punctuation marks that separate each value in a CSV row (plural).

Spot the Error

Question 1
A Import file: pets.csv
B Field PetName type: Number
C Check types after import
Line B — A pet's name is made of letters, so the field type should be Text, not Number.
Question 2
A Name Age Year
B Mia,13,8
C Sam,12,7
Line A — In a CSV file the values on a row are separated by commas. The heading row should be Name,Age,Year.
Question 3
A Import scores.csv
B Field Name type: Text
C Field Score type: Text
D Check types after import
Line C — Scores are numbers you may want to sort or add up, so the Score field should be type Number, not Text.
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
Line D — After an import you should check that each field has the right data type. Skipping the check can leave numbers stored as text.
Question 5
A Item,Price,Stock
B Pen,1.50,20
C Book,4.95,eight
D Ruler,2.00,15
Line C — The Stock field holds numbers. The word eight would make the import treat the field as Text. It should be 8.

Student with a class code? Join your class →