How to Set Up a SQL Database for Beginners
Every SQL tutorial assumes your data is already "in a database." Nobody explains the step in between. This guide is that step. You'll get a data file, create your first real database on your own computer, load the file into it, and run your first query. It takes two desktop tools and zero server setup.
You do not need to bring your own data. Step 1 gives you a file to download, and every query in this guide runs against it.
If you are still weighing up which engine to put on your machine, the one-question version of that decision is in which SQL database should you install. Everyone else can start at step 1.
- Understand what you're actually building (60 seconds)
- Get a CSV file to work with
- Install DB Browser for SQLite
- Create a database file
- Import your CSV as a table
- Verify the import with one query
- Fix the two most common import problems
First: what are you actually building?
Say what you think a database is, in one sentence, before you read the next one. Whatever you pictured, the real answer for this guide is smaller and less intimidating than that.
A database sounds like a big scary server in a data center. For learning and portfolio projects, it isn't. With SQLite, a database is just one file on your computer — like mygames.db sitting in your Documents folder. Inside that file live one or more tables, and a table is just a grid of rows and columns, like a spreadsheet sheet.
So the whole job is: make the file, put your CSV inside it as a table, confirm nothing got lost. That's it.
Step 1 — Get a CSV file to work with
A CSV is a plain text file holding a table, one row per line, values separated by commas. It is what almost every "download this data" button gives you.
If you already have one, use it and skip ahead. If not, here is the file the rest of this guide uses. Right-click the link, choose Save link as, and put it somewhere you can find again.
- seattle-weather.csv — four years of daily Seattle weather. 1,461 rows, about 60 KB, no sign-up.
- Open it once in Excel or a text editor before you go further. Six columns: date, precipitation, temp_max, temp_min, wind, weather. Knowing what is in the file is what lets you tell later whether it loaded correctly.
Before you move on, say out loud how many rows you expect to end up in the database. You just read the number. Holding on to it is what makes step 5 mean something.
weather_raw.Step 2 — Install DB Browser for SQLite
Where you'll type everything in this guide is a free desktop app called DB Browser for SQLite. It gives SQLite a friendly point-and-click window plus a tab where you can type SQL.
- Go to sqlitebrowser.org/dl
- Download the installer for Windows or Mac and run it (all defaults are fine)
- Open the app — you'll see a mostly empty window with buttons like New Database and Open Database
Step 3 — Create your database file
- Click New Database (top-left)
- Pick a folder you can find again, name the file something like
portfolio.db, click Save - A "Create Table" dialog pops up — click Cancel. You don't need it; the CSV import in the next step builds the table for you.
That's a real database. It's empty, but it exists — one file, no server.
Step 4 — Import your CSV as a table
- In the menu: File → Import → Table from CSV file…
- Pick the CSV you downloaded in step 1
- In the import dialog:
- Table name: type
weather_raw. The_rawsuffix is an analyst habit: it marks this table as the untouched original. Any cleaning happens later, in a copy — never in the original. Naming rule: underscores, never hyphens or spaces. DB Browser auto-fills the name from the filename, soseattle-weather.csvarrives asseattle-weather— legal, but SQL reads the hyphens as subtraction, forcing you to quote the name in every query forever. Rename it before clicking OK. - Tick "Column names in first line" — otherwise your header row gets imported as a data row.
- Table name: type
- Click OK, then press Ctrl+S (Cmd+S on Mac) to save the database. DB Browser doesn't write changes to the file until you save.
Step 5 — Verify it with your first query
Before you run it, say what number you expect back. That expectation is the whole point of this step, because a query with nothing to compare it to cannot verify anything.
Click the Execute SQL tab. This is where you type SQL from now on. Type this and press the ▶ (play) button:
SELECT COUNT(*) FROM weather_raw;
It returns one number: how many rows are in your table. With the Seattle weather file it should be 1461. If you brought your own CSV, swap weather_raw for the table name you typed in step 4, and compare the number to the row count of the source file (open it in Excel and check the last row number, minus 1 for the header).
If they match, every row arrived. Then eyeball a few rows:
SELECT * FROM weather_raw LIMIT 10;
You should see dates in the first column and numbers in the next four, with words like drizzle and rain in the last. If the columns look right and the count matches — you're done. You have a working SQL database, and every SQL lesson you take from here on applies to your own data.
The two problems that bite everyone once
Both of these show up as a wrong answer rather than an error message, which is what makes them expensive. Guess what a total would look like if the database thought your prices were words instead of numbers.
1. Numbers imported as text
If a price column contains values like $4.99 or 1,299, the dollar sign and comma force it to import as TEXT — and SUM(price) returns garbage. The fix is to clean those values into a new numeric column (in a new table — never edit the _raw one). The SQL Kit's cleaning lessons cover exactly this.
2. Row count doesn't match
Off by exactly one? You probably forgot "column names in first line." Off by more? The CSV likely has quoting or delimiter problems (commas inside un-quoted text fields are the classic). Re-check the separator and quote settings in the import dialog.
Cheat sheet
| Step | Where | Action |
|---|---|---|
| Get data | Browser | Save a CSV to disk. seattle-weather.csv from vega-datasets if you have none |
| Create database | DB Browser | New Database → save a .db file → Cancel the table dialog |
| Import CSV | File menu | Import → Table from CSV → name it something_raw → tick "column names in first line" |
| Save | DB Browser | Ctrl+S — changes aren't in the file until you save |
| Verify | Execute SQL tab | SELECT COUNT(*) vs the CSV's row count, then LIMIT 10 to eyeball |
Same idea, bigger databases
On the job you'll meet MySQL (LOAD DATA INFILE) and Postgres (COPY). The tools change; the workflow you just learned doesn't: create → import → verify, and keep an untouched _raw copy.
And if the file itself is huge (millions of rows, gigabytes on disk), the same database still works, you just add a few habits: see How to Handle Large Datasets.
Database Setup for Analysts: Which One, Installed How, and What to Do First
Every analyst eventually needs a database of their own: somewhere to put a file that outgrew Excel, somewhere to practise, somewhere to keep a table that four spreadsheets currently disagree about.
What you do: pick by how fast you need to be querying, not by which name looks most professional on a CV. The SQL is nearly the same in all of them.
The short version. Start with SQLite. Add DuckDB when the files get big. Learn Postgres when a job asks for it.
The four options
| Option | Minutes to first query | Genuinely for | Cost |
|---|---|---|---|
| SQLite | 5 | Learning, personal projects, one-file datasets | Free, no install on most systems |
| DuckDB | 5 | Analytical queries over large CSV and Parquet | Free |
| PostgreSQL | 45 | Anything with users, or a real application | Free, but it is a server |
| Hosted free tier | 15 | Sharing with someone else, or a portfolio piece | Free tier, then paid |
SQLite
A database is a single file. No server, no account, no port. Python ships with it, so import sqlite3 works with nothing installed, and DB Browser for SQLite gives you a free graphical client if you would rather click than type.
The SQL is standard enough that everything you learn transfers. The things it does not have are the things a learner does not need yet: user accounts, concurrent writers, strict types.
DuckDB
Also a single file, also no server, and built for exactly the work analysts do: aggregate a lot of rows. It reads CSV and Parquet directly, so a large file can be queried before any import happens at all. If a file has beaten Excel, this is usually the shortest route to an answer, as in opening a large CSV.
PostgreSQL
A proper database server. Users, permissions, concurrency, extensions, and the closest free thing to what a company runs. It is the right choice if you are working towards analytics engineering, and it is more setup than a beginner needs on day one. Step by step in installing PostgreSQL.
A hosted free tier
Supabase, Neon, Railway and similar give you a Postgres instance in a browser. Useful when something else needs to reach the database, or when a portfolio project should have a live link. The cautions are the ordinary ones: free tiers pause or expire, and anything you upload leaves your machine, so nothing confidential goes there.
The five-minute SQLite start
python
>>> import sqlite3
>>> con = sqlite3.connect('analysis.db')
>>> con.execute("CREATE TABLE orders(order_id INT, region TEXT, amount INT)")
>>> con.execute("INSERT INTO orders VALUES (101,'North',120)")
>>> con.commit()
>>> con.execute("SELECT COUNT(*), SUM(amount) FROM orders").fetchall()
[(1, 120)]
commit() is the line beginners miss. Without it the insert is not saved, and the table looks empty next time you connect.
For a graphical route: install DB Browser for SQLite, File, New Database, then File, Import, Table from CSV file. That covers the whole loop without typing any SQL, which is a reasonable way to start.
The first five things to do once it runs
- Load one real file you actually care about. Practice data teaches syntax; your own data teaches analysis. The load step is in loading your first CSV.
- Count the rows and compare with the source. Every project starts here.
- Check the types. A column of numbers imported as text will sort 100 before 20 and sum to nothing.
- Write five questions in English before writing any SQL, then answer them one at a time.
- Save the queries in a file, with comments. A query you cannot find again was practice, not work.
Where the data goes
Three habits that save a bad afternoon later:
- Keep the database file and the raw source files in the same project folder, with the raw files never edited.
- Back up the database file by copying it. For SQLite and DuckDB that is the entire backup procedure.
- Do not put a database file in a syncing folder that could write to it from two machines. That is how a file gets corrupted.
How to apply this to your own work
- Install SQLite today and load one CSV you already use. Twenty minutes end to end.
- Add DuckDB the first time a file is too big for Excel, rather than the third time.
- Check the job adverts you are aiming at, and learn Postgres if they name it.
- Keep a queries file per project from the start, so nothing has to be rewritten from memory.
- Reconcile every load against a row count. It is the check that catches everything else.
The one habit to keep
Load your own data early. A database with practice data in it teaches syntax. A database with your own data in it starts answering questions somebody is asking you, which is the point at which the tool stops being homework.
What is the file you would load first, if you had a database this afternoon?
Which SQL Database Should You Install?
If you want to write SQL against your own data today, install a file-based engine: SQLite if you are learning, DuckDB if your data is already in CSV files. Both give you the whole SQL language. Neither has a server to start, a port to open, or a password to set.
Install a server such as PostgreSQL, MySQL or SQL Server when, and only when, more than one person or program needs to read and write the same data at the same time. That is the whole decision. The rest of this page shows you how to check which side of it you are on, so you can stop reading in two minutes and go write a query.
- The question that decides it
- What "a file" and "a server" actually mean
- SQLite, and why you may already have it
- DuckDB, if your data is CSV files
- When you genuinely do need a server
- Does the SQL you learn transfer?
- Cheat sheet
The question that decides it
Before the answer: think about the data you want to query right now. How many people, other than you, need to change it while you are looking at it?
Here is the fork, laid out.
The question. Does anything other than you need to read and write this data at the same time as you?
Answer one: no. It is your data, on your machine, and you are the only one touching it. If that is true, a database that is a single file does everything you need. You skip accounts, ports, services and permissions, because there is nobody to keep out and nothing to coordinate.
Answer two: yes. An application writes to it, or a team queries it, or it has to be reachable from another machine. If that is true, you need a server, because something has to sit in the middle and decide what happens when two callers arrive at once.
What decides between them is not the size of your data and not how serious the work is. It is only whether there is a second caller.
Why it matters is that installing a server first is where most people stall. Setting up PostgreSQL means a service, a superuser, a port, a client, and a connection string, and none of that teaches you any SQL. People spend an evening on it, hit an authentication error, and never get to the query. Starting with a file means your first SELECT runs in about fifteen minutes.
What "a file" and "a server" actually mean
These two words do a lot of work, so here is what each one is.
A file-based database is a library your program loads. The engine runs inside whatever you are already running, and the whole database, tables and rows and indexes, is one file on disk. You can copy that file to a USB stick, email it, or put it in a folder. Nothing is running when you are not using it.
A server database is a separate program that stays running. It starts when your computer starts and waits for connections. Your query does not read the data itself. It sends a request to that program, over a network connection, and the program reads the data and sends rows back.
Every difference people list between the two comes out of that one structural fact. Say why a server needs user accounts before reading on. It needs them because it accepts connections from callers it cannot see, so it has to be able to tell them apart. A file has no callers to tell apart. The file's permissions are the folder's permissions, and that is the end of it.
SQLite, and why you may already have it
SQLite is the file-based engine to reach for while you are learning. It is the most widely deployed database in the world, mostly because it is inside things rather than installed next to them: phones, browsers, desktop apps.
That includes Python. SQLite ships in Python's standard library, so if you have Python you already have a working SQL engine and did not install one. Two lines proves it:
import sqlite3
print(sqlite3.sqlite_version)
On the machine this guide was written on, that prints 3.38.4. Yours will differ, and any version will do.
For a window you can click around in rather than a script, DB Browser for SQLite is an open-source desktop app that opens the file, shows the tables, imports a CSV and runs queries. That combination, DB Browser plus one .db file, is the fastest route from nothing to a real query, and it is the one walked step by step in how to set up a SQL database.
DuckDB, if your data is CSV files
DuckDB is file-based like SQLite, and built for the shape of work analysts actually do: reading a lot of rows and summarizing them. The practical difference you will feel on day one is that it queries a CSV directly. There is no import step.
import duckdb
duckdb.sql("SELECT name, score FROM 'players.csv' WHERE score > 50")
That runs against the file as it sits on disk. No table to create, no columns to declare, no load. For anyone who has been doing this in a spreadsheet and has a folder of exports, that is the shortest path from a CSV to a GROUP BY that exists.
Picture your own downloads folder. If the answer you want lives across three of those CSVs, this is the engine that gets you there without building anything first.
When you genuinely do need a server
Four situations, and they are all the same situation.
- An application writes to the data while you read it. A web app, a scheduled job, anything with its own connection.
- Other people need to query it. Colleagues on their own machines, hitting the same data.
- It has to be reachable from somewhere else. Another server, a hosted tool, a dashboard product.
- The work requires a specific product. The job runs on SQL Server, so you practice on SQL Server. That is a real reason and it outranks everything above.
When one of those is true, PostgreSQL is the usual choice for analysis work and MySQL is the usual choice behind web applications. If your workplace runs Microsoft, SQL Server with SQL Server Management Studio is what you will meet. Match the tool to the job you are aiming at, rather than to a general ranking.
Does the SQL you learn transfer?
Mostly, yes, and this is the part worth being precise about because it decides whether starting small costs you anything.
What transfers unchanged: SELECT, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, subqueries, CTEs, window functions, CASE, and both comment syntaxes. That is the whole of analyst SQL and effectively all of what an interview will ask you.
What does not transfer: function names around the edges. String handling, date maths and type conversion are named differently in each product. SQLite uses INSTR and SUBSTR where SQL Server uses CHARINDEX and SUBSTRING. You look those up when you meet them, and looking them up is what practitioners do anyway.
So the cost of learning on a file and moving to a server later is a handful of function names. The cost of trying to install a server first is often the whole first evening.
Cheat sheet
| Your situation | Install | Why |
|---|---|---|
| Learning SQL, data is yours alone | SQLite, with DB Browser | One file, no setup between you and the first query |
| Already have Python | Nothing | SQLite is in the standard library |
| Data is a folder of CSVs | DuckDB | Queries the CSV directly, no import step |
| Building a portfolio project | SQLite or DuckDB | The database file goes in the repo, so anyone can rerun your work |
| An app or a team writes to the data | PostgreSQL or MySQL | Something has to arbitrate concurrent writers |
| Preparing for a job that names a product | That product | The job's tools outrank any general ranking |
The one habit to keep
Choose the smallest thing that answers your question, and add machinery only when something breaks. Most analysis work never outgrows a file, and the evening you did not spend on a server install is an evening of writing queries.
What is stopping you from running a query on your own data right now: the tool, or not knowing which question to ask it?
SQL for Analysts is 458 pages, every query read line by line in plain words, so the empty database has somewhere to go.
Download the free guide here →Always free. Help keep the lights on: tip the author on Gumroad if it helped.
The SQL Kit teaches SELECT, WHERE, JOIN, and GROUP BY with worked examples, practice, flash cards, and a mock exam — all in your browser, nothing to install.
Open the SQL Kit →Or get right into it and learn by writing queries: open SQL Drill, thirteen queries that each add one thing to the last.