AlgoViz
Databases
Databases · EasyLesson 3 of 14

What is SQL?

A database full of tidy tables is useless if you can't ask it questions. SQL (say it 'sequel' or spell it out, both are fine) is the language you use to do exactly that: get rows, add rows, change rows, delete rows. Its big, beautiful idea is that you say WHAT you want — 'give me every user in Pune' — and the database itself works out HOW to find them fast. You never write the search loop. You describe the result; the database delivers it.

You say what you want, not how to get it

In most programming, you write the steps: loop over the list, check each item, collect the matches. That's telling the computer HOW. SQL is different — it's declarative. You write 'SELECT name FROM users WHERE city = "Pune"' which reads almost like English: 'give me the name, from the users table, where the city is Pune.' You never wrote a loop. You didn't say whether to scan the table or use an index. You stated the goal, and the database decided the fastest way to reach it. That's the whole spirit of SQL: describe the destination, let the database pick the road.

The four things you do to data (CRUD)

Almost everything you ever do to stored data is one of four actions, and SQL has one verb for each: • SELECT — read rows ('show me the matching users'). • INSERT — add a new row ('add a user named Maya'). • UPDATE — change existing rows ('set Maya's city to Mumbai'). • DELETE — remove rows ('remove the cancelled orders'). Programmers call this quartet CRUD (Create, Read, Update, Delete). If you know these four, you can do the everyday work of any database. Everything fancier — joins, grouping, transactions — is built on top of them.

Reading a SELECT, piece by piece

Take 'SELECT name, city FROM users WHERE city = "Pune"'. Three parts: • SELECT name, city — WHICH columns you want back (just name and city, not every column). • FROM users — WHICH table to look in. • WHERE city = "Pune" — WHICH rows to keep (only those where city equals Pune). That's the skeleton of nearly every read you'll ever write: pick columns, pick a table, filter rows. You don't need to memorize syntax to take the lesson here — just see that a query is a sentence describing the rows you want, and the database returns exactly those.

Why one language for every database matters

SQL isn't tied to one product. The same 'SELECT … WHERE …' sentence works across many different relational databases — PostgreSQL, MySQL, SQLite, SQL Server, and more. They each store and search data with their own internal machinery, but they all SPEAK SQL. That's a huge deal: learn SQL once and you can talk to almost any relational database. It's like learning to read maps in general instead of memorizing one city — the skill transfers. (Each database adds a few extras of its own, but the core you're learning is shared by all of them.)

It's a tradeoff

Option👍 Pro👎 Con
Declarative SQL (say WHAT you want)Short, readable, and the database picks the fastest plan for you — using indexes you didn't have to know about. The same query stays correct as data grows.You give up fine control over HOW it runs. Usually that's a win, but a poorly-shaped query can be slow without you seeing why (a later 'query execution' lesson opens that box).
Hand-writing the fetch yourself in code (say HOW)Total control over every step of how data is read.Far more code, easy to get wrong, and you'd have to re-invent fast searching, filtering, and combining tables — exactly the work the database already does well.

Questions you might have

Is SQL a programming language like Python?

Not quite. Python is general-purpose — you build anything with it. SQL has one job: talking to relational databases. And it's declarative — you describe the result you want rather than writing step-by-step instructions. You'll often use SQL FROM inside a Python (or Java, or JavaScript) program: your code sends SQL to the database and gets rows back.

Do I have to memorize all the SQL syntax?

No — and these lessons won't drill syntax. The goal is to THINK relationally: see your data as tables, and know that you ask for rows by describing them (which columns, which table, which filter). The exact punctuation you can always look up; the mental model is the part that lasts.

What does 'declarative' really buy me?

It means the database is free to be clever. You wrote 'find users in Pune'; behind the scenes it might use an index to jump straight to them instead of scanning everything — and you get that speed for free, without changing your query. You stated the goal; it optimized the path.

How does my app actually send SQL to the database?

Your program opens a connection to the database (often over the network), sends the SQL text as a message, and reads back the rows it returns. Libraries in every language make this a couple of lines. The key picture: SQL is the message format between your app and the database.

Is SQL the same as a NoSQL database's language?

No. SQL is specifically the language of RELATIONAL (table-based) databases. NoSQL databases — document or key-value stores — have their own ways of asking for data, usually less standardized. SQL's superpower is that it's shared across all the relational ones.

🧠SQL is the shared language for talking to relational databases. It's declarative: you describe WHAT rows you want (which columns, which table, which filter) and the database figures out HOW to fetch them fast. The four everyday verbs are SELECT (read), INSERT (add), UPDATE (change), DELETE (remove) — learn to think in those and you can drive any relational database.
✅ Check yourself4 quick questions — prove the idea stuck.Start →

Best read after: The relational model