Course 9.1Lesson 1 of 3
A database table stores data about many things of one kind, such as the members of a club. Each row is a record and each column is a field. You learn these words, count records and fields, and define a single-table database from a list of what has to be stored.
Try the code and the simulations beside the lesson.
Think of the register your teacher keeps. There is one line for each student. Along the top are headings such as the first name, the surname and the date of birth. Every line has the same headings.
A database is a store of data kept in this kind of order, so that a computer can search it, sort it and add things up. The IGCSE course uses a single-table database: all the data sits in one table.
Look at this table from a sports club. Its name is Members.
MemberID FirstName Surname Town Age Paid
M01 Asha Patel Riverside 15 TRUE
M02 Tom Okafor Hillview 14 FALSE
M03 Lena Novak Riverside 16 TRUE
M04 Ravi Patel Lakeside 15 TRUE
M05 Mei Chen Hillview 13 FALSESurname. Field names are not records.So one record is all about one member, and one field is one detail about every member. Ask yourself: is the line of headings a record? No. It only names the fields.
Each box of the table holds one data item. The table holds data items.
An examination question often describes what a business wants to store. You then define the table. Let us do one together.
A vet wants to store, for each pet: its name, the kind of animal, the owner's phone number, the date of its last visit and whether it has had its injections.
PetName, Animal, OwnerPhone, LastVisit and Vaccinated.PetID. The next lesson calls this the primary key.OwnerPhone, not Owner Phone.Keep one item of data in each field. If a whole name is in one field, you cannot sort by surname. So a person's name is usually split into FirstName and Surname.
Python has a small database inside it, called sqlite3. The program builds the Members table in the computer's memory. It puts in all five records at once with executemany, then prints every record and counts the records and the fields.
FullAddress cannot be sorted or searched by town. Store the town in its own field.DateOfBirth, not Date of birth.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Members table, what does the third record hold?Town field of the Members table?FullName a poor choice for a list of students?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.