A-level Computing/AQA/Paper 2/Fundamentals of databases/INSERT

PAPER 2 - ⇑ Fundamentals of databases ⇑

UPDATE INSERT DELETE
Category:Book:A-level Computing#AQA/Paper%202/Fundamentals%20of%20databases/INSERT

We might also want to add new things to our database, for example when we are adding new Criminal records or a new friendship link on Facebook. To add new records we use the INSERT command with values of the fields we want to insert:

INSERT INTO crooks
VALUES (1234,'Julie', 'female','12/12/1994','Little Maplestead',67)

Sometimes we might not want to insert all the fields, some of them might not be compulsory:

INSERT INTO crooks (ID, name, town) --specific fields to insert into
VALUES (999, 'Frederick', 'Shotley')
IDnamegenderDoBtownnumScars
1Geoffmale12/05/1982Hull0
2Janefemale05/08/1956York1
3Keithmale07/02/1999Snape6
4Olivermale22/08/1976Blaxhall2
5Kellyfemale11/11/1911East Ham10
6Mareafemale14/07/1940Wythenshawe6
1234Juliefemale12/12/1994Little Maplestead67
999FrederickShotley


Exercise: INSERT statements

Using the above data set, write an INSERT statement to create the following person:

name: Gerry
town: Keele
gender: male
numScars: 9
ID: 12
DoB: 13/12/1987

Answer:

Be careful, you must insert the fields in the order they are specified in the table

INSERT INTO crooks
VALUES (12, 'Gerry', 'male', '13/12/1987', 'Keele', 9)

Alternatively you could use the field headings, but this is a little cumbersome:

INSERT INTO crooks (name, town, gender, numScars, ID, DoB)
VALUES ('Gerry', 'Keele', 'male', 9, 12, '13/12/1987')

Using the above data set, write an INSERT statement to create the following person:

name: Kelly-Ann
gender: female
numScars: 1

Answer:

INSERT INTO crooks (name, gender, numScars)
VALUES ('Kelly-Ann', 'female', 1)
Category:Book:A-level Computing#AQA/Paper%202/Fundamentals%20of%20databases/INSERT%20
Category:Book:A-level Computing