INSERT INTO, UPDATE and DELETE, then storing data in text and CSV files: open, read, write, append and close.
What you will learn
- Work out the effect of INSERT, UPDATE and DELETE
- Choose the right SQL command for a job
- Choose read, write or append mode
- Process records read from a CSV file
INSERT, UPDATE and DELETE
INSERT INTO Film (FilmID, Title, Genre, Year, Minutes)
VALUES (8, 'Iron Harbour', 'Action', 2023, 112)
UPDATE Film
SET Minutes = Minutes + 5
WHERE Genre = 'Musical'
DELETE FROM Film
WHERE Year < 2005
- INSERT INTO adds one new record: one value for each field listed, in the same order, with text in quotes.
- UPDATE changes the fields named after SET, in every record that meets WHERE.
- DELETE FROM removes every record that meets WHERE.
Leave out WHERE and UPDATE changes every record, and DELETE empties the whole table.
Practise: INSERT, UPDATE and DELETE on Brainlag Code.
The rest of this lesson and its 18 practice questions are locked.
In this lesson
- INSERT, UPDATE and DELETE
- Text files and CSV files
- Try it: Before and after
18 practice questions, marked as you go; about 25 minutes in all.
Key terms
INSERT INTO, UPDATE, DELETE FROM, File, CSV
In this unit: Databases and SQL
Tables, records and fields, primary and foreign keys, why linked tables beat one big table, SQL queries over one or two tables, changing data with INSERT, UPDATE and DELETE, and reading and writing CSV files.
- Relational databases and records
- SQL queries
- Changing data and files
- Writing SQL