# tables

Canonical URL: https://developers.iagenify.com/sdk/ref/connected-storage/run/tables/
Language: en

`storage.run({ action: "tables" })`

Every table in a relational database, with its columns, their types, and which one is the key.

Status: relational database · free · no row counts

```javascript
await storage.run({ action: "tables" });
// [
//   { name: "users", columns: [
//       { name: "id",    type: "INTEGER", primaryKey: true },
//       { name: "email", type: "TEXT" },
//       { name: "created_at", type: "TEXT" } ] }
// ]
```

## No row counts, deliberately {#counts}

> **A COUNT is charged by the row on some providers**
>
> Counting every table to show how big it is can cost more than the query you were about to run. If you need a count, ask for the one table you care about.

```javascript
await storage.run({ action: "execute", sql: "SELECT COUNT(*) AS n FROM users" });
```

## Internal tables are left out {#internal}

The provider's own bookkeeping tables are filtered, so what comes back is what you created. A table you made and cannot see means you are connected to a different database.

## Writing a statement from it {#use}

```javascript
const tables = await storage.run({ action: "tables" });

const users = tables.find((t) => t.name === "users");
const key = users.columns.find((c) => c.primaryKey)?.name ?? "rowid";
const cols = users.columns.map((c) => c.name).join(", ");

await storage.run({ action: "execute",
  sql: `SELECT ${cols} FROM users ORDER BY ${key} DESC LIMIT 20` });
```

Knowing the key matters beyond ordering: a table without one cannot be updated row by row with any confidence, since there is nothing that names a single row.

- [execute](/sdk/ref/connected-storage/run/execute): Exécuter une instruction.
- [overview](/sdk/ref/connected-storage/run/overview): Les tables plus une ligne d'exemple, en un appel.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
storage.run(action="tables")
# [
#   {"name": "users", "columns": [
#       {"name": "id",    "type": "INTEGER", "primaryKey": True},
#       {"name": "email", "type": "TEXT"},
#       {"name": "created_at", "type": "TEXT"}]}
# ]
```

```python
storage.run(action="execute", sql="SELECT COUNT(*) AS n FROM users")
```

```python
tables = storage.run(action="tables")

users = next(t for t in tables if t["name"] == "users")
key = next((c["name"] for c in users["columns"] if c.get("primaryKey")), "rowid")
cols = ", ".join(c["name"] for c in users["columns"])

storage.run(action="execute", sql=f"SELECT {cols} FROM users ORDER BY {key} DESC LIMIT 20")
```
