SQL (Structured Query Language) is the language relational databases use to define tables and query the rows inside them. A website can execute SQL from Python, but that quickly becomes a pile of table definitions, queries, and maintenance scripts. section 4.1
A relational design stores data in tables connected through identifiers. A band and a song can each have a primary key, while a column references the related record. Querying songs may therefore require another query for the matching band. section 4.1
Bands and songs
A SQL-based RiffMates implementation might create band and song tables, add a composer column through another SQL script, and return song rows from a query. Django’s ORM offers an alternative: define classes such as Musician, then let the ORM map those classes to database tables. section 4.1
Figure 4.1 Inter-table relationships between bands and songs
Use the relationship diagram to trace how band and song tables connect through identifiers. section 4.1
SQL remains important even when Django hides most queries behind models:
- Treat Django Models as proxies for database tables, not ordinary Python objects; object-oriented designs can produce inefficient SQL. section 4.10
- Consider database structure separately from Python class design. A single person table with a role can avoid repeating fields across student, teacher, and staff tables. section 4.10
- Watch query costs in many-to-many relationships, where retrieving one band and its musicians can trigger lookups across several tables. section 4.10
























