Skip to content

[FEATURE] SQL Database DDL via fab CLI / Fabric REST API #1004 #240

Description

@goreavin

Use Case / Problem

Title

Enable T-SQL execution against Fabric SQL Database via the Fabric REST API and fab CLI

Problem Statement

Currently, there is no way to execute T-SQL statements (DDL or DML) against a Fabric SQL Database from the fab CLI or the Fabric REST API. The only supported methods are:

  1. Fabric Portal — SQL Query editor (manual, not automatable)
  2. sqlcmd (Go) — Requires database.windows.net token audience, which the fab CLI app registration (5814bfb4-2705-4994-b8d6-39aabeb5eaeb) does not have consent for
  3. pyodbc/JDBC from Spark notebooks — Fails with "Login failed for user" because the Fabric-issued Spark token doesn't have SQL Database permissions by default

This makes it impossible to automate SQL Database schema setup (CREATE TABLE, INSERT seed data) as part of a CI/CD deployment pipeline using fab CLI.

Current Workarounds (all inadequate)

Approach Issue
fab CLI table schema / table load Only works on Lakehouse tables, not SQL Database
Fabric REST API /sqldatabases/{id}/executeQueries Endpoint does not exist (404)
Spark notebook with spark.sql('CREATE TABLE sqldb.dbo.table') Cross-database DDL from Spark to SQL DB not supported
Spark notebook with py4j JDBC Token scope mismatch — database.windows.net token not obtainable via mssparkutils.credentials.getToken() in some configs
fab api with -A powerbi Power BI executeQueries only supports DAX, not T-SQL against SQL Databases
pyodbc from external CLI ODBC driver available but fab auth token is scoped to api.fabric.microsoft.com, not database.windows.net

Proposed Solution

Proposed Solution

Requested Enhancement

Option A (preferred): Add fab sql command

# Execute T-SQL against a SQL Database item
fab sql "workspace.Workspace/mydb.SQLDatabase" -q "CREATE TABLE dbo.my_table (id INT PRIMARY KEY, name VARCHAR(100))"

# Or from file
fab sql "workspace.Workspace/mydb.SQLDatabase" -i ./schema.sql

Alternatives Considered

Option B: Add REST API endpoint

POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/sqldatabases/{sqlDbId}/executeStatement
Content-Type: application/json
Authorization: Bearer {fabric_token}

{
    "statement": "CREATE TABLE dbo.my_table (id INT, name VARCHAR(100))"
}

Option C: Allow fab auth to acquire database.windows.net scoped tokens

fab auth token --audience database.windows.net
# Returns a token usable with sqlcmd -S server -G --access-token <token>

Impact

  • Blocks CI/CD automation for Fabric SQL Database deployments
  • Forces manual portal interaction for any schema changes
  • Inconsistent with Lakehouse (where fab table commands work) and Warehouse (where Spark cross-DB queries work)
  • User Data Functions that connect to SQL Databases require the staging table to exist — but there's no automated way to create it

Environment

  • fab CLI version: 1.0.0 (Python-based, fabric_cli.main)
  • Workspace type: Fabric F64 capacity
  • Item type: SQLDatabase (SqlDatabase / SqlDbNative)
  • SageMaker CodeEditor environment (Linux x86_64, no az CLI)

Related

  • Fabric User Data Functions can write to SQL Databases (confirmed) but the table must pre-exist
  • Lakehouse SQL analytics endpoint is read-only (by design, documented)
  • fab table schema works for Lakehouses but returns "unsupported" for SQL Databases

Impact Assessment

  • This would help me personally
  • This would help my team/organization
  • This would help the broader fabric-cli community
  • This aligns with Microsoft Fabric roadmap items

Implementation Attestation

  • I understand this feature should maintain backward compatibility with existing commands
  • I confirm this feature request does not introduce performance regressions for existing workflows
  • I acknowledge that new features must follow fabric-cli's established patterns and conventions

Implementation Notes

fab cli or rest api. Preferred CLI.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions