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

# Get SQL Schema

> Describe a database's tables, fields, and link tables for composing SQL queries.

Returns the database schema (tables, their fields, and the link tables that connect them) using human-readable names. Use this to discover the exact table and field names to reference from [Run SQL](https://developers.zite.com/api/sql/run-sql.md).

> [!NOTE]
>
> Names in the response match the human-readable names used in your SQL queries and the Zite SDK.

## Query parameters

| Parameter | Type | Description |
| - | - | - |
| `tables` | string\[] | Optional whitelist of table names to include. Repeat the parameter for multiple tables (e.g. `?tables=Orders&tables=Customers`) or pass a single comma-separated string. Omit to return all tables. |
| `includeFields` | boolean | Whether to include field-level detail. Defaults to `true`. Set to `false` for a cheap overview of just table names. |

## Link tables

`linkTables` describes the junction tables that connect two tables for many-to-many relationships. Each entry exposes the source and target tables along with the columns to join on, so you can traverse linked records in SQL.


## OpenAPI

````yaml api/openapi.json GET /bases/{databaseId}/sql/schema
openapi: 3.0.1
info:
  title: Zite DB REST API
  description: >-
    A REST API for managing Zite databases, tables, fields, and records. Build
    database-driven applications with programmatic access to your structured
    data.


    ## What is REST API


    A **REST API** simplifies interaction with your database data, allowing for
    automation and integration. Following RESTful principles, it seamlessly
    connects to retrieve, create, and modify database data.


    ## Getting Started


    ### Authentication

    All API requests require authentication using your Zite API key in the
    Authorization header:

    ```

    Authorization: Bearer YOUR_API_KEY

    ```


    ### Base URL

    https://tables.zite.com/api/v1


    ### Rate Limits

    Requests are limited to 30 per second per database. Responses carry
    `RateLimit-*` headers, and a request over the limit returns `429 Too Many
    Requests` with a `Retry-After` header and the body `{ "statusCode": 429,
    "error": "Too Many Requests", "message": "..." }`.


    ### Error Handling

    The API returns standard HTTP status codes. Error bodies have the shape `{
    "error": { "code", "message" } }`, except `429` responses (see Rate Limits).
  version: 1.0.0
servers:
  - url: https://tables.zite.com/api/v1
    description: Zite DB API
security:
  - bearerAuth: []
tags:
  - name: Databases
    description: Operations for managing databases
  - name: Tables
    description: Operations for managing tables within databases
  - name: Fields
    description: Operations for managing fields within tables
  - name: Records
    description: Operations for managing records within tables
  - name: Webhooks
    description: >-
      Operations for managing webhook subscriptions to receive real-time
      notifications when database events occur
  - name: SQL
    description: Run read-only SQL queries against a database and inspect its SQL schema
paths:
  /bases/{databaseId}/sql/schema:
    get:
      tags:
        - SQL
      summary: Get SQL schema
      description: >-
        Returns the database schema (tables, fields, and link tables) using
        human-readable names, for composing SQL queries.
      operationId: getSqlSchema
      parameters:
        - name: databaseId
          in: path
          required: true
          schema:
            type: string
          description: The unique identifier of the database
        - name: tables
          in: query
          required: false
          schema:
            type: array
            items:
              type: string
          style: form
          explode: true
          description: >-
            Optional whitelist of table names to include. Repeat the parameter
            for multiple tables (or pass a single comma-separated string). Omit
            to return all tables.
        - name: includeFields
          in: query
          required: false
          schema:
            type: boolean
            default: true
          description: >-
            Whether to include field-level detail for each table. Set to false
            for a cheap overview of just table names.
      responses:
        '200':
          description: Database schema
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SqlSchemaResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    SqlSchemaResponse:
      type: object
      properties:
        tables:
          type: array
          items:
            $ref: '#/components/schemas/SqlSchemaTable'
          description: The tables in the database.
        linkTables:
          type: array
          items:
            $ref: '#/components/schemas/SqlSchemaLinkTable'
          description: >-
            The junction tables linking tables together for many-to-many
            relationships.
      required:
        - tables
        - linkTables
    SqlSchemaTable:
      type: object
      properties:
        name:
          type: string
          description: Human-readable table name.
        primaryFieldName:
          type: string
          description: The name of the table's primary field.
        fields:
          type: array
          items:
            $ref: '#/components/schemas/SqlSchemaField'
          description: The fields in the table. Omitted when `includeFields=false`.
      required:
        - name
    SqlSchemaLinkTable:
      type: object
      description: >-
        A junction table representing a many-to-many link between two tables.
        Join on it to traverse linked records in SQL.
      properties:
        name:
          type: string
          description: Name of the link (junction) table.
        joins:
          type: array
          minItems: 2
          maxItems: 2
          items:
            type: string
          description: >-
            The names of the two tables this link table connects, as
            `[sourceTable, targetTable]`. Join on `sourceTableIdColumn` and
            `targetTableIdColumn`.
        sourceTable:
          type: string
          description: Name of the source table.
        targetTable:
          type: string
          description: Name of the target table.
        sourceTableIdColumn:
          type: string
          description: Column on the link table referencing the source table's id.
        targetTableIdColumn:
          type: string
          description: Column on the link table referencing the target table's id.
      required:
        - name
        - joins
        - sourceTable
        - targetTable
        - sourceTableIdColumn
        - targetTableIdColumn
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Error code
            message:
              type: string
              description: Human-readable error message
          required:
            - code
            - message
      required:
        - error
    SqlSchemaField:
      type: object
      properties:
        name:
          type: string
          description: Human-readable field name.
        type:
          type: string
          description: The Zite field type (e.g. `single_line_text`, `number`).
        postgresType:
          type: string
          description: The underlying PostgreSQL column type.
        linksTo:
          type: string
          description: For linked-record fields, the name of the table this field links to.
        options:
          type: array
          description: For select fields, the available options as value/label pairs.
          items:
            type: object
            properties:
              value:
                type: string
              label:
                type: string
              color:
                type: string
            required:
              - value
              - label
      required:
        - name
        - type
        - postgresType
  responses:
    BadRequest:
      description: Invalid request data or validation failure
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            invalidRecordId:
              value:
                error:
                  code: INVALID_RECORD_ID
                  message: Record ID is not in valid UUID format
            validationError:
              value:
                error:
                  code: BAD_REQUEST
                  message: Invalid request data or validation failure
    Unauthorized:
      description: Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: UNAUTHORIZED
              message: Invalid or missing API key
    NotFound:
      description: Requested resource does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: NOT_FOUND
              message: Requested resource does not exist
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Enter your Zite API key. Format: Bearer <api_key>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.