Relational database concepts
Computer Science · Databases
Question 1 of 10
0In a LIKE pattern, the % symbol matches:
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Relational database concepts explained
A relational database stores data in tables. Each table holds one kind of thing, such as students or courses, and each row in a table is one record. Keys link the tables together, so related data can be combined without copying it everywhere. A table is made of rows and columns. Each row is one record, such as one student, and each column is one field, such as name or date of birth.
A primary key is a field whose value is unique for each row, such as a student ID. A foreign key is a field in one table that holds the primary key of a row in another table. A row in an Enrolments table might store a StudentID as a foreign key, which says which student the enrolment belongs to, without repeating the student's name and address.
Relationships are described as one-to-one, one-to-many or many-to-many. One teacher can teach many classes, but each class has one teacher, which is a one-to-many relationship. Textbooks sometimes call tables entities and columns attributes, so check the terms your course uses.
A common mistake is to think a primary key can repeat. Every value must be unique, and it should never be left empty.
Worked example
An Enrolments table has these rows:
EnrolmentID StudentID CourseID
1 1 C1
2 1 C2
3 2 C1
Ali has StudentID 1, and Bea has StudentID 2.
- Count the rows where StudentID is 1: there are 2, so Ali has 2 enrolments.
- Count the rows where StudentID is 2: there is 1, so Bea has 1 enrolment.
- The table holds 3 enrolments in total, and each student's details are stored once, in a Students table.
What you will practise
100 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- A relational database stores data in:
- A primary key:
- A foreign key:
- SQL is used to:
- A schema describes:
- A row in a relational table represents:
- A column in a table represents:
- NULL in a column means:
…and 92 more.