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

# Query SQL Server

> Execute a read-only T-SQL query (SELECT or WITH; metadata through INFORMATION_SCHEMA views) against the SQL Server or Azure SQL destination of a pipeline. Connection credentials come from the pipeline's configured `credentialsSecret`, for every `authMethod`. Rows are capped with `OFFSET 0 ROWS FETCH NEXT <limit> ROWS ONLY` when the statement has a top-level ORDER BY and no TOP, left as written when it already has OFFSET, otherwise by wrapping it in `SELECT TOP (<limit>) * FROM (...) q` (for a WITH statement only the final SELECT is wrapped). When SQL Server rejects the wrapper (an unnamed or duplicate column name, FOR JSON / FOR XML) the query runs unwrapped with the same row cap. Write, exec and session keywords (INSERT, UPDATE, DELETE, INTO, EXEC, USE, OPENROWSET and others) are rejected anywhere in the statement, string literals included. Requires the `query:sqlserver` capability.



## OpenAPI

````yaml /openapi.yaml post /api/v1/query/sqlserver
openapi: 3.0.3
info:
  title: Datris API
  description: >
    REST API for the Datris AI Data Platform. Ingest, validate, transform,
    store, and retrieve data.


    For AI agent integration, use the [MCP
    Server](https://docs.datris.ai/mcp-server) instead.
  version: 1.53.0
  contact:
    name: Datris
    url: https://datris.ai
  license:
    name: Apache 2.0
servers:
  - url: http://localhost:8080
    description: Local development
security:
  - ApiKeyAuth: []
paths:
  /api/v1/query/sqlserver:
    post:
      tags:
        - Query
      summary: Query SQL Server
      description: >-
        Execute a read-only T-SQL query (SELECT or WITH; metadata through
        INFORMATION_SCHEMA views) against the SQL Server or Azure SQL
        destination of a pipeline. Connection credentials come from the
        pipeline's configured `credentialsSecret`, for every `authMethod`. Rows
        are capped with `OFFSET 0 ROWS FETCH NEXT <limit> ROWS ONLY` when the
        statement has a top-level ORDER BY and no TOP, left as written when it
        already has OFFSET, otherwise by wrapping it in `SELECT TOP (<limit>) *
        FROM (...) q` (for a WITH statement only the final SELECT is wrapped).
        When SQL Server rejects the wrapper (an unnamed or duplicate column
        name, FOR JSON / FOR XML) the query runs unwrapped with the same row
        cap. Write, exec and session keywords (INSERT, UPDATE, DELETE, INTO,
        EXEC, USE, OPENROWSET and others) are rejected anywhere in the
        statement, string literals included. Requires the `query:sqlserver`
        capability.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - pipeline
              properties:
                pipeline:
                  type: string
                  description: Name of a pipeline with a SQL Server destination
                sql:
                  type: string
                  description: >-
                    Read-only T-SQL to execute (SELECT or WITH, no semicolons or
                    comments). Omit to preview the pipeline's destination table.
                limit:
                  type: integer
                  default: 100
                  description: >-
                    Maximum rows to return. 0 means the default; there is no
                    upper bound. Pass -1 for unlimited (also disables the
                    30-second query timeout).
      responses:
        '200':
          description: Query results including the SQL that was executed
          content:
            application/json:
              schema:
                type: object
                properties:
                  pipeline:
                    type: string
                  sql:
                    type: string
                  results:
                    type: array
                    items:
                      type: object
                  count:
                    type: integer
        '400':
          description: >-
            User-actionable error (e.g. unknown pipeline, no SQL Server
            destination, a statement outside the SELECT/WITH allowlist or with a
            blocked keyword, an unknown table or column, a refused connection or
            login, whose message names the auth method and the fix)
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
        '500':
          description: Error
        '502':
          description: >-
            SQL Server failed for a reason outside the query (transport,
            server-side error)
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Optional API key for authentication (enabled via application.yaml)

````

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