> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getcargo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL

> Connect to SQL databases for direct data access and manipulation

The SQL integration allows you to connect directly to SQL databases, enabling you to fetch data from tables or custom queries, and perform CRUD operations on your data.

## Authentication

SQL connections are configured through your warehouse connections (Snowflake, BigQuery, or Redshift). No additional authentication is required.

***

## SQL actions

### Search records

Retrieve multiple records from a table with filtering and sorting.

**Configuration**

| Field        | Description                                |
| ------------ | ------------------------------------------ |
| **Database** | The database name                          |
| **Schema**   | The schema name                            |
| **Table**    | The table name                             |
| **Filter**   | Define filter conditions                   |
| **Sort**     | Sort results                               |
| **Limit**    | Maximum records to retrieve (default: 100) |

### Insert record

Insert a new record into a table.

**Configuration**

| Field        | Description       |
| ------------ | ----------------- |
| **Database** | The database name |
| **Schema**   | The schema name   |
| **Table**    | The table name    |
| **Mappings** | Map column values |

### Update records

Update existing records in a table.

**Configuration**

| Field               | Description            |
| ------------------- | ---------------------- |
| **Database**        | The database name      |
| **Schema**          | The schema name        |
| **Table**           | The table name         |
| **Matching Value**  | Value to match against |
| **Matching column** | Column to match on     |
| **Mappings**        | Map columns to update  |

### Upsert records

Insert or update records based on a matching column.

**Configuration**

| Field               | Description            |
| ------------------- | ---------------------- |
| **Database**        | The database name      |
| **Schema**          | The schema name        |
| **Table**           | The table name         |
| **Matching Value**  | Value to match against |
| **Matching column** | Column to match on     |
| **Mappings**        | Map column values      |

### Delete records

Delete records from a table.

**Configuration**

| Field               | Description            |
| ------------------- | ---------------------- |
| **Database**        | The database name      |
| **Schema**          | The schema name        |
| **Table**           | The table name         |
| **Matching Value**  | Value to match against |
| **Matching column** | Column to match on     |

<Warning>
  Delete operations are permanent. Ensure you have proper filters configured.
</Warning>

***

## Data models

### Fetch table

Create data models directly from database tables.

**Configuration**

| Field        | Description                             |
| ------------ | --------------------------------------- |
| **Database** | The database name                       |
| **Schema**   | The schema name                         |
| **Table**    | The table name                          |
| **ID**       | Column containing unique record IDs     |
| **Title**    | Column containing record display titles |

### Fetch query

Create data models from custom SQL queries.

**Configuration**

| Field     | Description                             |
| --------- | --------------------------------------- |
| **SQL**   | The SQL query to execute                |
| **ID**    | Column containing unique record IDs     |
| **Title** | Column containing record display titles |

<Tip>
  Use fetch query for complex joins, aggregations, or filtered views of your
  data.
</Tip>

***

## Best practices

1. **Index your columns** - Ensure columns used in filters and joins are properly indexed
2. **Limit result sets** - Always use appropriate limits to avoid pulling excessive data
3. **Use views for complex queries** - Consider creating database views for frequently used complex queries
