# How do I get my Apple Health data into a database?

Source: https://healthsql.app/apple-health-database · Updated 2026-11-30

Install HealthSQL on your iPhone and run its command on your Mac: it builds a SQLite database at `~/Library/Application Support/HealthSQL/health.db` from every Health record, and keeps it current from your iCloud Drive. The other route is Apple's Export All Health Data, an XML file you convert yourself, again each time you want fresh data.

HealthSQL is an iPhone app and a command-line tool that copy your whole Apple Health record into a local SQLite database on your computer, so AI agents can query it with SQL or MCP.

## The two routes

| | HealthSQL | Apple's export.xml and a converter |
|---|---|---|
| How you get the data | The iPhone app writes new records to iCloud Drive; `healthsql` reads them into SQLite | In the Health app, Export All Health Data, move the zip to your Mac, run a converter |
| Freshness | Current to the iPhone's last export, and every answer says when that was | As old as the last time you exported |
| Daily totals | Apple Health's own totals, as the Health app shows them | You compute them, and a plain sum counts overlapping devices twice |
| Effort after setup | None with the automatic purchase; open the app otherwise | The whole routine, each time |
| Cost | Free export when you open the app; $7.99 once for automatic | Free |

Apple documents the export in [Share your health data](https://support.apple.com/guide/iphone/share-your-health-data-iph5ede58c3d/ios): "You can export all of your health and fitness data from Health in XML format." For a one-time look at old history, that is enough. More on its trouble for AI use: [export.xml and AI](https://healthsql.app/blog/apple-health-export-xml-ai).

## What is in the database

Start from the views; they do the joins for you.

| View | What it holds |
|---|---|
| `daily` | START HERE for any question about a day or a trend. |
| `days` | Health's own total for each metric and day, for every metric (the list is below). |
| `nights` | One row for each night of sleep, from one source (the one with sleep stages; if two have stages, the longer). |
| `nights_by_source` | One row for each night and each source that recorded it. |
| `sleep` | One row for each sleep stage interval, from every source. |
| `workouts` | One row for each workout. |
| `samples` | One row for each raw measurement or logged event, from every source. |
| `rings` | One row for each day of Activity rings, with the goals. |

The views read 7 tables: one row per record, with its type, unit and source by id, and Health's daily totals beside them. Every column: [schema reference](https://healthsql.app/docs/schema).

## Example SQL

```sql
SELECT day, steps, active_kcal, resting_hr, hrv_ms, asleep_min FROM daily ORDER BY day DESC LIMIT 14
```

```sql
SELECT night, asleep_min, deep_min, rem_min, fell_asleep, woke, source_name FROM nights ORDER BY night DESC LIMIT 7
```

```sql
SELECT day, activity, minutes, meters, avg_hr, source_name FROM workouts ORDER BY start_ts DESC LIMIT 10
```

Run any of them with `healthsql query "..."`. The answer is JSON: the rows, whether they were cut at 2000, and `phone_synced`.

## Use any SQLite tool

`health.db` is a plain SQLite file. Open it read-only in `sqlite3`, Datasette, DB Browser for SQLite or a notebook:

```sh
sqlite3 -readonly "$HOME/Library/Application Support/HealthSQL/health.db" "SELECT count(*) FROM daily"
```

Other tools do not read the iPhone's new files, so run `healthsql sync` first when you want the latest data. The database is a copy: delete it and `healthsql` builds it again from the files in iCloud Drive.

## Daily totals, not sums

Your Watch, your iPhone and a ring each record the same steps, as separate samples. A `SUM` over raw samples adds all of them. The `daily` and `days` views hold the totals Apple Health itself computes for each day, which count each stretch of time once. Use them for any daily number, and the `samples` view for a value at a time of day or for one device's own numbers. [Why sums double count](https://healthsql.app/blog/apple-health-steps-double-counted).

## Questions

### Is there an Apple Health SQL or SQLite export built into iOS?

No. Apple's only full export is XML ([Apple](https://support.apple.com/guide/iphone/share-your-health-data-iph5ede58c3d/ios), as of November 2026). Getting SQL means converting that file, or using an app that writes the data out for you.

### Can I write my own tables into it?

Use a separate database for your own tables and attach `health.db` read-only. `healthsql` may rebuild `health.db` from the files, for example after an update that changes its tables.

### Which records are not in it?

Clinical records need a separate permission from Apple, and iOS asks about medications and vision prescriptions one item at a time, so the export leaves them out, along with ECG voltages, heartbeat series and audiograms. See the [export format](https://healthsql.app/docs/format).
