# Datasets

Define datasets and views in a project's Spicepod, then deploy them and query them with SQL.

A dataset is a table that Spice reads from a data source. A view is a SQL query over one or more datasets. You define both in the project's Spicepod.

## Add a dataset

1. In the project, go to **Build** > [**Code**](https://spice.ai/docs/cloud/portal/app-spicepod).
2. In the **Components** sidebar, select a ready-to-use dataset on the **Datasets** tab, or a source on the **Data Connectors** tab.
3. Click **Save** in the code toolbar, then click **Deploy**.

In `spicepod.yaml`, a dataset names its source in `from` and its table in `name`:

```yaml
datasets:
  - from: postgres:public.orders
    name: orders
    params:
      pg_host: my-database.example.com
      pg_db: mydb
      pg_user: reader
      pg_pass: ${secrets:PG_PASS}
```

To keep a local copy of a dataset for fast queries, add an `acceleration` block. See [Data Acceleration](https://spice.ai/docs/features/data-acceleration). For every source that Spice can read, see [Data Connectors](https://spice.ai/docs/building-blocks/data-connectors).

## Add a view

A view names a SQL query. Query it as you query a dataset:

```yaml
views:
  - name: recent_orders
    sql: SELECT * FROM orders WHERE created_at > now() - INTERVAL '1 day'
```

## Query a dataset

Open the [**Playground**](https://spice.ai/docs/cloud/portal/playground) and run SQL against the dataset or view, or send SQL to the [HTTP API](https://spice.ai/docs/cloud/api/sql-query/http-api).
