Counting the Cost of Learning an ORM Before SQL
An ORM (object-relational mapper) is a library that lets you work with database rows as if they were objects in your programming language. Many tutorials start with one. This page weighs the cost of learning an ORM first against learning plain SQL first, without pretending there is one right answer.
Two learning paths
Path A: ORM first. You write code like Book.objects.filter(author="Ann") in Django or Book.where(author: "Ann") in Rails. The ORM writes the SQL for you.
Path B: SQL first. You write SELECT * FROM books WHERE author = 'Ann'; yourself, using a database driver (the small library that sends SQL to the database), then pick up an ORM later.
What each path costs you up front
| Cost | ORM first | SQL first |
|---|---|---|
| Time to first working app | Usually shorter | A little longer |
| New ideas to learn at once | Framework, ORM and database together | Database and SQL, then the framework |
| Understanding errors | Errors may come from several layers | Errors usually point to your SQL |
What each path costs you later
| Later cost | ORM first | SQL first |
|---|---|---|
| Debugging slow pages | Harder if you cannot read the SQL the ORM sends | Easier, you recognise the queries |
| Writing a report the ORM cannot express | Need to learn SQL then, under pressure | Already comfortable |
| Moving to another framework | ORM skills do not transfer directly | SQL transfers to almost any stack |
A way to estimate for yourself
Ask three questions and note your answers:
- Do I need something working this week? If yes, the ORM path gets you there faster.
- Will I work with data for years? If yes, SQL is a skill that keeps paying back.
- Do I enjoy seeing how things work underneath? If yes, you will likely enjoy SQL first.
Two or three "years and underneath" answers suggest SQL first. A pressing deadline suggests ORM first, with SQL soon after.
A middle path many learners like
- Spend a few evenings learning SELECT, INSERT, UPDATE and DELETE on a tiny SQLite database.
- Then start with your framework's ORM.
- Turn on the ORM's query logging so you can see the SQL it produces. Read it. You will recognise most of it.
This costs only a little extra time at the start and removes most of the later costs in the table above.
Common beginner traps either way
- Not knowing what the ORM sends. A page that loops over items can quietly run one query per item. Seeing the SQL helps you notice.
- Writing SQL by gluing strings together. Whether you use an ORM or plain SQL, always pass values as parameters. Our placeholders how-to shows how.
The takeaway
Neither path is wrong. The cheapest overall route for most people is "a little SQL first, then the ORM, with the query log switched on". When you are ready for performance topics such as counting queries per page, the sister site databaseintegrate.com covers them for working developers.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.