Computer science · University
Relational data, SQL and safe queries
A relational table holds rows and columns with a defined schema. Keys identify rows or relationships, while constraints enforce some consistency rules.
Prerequisites
Relevant school subject foundations and careful reasoning.
Study notes
Relations
A relational table holds rows and columns with a defined schema. Keys identify rows or relationships, while constraints enforce some consistency rules.
Queries
SELECT retrieves values; WHERE filters rows. A result has no guaranteed order without an appropriate ORDER BY clause.
Joins
A join combines related records according to a condition. One-to-many relationships can create multiple result rows, so count assumptions must be checked.
Safety
Parameterized queries separate data from SQL syntax. Permissions, validation and transactions remain necessary for a complete application.
Worked examples
Which clause specifies result ordering in an ordinary SQL query?
Without explicit ordering, result order should not be assumed.
ORDER BY
A table contains 12 rows and a stated filter matches 5. How many rows does SELECT without grouping return for that filter?
The filter retains exactly the five matching rows.
5
Check your understanding
What is a primary key intended to do?
- Uniquely identify rows under its constraint
- Make every column secret
- Sort every query automatically
- Guarantee that all text is accurate
Why can joining a parent table to several matching child records repeat the parent values?
Why use parameterized SQL for user-supplied values?
- Remove all need for permissions
- Make every query return one row
- Keep values separate from executable SQL syntax
- Automatically correct every schema
Three parent rows each match two child rows under the stated join. How many joined rows result?
Answers and marking guidance
Answers and marking notes
- Uniquely identify rows under its constraint
Uniqueness and non-null key constraints identify records, not all semantic truth.
- Each matching parent-child combination appears in the join result. A one-to-many relation naturally produces multiple rows.
Credit join cardinality.
- Keep values separate from executable SQL syntax
Parameter binding reduces injection risk from data values.
- 6
3×2=6 combinations.
Further reading and review references
These are reference links, not copied exercises, institutional endorsement or proof of independent review.
AI-assisted preview; independent educational review required. Level labels describe prerequisites, not accreditation or official curriculum alignment.