sqldw-authoring-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Update Check — ONCE PER SESSION (mandatory) The first time this skill is used in a session, run the check-updates skill before proceeding.
  • GitHub Copilot CLI / VS Code: invoke the
    check-updates
    skill.
  • Claude Code / Cowork / Cursor / Windsurf / Codex: compare local vs remote package.json version.
  • Skip if the check was already performed earlier in this session.
CRITICAL NOTES
  1. To find the workspace details (including its ID) from workspace name: list all workspaces and, then, use JMESPath filtering
  2. To find the item details (including its ID) from workspace ID, item type, and item name: list all items of that type in that workspace and, then, use JMESPath filtering
更新检查 — 每会话一次(必填) 在会话中首次使用本技能时,请先运行 check-updates 技能,再继续操作。
  • GitHub Copilot CLI / VS Code:调用
    check-updates
    技能。
  • Claude Code / Cowork / Cursor / Windsurf / Codex:比较本地与远程package.json版本。
  • 若本会话中已执行过检查,可跳过此步骤。
重要说明
  1. 要通过工作区名称查找工作区详情(包括ID):列出所有工作区,然后使用JMESPath过滤
  2. 要通过工作区ID、项目类型和项目名称查找项目详情(包括ID):列出该工作区中对应类型的所有项目,然后使用JMESPath过滤

SQL Endpoint Authoring — CLI Skill

SQL端点编写 — CLI技能

Table of Contents

目录

TaskReferenceNotes
Finding Workspaces and Items in FabricCOMMON-CLI.md § Finding Workspaces and Items in FabricMandatoryREAD link first [needed for finding workspace id by its name or item id by its name, item type, and workspace id]
Fabric Topology & Key ConceptsCOMMON-CORE.md § Fabric Topology & Key Concepts
Environment URLsCOMMON-CORE.md § Environment URLs
Authentication & Token AcquisitionCOMMON-CORE.md § Authentication & Token AcquisitionWrong audience = 401; read before any auth issue
Core Control-Plane REST APIsCOMMON-CORE.md § Core Control-Plane REST APIsIncludes pagination, LRO polling, and rate-limiting patterns
OneLake Data AccessCOMMON-CORE.md § OneLake Data AccessRequires
storage.azure.com
token, not Fabric token
Definition EnvelopeITEM-DEFINITIONS-CORE.md § Definition EnvelopeDefinition payload structure
Per-Item-Type DefinitionsITEM-DEFINITIONS-CORE.md § Per-Item-Type DefinitionsSupport matrix, decoded content, part paths — REST specs, CLI recipes
Job ExecutionCOMMON-CORE.md § Job Execution
Capacity ManagementCOMMON-CORE.md § Capacity Management
Gotchas, Best Practices & Troubleshooting (Platform)COMMON-CORE.md § Gotchas, Best Practices & Troubleshooting
Tool Selection RationaleCOMMON-CLI.md § Tool Selection Rationale
Authentication RecipesCOMMON-CLI.md § Authentication Recipes
az login
flows and token acquisition
Fabric Control-Plane API via
az rest
COMMON-CLI.md § Fabric Control-Plane API via az restAlways pass
--resource
; includes pagination and LRO helpers
OneLake Data Access via
curl
COMMON-CLI.md § OneLake Data Access via curlUse
curl
not
az rest
(different token audience)
SQL / TDS Data-Plane AccessCOMMON-CLI.md § SQL / TDS Data-Plane Access
sqlcmd
(Go) connect, query, CSV export
Job Execution (CLI)COMMON-CLI.md § Job Execution
OneLake ShortcutsCOMMON-CLI.md § OneLake Shortcuts
Capacity Management (CLI)COMMON-CLI.md § Capacity Management
Composite RecipesCOMMON-CLI.md § Composite Recipes
Gotchas & Troubleshooting (CLI-Specific)COMMON-CLI.md § Gotchas & Troubleshooting (CLI-Specific)
az rest
audience, shell escaping, token expiry
Quick ReferenceCOMMON-CLI.md § Quick Reference
az rest
template + token audience/tool matrix
Item-Type Capability MatrixSQLDW-CONSUMPTION-CORE.md § Item-Type Capability MatrixShows read-only (SQLEP) vs read-write (DW)
Connection FundamentalsSQLDW-CONSUMPTION-CORE.md § Connection FundamentalsTDS, port 1433, Entra-only, no MARS
Supported T-SQL Surface Area (Consumption Focus)SQLDW-CONSUMPTION-CORE.md § Supported T-SQL Surface AreaRead before writing T-SQL — includes data types (no
nvarchar
/
datetime
/
money
)
Read-Side Objects You Can CreateSQLDW-CONSUMPTION-CORE.md § Read-Side Objects You Can CreateViews, TVFs, scalar UDFs, procedures
Temporary TablesSQLDW-CONSUMPTION-CORE.md § Temporary Tables
Cross-Database QueriesSQLDW-CONSUMPTION-CORE.md § Cross-Database Queries3-part naming, same workspace only
Security for ConsumptionSQLDW-CONSUMPTION-CORE.md § Security for ConsumptionGRANT/DENY, RLS, CLS, DDM
Monitoring and DiagnosticsSQLDW-CONSUMPTION-CORE.md § Monitoring and DiagnosticsIncludes query labels; DMVs (live) +
queryinsights.*
(30-day history)
Performance: Best Practices and TroubleshootingSQLDW-CONSUMPTION-CORE.md § Performance: Best Practices and TroubleshootingStatistics, caching, clustering, query tips
REST API: Refresh SQL Endpoint MetadataSQLDW-CONSUMPTION-CORE.md § REST API: Refresh SQL Endpoint MetadataForce metadata sync when SQLEP is stale after ETL
System Catalog Queries (Metadata Exploration)SQLDW-CONSUMPTION-CORE.md § System Catalog Queries
sys.tables
,
sys.columns
,
sys.views
,
sys.stats
Common Consumption PatternsSQLDW-CONSUMPTION-CORE.md § Common Consumption PatternsReporting views, cross-DB analytics, temp table staging
Gotchas and Troubleshooting (Consumption)SQLDW-CONSUMPTION-CORE.md § Gotchas and Troubleshooting Reference18 numbered issues with cause + resolution
Quick Reference: Consumption CapabilitiesSQLDW-CONSUMPTION-CORE.md § Quick Reference: Consumption Capabilities
Authoring Capability MatrixSQLDW-AUTHORING-CORE.md § Authoring Capability MatrixRead first — DW vs SQLEP authoring scope
Table DDL (DW Only)SQLDW-AUTHORING-CORE.md § Table DDL (DW Only)CREATE, CTAS, ALTER, sp_rename, DROP, constraints, schema evolution, IDENTITY
DML Operations (DW Only)SQLDW-AUTHORING-CORE.md § DML Operations (DW Only)INSERT...SELECT, UPDATE, DELETE, TRUNCATE, MERGE
Data Ingestion (DW Only)SQLDW-AUTHORING-CORE.md § Data Ingestion (DW Only)COPY INTO, OPENROWSET, method comparison
Transactions (DW Only)SQLDW-AUTHORING-CORE.md § Transactions (DW Only)Snapshot isolation only; write-write conflict rules
Stored Procedures (Authoring Patterns)SQLDW-AUTHORING-CORE.md § Stored Procedures (Authoring Patterns)ETL procs, upsert, CTAS swap, cursor replacement
Time Travel and Warehouse SnapshotsSQLDW-AUTHORING-CORE.md § Time Travel and Warehouse Snapshots (DW Only)FOR TIMESTAMP AS OF; 30-day retention; snapshots GA
Source Control and CI/CDSQLDW-AUTHORING-CORE.md § Source Control and CI/CD (DW Only — Preview)Git integration, SQL DB projects, deployment pipelines
Authoring Permission ModelSQLDW-AUTHORING-CORE.md § Authoring Permission ModelContributor minimum for DDL/DML; Admin for GRANT
Authoring Gotchas and TroubleshootingSQLDW-AUTHORING-CORE.md § Authoring Gotchas and Troubleshooting17-row issue/cause/resolution table
Common Authoring PatternsSQLDW-AUTHORING-CORE.md § Common Authoring PatternsIncremental load, SCD Type 1, SQLEP view layer
Quick Reference: Authoring Decision GuideSQLDW-AUTHORING-CORE.md § Quick Reference: Authoring Decision GuideScenario → recommended approach lookup
Core Authoring via CLIauthoring-cli-quickref.md § Core Authoring via CLITable DDL, DML, data ingestion
sqlcmd
one-liners
Advanced Authoring Patterns via CLIauthoring-cli-quickref.md § Advanced Authoring Patterns via CLITransactions, schema evolution, stored procedures, time travel
Bash Templatesauthoring-script-templates.md § Bash TemplatesCOPY INTO, ELT pipeline, upsert with retry, schema migration, time travel recovery, stored procedure
PowerShell Templatesauthoring-script-templates.md § PowerShell TemplatesCOPY INTO ingestion, incremental upsert with retry
Tool StackSKILL.md § Tool Stack
sqlcmd
(Go) +
az
CLI +
jq
; verify before first op
ConnectionSKILL.md § ConnectionFQDN discovery, reusable vars, PowerShell
Script Generationauthoring-cli-quickref.md § Script Generationsqlcmd output flags, piped input, parameterized queries
Agentic WorkflowsSKILL.md § Agentic WorkflowsStart here — discover schema before any write
Monitoring Authoring Operationsauthoring-cli-quickref.md § Monitoring Authoring OperationsActive DML/DDL, recent ETL, failed writes
Gotchas, Rules, TroubleshootingSKILL.md § Gotchas, Rules, TroubleshootingMUST DO / AVOID / PREFER checklists
Agent Integration Notesauthoring-cli-quickref.md § Agent Integration NotesPlatform-specific tips (Copilot CLI, Claude Code)

任务参考文档说明
在Fabric中查找工作区和项目COMMON-CLI.md § 在Fabric中查找工作区和项目必看请先阅读链接内容 [需要通过工作区名称查找工作区ID,或通过项目名称、项目类型和工作区ID查找项目ID]
Fabric拓扑与核心概念COMMON-CORE.md § Fabric拓扑与核心概念
环境URLCOMMON-CORE.md § 环境URL
认证与令牌获取COMMON-CORE.md § 认证与令牌获取受众错误会导致401;遇到任何认证问题前请先阅读
核心控制平面REST APICOMMON-CORE.md § 核心控制平面REST API包含分页、LRO轮询和速率限制模式
OneLake数据访问COMMON-CORE.md § OneLake数据访问需要
storage.azure.com
令牌,而非Fabric令牌
定义信封ITEM-DEFINITIONS-CORE.md § 定义信封定义负载结构
按项目类型分类的定义ITEM-DEFINITIONS-CORE.md § 按项目类型分类的定义支持矩阵、解码内容、部分路径 — REST规范CLI示例
作业执行COMMON-CORE.md § 作业执行
容量管理COMMON-CORE.md § 容量管理
注意事项、最佳实践与故障排查(平台层面)COMMON-CORE.md § 注意事项、最佳实践与故障排查
工具选择依据COMMON-CLI.md § 工具选择依据
认证示例COMMON-CLI.md § 认证示例
az login
流程和令牌获取
通过
az rest
调用Fabric控制平面API
COMMON-CLI.md § 通过az rest调用Fabric控制平面API务必传递
--resource
参数
;包含分页和LRO辅助工具
通过
curl
访问OneLake数据
COMMON-CLI.md § 通过curl访问OneLake数据使用
curl
而非
az rest
(令牌受众不同)
SQL / TDS数据平面访问COMMON-CLI.md § SQL / TDS数据平面访问
sqlcmd
(Go版本)连接、查询、CSV导出
作业执行(CLI)COMMON-CLI.md § 作业执行
OneLake快捷方式COMMON-CLI.md § OneLake快捷方式
容量管理(CLI)COMMON-CLI.md § 容量管理
复合示例COMMON-CLI.md § 复合示例
注意事项与故障排查(CLI专属)COMMON-CLI.md § 注意事项与故障排查(CLI专属)
az rest
受众、shell转义、令牌过期
快速参考COMMON-CLI.md § 快速参考
az rest
模板 + 令牌受众/工具矩阵
项目类型能力矩阵SQLDW-CONSUMPTION-CORE.md § 项目类型能力矩阵展示只读(SQLEP)与读写(DW)的区别
连接基础SQLDW-CONSUMPTION-CORE.md § 连接基础TDS、端口1433、仅支持Entra、不支持MARS
支持的T-SQL功能范围(以消费为重点)SQLDW-CONSUMPTION-CORE.md § 支持的T-SQL功能范围编写T-SQL前请阅读 — 包含数据类型(不支持
nvarchar
/
datetime
/
money
可创建的只读端对象SQLDW-CONSUMPTION-CORE.md § 可创建的只读端对象视图、TVF、标量UDF、存储过程
临时表SQLDW-CONSUMPTION-CORE.md § 临时表
跨数据库查询SQLDW-CONSUMPTION-CORE.md § 跨数据库查询三部分命名规则,仅支持同一工作区
消费端安全SQLDW-CONSUMPTION-CORE.md § 消费端安全GRANT/DENY、RLS、CLS、DDM
监控与诊断SQLDW-CONSUMPTION-CORE.md § 监控与诊断包含查询标签;DMVs(实时)+
queryinsights.*
(30天历史)
性能:最佳实践与故障排查SQLDW-CONSUMPTION-CORE.md § 性能:最佳实践与故障排查统计信息、缓存、聚类、查询提示
REST API:刷新SQL端点元数据SQLDW-CONSUMPTION-CORE.md § REST API:刷新SQL端点元数据ETL后SQLEP元数据过时,强制同步
系统目录查询(元数据探索)SQLDW-CONSUMPTION-CORE.md § 系统目录查询
sys.tables
sys.columns
sys.views
sys.stats
常见消费模式SQLDW-CONSUMPTION-CORE.md § 常见消费模式报表视图、跨数据库分析、临时表 staging
注意事项与故障排查(消费端)SQLDW-CONSUMPTION-CORE.md § 注意事项与故障排查参考18个带原因和解决方案的问题
快速参考:消费端能力SQLDW-CONSUMPTION-CORE.md § 快速参考:消费端能力
编写能力矩阵SQLDW-AUTHORING-CORE.md § 编写能力矩阵请先阅读 — DW与SQLEP的编写范围区别
表DDL(仅DW支持)SQLDW-AUTHORING-CORE.md § 表DDL(仅DW支持)CREATE、CTAS、ALTER、sp_rename、DROP、约束、架构演进、IDENTITY
DML操作(仅DW支持)SQLDW-AUTHORING-CORE.md § DML操作(仅DW支持)INSERT...SELECT、UPDATE、DELETE、TRUNCATE、MERGE
数据Ingestion(仅DW支持)SQLDW-AUTHORING-CORE.md § 数据Ingestion(仅DW支持)COPY INTO、OPENROWSET、方法对比
事务(仅DW支持)SQLDW-AUTHORING-CORE.md § 事务(仅DW支持)仅支持快照隔离;写写冲突规则
存储过程(编写模式)SQLDW-AUTHORING-CORE.md § 存储过程(编写模式)ETL存储过程、Upsert、CTAS切换、游标替代方案
时间回溯与仓库快照SQLDW-AUTHORING-CORE.md § 时间回溯与仓库快照(仅DW支持)FOR TIMESTAMP AS OF;30天保留期;快照已正式发布
源代码控制与CI/CDSQLDW-AUTHORING-CORE.md § 源代码控制与CI/CD(仅DW支持——预览版)Git集成、SQL DB项目、部署流水线
编写权限模型SQLDW-AUTHORING-CORE.md § 编写权限模型执行DDL/DML至少需要Contributor权限;执行GRANT需要Admin权限
编写注意事项与故障排查SQLDW-AUTHORING-CORE.md § 编写注意事项与故障排查包含17行问题/原因/解决方案的表格
常见编写模式SQLDW-AUTHORING-CORE.md § 常见编写模式增量加载、SCD Type 1、SQLEP视图层
快速参考:编写决策指南SQLDW-AUTHORING-CORE.md § 快速参考:编写决策指南场景→推荐方法查询表
通过CLI进行核心编写authoring-cli-quickref.md § 通过CLI进行核心编写表DDL、DML、数据Ingestion的
sqlcmd
单行命令
通过CLI进行高级编写模式authoring-cli-quickref.md § 通过CLI进行高级编写模式事务、架构演进、存储过程、时间回溯
Bash模板authoring-script-templates.md § Bash模板COPY INTO、ELT流水线、带重试的Upsert、架构迁移、时间回溯恢复、存储过程
PowerShell模板authoring-script-templates.md § PowerShell模板COPY INTO数据Ingestion、带重试的增量Upsert
工具栈SKILL.md § 工具栈
sqlcmd
(Go版本)+
az
CLI +
jq
;首次操作前请验证
连接SKILL.md § 连接FQDN发现、可重用变量、PowerShell
脚本生成authoring-cli-quickref.md § 脚本生成sqlcmd输出标志、管道输入、参数化查询
Agentic工作流SKILL.md § Agentic工作流从此处开始 — 执行任何写入操作前先发现架构
监控编写操作authoring-cli-quickref.md § 监控编写操作活跃的DML/DDL、近期ETL、失败的写入操作
注意事项、规则与故障排查SKILL.md § 注意事项、规则与故障排查必须做/避免/优先选择检查清单
Agent集成说明authoring-cli-quickref.md § Agent集成说明平台专属提示(Copilot CLI、Claude Code)

Tool Stack

工具栈

ToolRoleInstall
sqlcmd
(Go)
Primary: Execute DDL/DML T-SQL. Standalone binary, no ODBC, built-in Entra ID auth.
winget install sqlcmd
/
brew install sqlcmd
/
apt-get install sqlcmd
az
CLI
Auth (
az login
), token acquisition, Fabric REST for endpoint discovery, snapshot management.
Pre-installed in most dev environments
jq
Parse JSON from
az rest
Pre-installed or trivial
Agent check — verify before first operation:
bash
sqlcmd --version 2>/dev/null || echo "INSTALL: winget install sqlcmd OR brew install sqlcmd"
工具作用安装方式
sqlcmd
(Go版本)
核心工具:执行DDL/DML T-SQL。独立二进制文件,无需ODBC,内置Entra ID认证。
winget install sqlcmd
/
brew install sqlcmd
/
apt-get install sqlcmd
az
CLI
认证(
az login
)、令牌获取、Fabric REST端点发现、快照管理。
多数开发环境已预装
jq
解析
az rest
返回的JSON
已预装或易于安装
Agent检查 — 首次操作前请验证:
bash
sqlcmd --version 2>/dev/null || echo "INSTALL: winget install sqlcmd OR brew install sqlcmd"

Authoring Scope by Item Type

按项目类型划分的编写范围

CapabilityWarehouse (DW)Lakehouse/Mirrored DB SQLEP
Table DDL (CREATE/ALTER/DROP)
DML (INSERT/UPDATE/DELETE/MERGE)
COPY INTO, OPENROWSET (ingest)OPENROWSET read-only
Transactions
Time travel, snapshots
CREATE VIEW/FUNCTION/PROCEDURE
CREATE SCHEMA

能力数据仓库(DW)Lakehouse/镜像数据库SQLEP
表DDL(CREATE/ALTER/DROP)
DML(INSERT/UPDATE/DELETE/MERGE)
COPY INTO、OPENROWSET(数据Ingestion)OPENROWSET仅支持只读
事务
时间回溯、快照
CREATE VIEW/FUNCTION/PROCEDURE
CREATE SCHEMA

Connection

连接

Discover the SQL Endpoint FQDN

发现SQL端点FQDN

Per COMMON-CLI.md Discovering Connection Parameters via REST:
bash
WS_ID="<workspaceId>"
ITEM_ID="<warehouseOrLakehouseId>"
根据COMMON-CLI.md中通过REST发现连接参数的方法:
bash
WS_ID="<workspaceId>"
ITEM_ID="<warehouseOrLakehouseId>"

Warehouse

数据仓库

az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/warehouses/$ITEM_ID"
--query "properties.connectionString" --output tsv
az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/warehouses/$ITEM_ID"
--query "properties.connectionString" --output tsv

Lakehouse SQL endpoint

Lakehouse SQL端点

az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/lakehouses/$ITEM_ID"
--query "properties.sqlEndpointProperties.connectionString" --output tsv

Result: `<uniqueId>.datawarehouse.fabric.microsoft.com`
az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/lakehouses/$ITEM_ID"
--query "properties.sqlEndpointProperties.connectionString" --output tsv

结果:`<uniqueId>.datawarehouse.fabric.microsoft.com`

Connect with sqlcmd (Go)

使用sqlcmd(Go版本)连接

bash
undefined
bash
undefined

Non-interactive one-shot query

非交互式单次查询

sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>" -G
-Q "SELECT TOP 10 * FROM dbo.FactSales"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>" -G
-Q "SELECT TOP 10 * FROM dbo.FactSales"

Service principal (CI/CD)

服务主体(CI/CD场景)

SQLCMDPASSWORD="<clientSecret>"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>"
--authentication-method ActiveDirectoryServicePrincipal
-U "<appId>"
-Q "SELECT COUNT(*) FROM dbo.FactSales"
undefined
SQLCMDPASSWORD="<clientSecret>"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>"
--authentication-method ActiveDirectoryServicePrincipal
-U "<appId>"
-Q "SELECT COUNT(*) FROM dbo.FactSales"
undefined

Reusable Connection Variables

可重用连接变量

bash
undefined
bash
undefined

Set once at script top

在脚本顶部设置一次

FABRIC_SERVER="<endpoint>.datawarehouse.fabric.microsoft.com" FABRIC_DB="<DatabaseName>" SQLCMD="sqlcmd -S $FABRIC_SERVER -d $FABRIC_DB -G"
FABRIC_SERVER="<endpoint>.datawarehouse.fabric.microsoft.com" FABRIC_DB="<DatabaseName>" SQLCMD="sqlcmd -S $FABRIC_SERVER -d $FABRIC_DB -G"

Use throughout

在脚本中重复使用

$SQLCMD -Q "SELECT TOP 5 * FROM dbo.DimProduct" $SQLCMD -i myscript.sql
undefined
$SQLCMD -Q "SELECT TOP 5 * FROM dbo.DimProduct" $SQLCMD -i myscript.sql
undefined

PowerShell / Windows CMD

PowerShell / Windows CMD

powershell
$s = "<endpoint>.datawarehouse.fabric.microsoft.com"; $db = "<DatabaseName>"
sqlcmd -S $s -d $db -G -Q "SELECT TOP 10 * FROM dbo.FactSales"
powershell
$s = "<endpoint>.datawarehouse.fabric.microsoft.com"; $db = "<DatabaseName>"
sqlcmd -S $s -d $db -G -Q "SELECT TOP 10 * FROM dbo.FactSales"

CMD: use set S=... and %S% / %DB% instead of $variables

CMD:使用set S=...和%S% / %DB%替代$变量


---

---

Agentic Workflows

Agentic工作流

Schema Discovery Before Authoring

编写前的架构发现

Before any write operation, discover the target schema:
bash
undefined
执行任何写入操作前,请先发现目标架构:
bash
undefined

1. List tables

1. 列出表

$SQLCMD -Q "SELECT table_schema, table_name FROM information_schema.tables ORDER BY 1,2" -W
$SQLCMD -Q "SELECT table_schema, table_name FROM information_schema.tables ORDER BY 1,2" -W

2. Check columns

2. 查看列信息

$SQLCMD -Q "SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name='FactSales' ORDER BY ordinal_position" -W
$SQLCMD -Q "SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name='FactSales' ORDER BY ordinal_position" -W

3. Sample data

3. 查看样本数据

$SQLCMD -Q "SELECT TOP 5 * FROM dbo.FactSales" -W
$SQLCMD -Q "SELECT TOP 5 * FROM dbo.FactSales" -W

4. Check constraints

4. 查看约束

$SQLCMD -Q "SELECT constraint_name, constraint_type FROM information_schema.table_constraints WHERE table_name='FactSales'" -W
$SQLCMD -Q "SELECT constraint_name, constraint_type FROM information_schema.table_constraints WHERE table_name='FactSales'" -W

5. Row counts

5. 查看行数

$SQLCMD -Q "SELECT s.name AS [schema], t.name AS [table], SUM(p.rows) AS row_count FROM sys.tables t JOIN sys.schemas s ON t.schema_id=s.schema_id JOIN sys.partitions p ON t.object_id=p.object_id AND p.index_id IN (0,1) GROUP BY s.name, t.name ORDER BY row_count DESC" -W
$SQLCMD -Q "SELECT s.name AS [schema], t.name AS [table], SUM(p.rows) AS row_count FROM sys.tables t JOIN sys.schemas s ON t.schema_id=s.schema_id JOIN sys.partitions p ON t.object_id=p.object_id AND p.index_id IN (0,1) GROUP BY s.name, t.name ORDER BY row_count DESC" -W

6. Programmability objects

6. 查看可编程对象

$SQLCMD -Q "SELECT name, type_desc FROM sys.objects WHERE type IN ('V','FN','IF','P','TF') ORDER BY type_desc, name" -W
undefined
$SQLCMD -Q "SELECT name, type_desc FROM sys.objects WHERE type IN ('V','FN','IF','P','TF') ORDER BY type_desc, name" -W
undefined

Agentic Workflow

Agentic工作流步骤

  1. Discover → Run steps 1–4 to understand available tables/columns.
  2. Sample
    SELECT TOP 5
    on relevant tables.
  3. Formulate → Select pattern from SQLDW-AUTHORING-CORE.md (Table DDL through Common Authoring Patterns).
  4. Execute
    $SQLCMD -Q "..."
    or
    $SQLCMD -i file.sql
    for multi-statement.
  5. Verify → Query affected table (
    SELECT COUNT(*)
    ,
    SELECT TOP 5
    ).
  6. Optionally script → Generate reusable
    .sh
    or
    .ps1
    using references/authoring-script-templates.md.

  1. 发现 → 执行步骤1-4,了解可用的表/列。
  2. 采样 → 对相关表执行
    SELECT TOP 5
    查询。
  3. 制定方案 → 从SQLDW-AUTHORING-CORE.md中选择合适的模式(从表DDL到常见编写模式)。
  4. 执行 → 使用
    $SQLCMD -Q "..."
    $SQLCMD -i file.sql
    执行多语句操作。
  5. 验证 → 查询受影响的表(如
    SELECT COUNT(*)
    ,
    SELECT TOP 5
    )。
  6. 可选:生成脚本 → 使用references/authoring-script-templates.md生成可重用的
    .sh
    .ps1
    脚本。

Gotchas, Rules, Troubleshooting

注意事项、规则与故障排查

For full authoring gotchas: SQLDW-AUTHORING-CORE.md Authoring Gotchas and Troubleshooting. For CLI-specific issues: COMMON-CLI.md Gotchas & Troubleshooting (CLI-Specific).
完整的编写注意事项请查看:SQLDW-AUTHORING-CORE.md中的编写注意事项与故障排查。 CLI专属问题请查看:COMMON-CLI.md中的注意事项与故障排查(CLI专属)。

MUST DO

必须做

  • Verify workspace has capacity before creating warehouse — call
    GET /v1/workspaces/{id}
    and check
    capacityId
    .
  • Always
    -d <DatabaseName>
    — FQDN alone is insufficient.
  • Always
    -G
    or
    --authentication-method
    — SQL auth not supported on Fabric.
  • az login
    first
    ActiveDirectoryDefault
    uses az session. No session → cryptic failure.
  • SET NOCOUNT ON;
    in scripts — suppresses row-count messages that corrupt output.
  • Use
    -i file.sql
    for multi-statement batches (CREATE PROCEDURE, transactions with GO separators).
  • Label authoring queries with
    OPTION (LABEL = 'ETL_description')
    .
  • Use explicit
    CAST()
    in CTAS to control output types.
  • Keep transactions short — long transactions increase conflict window.
  • 创建仓库前验证工作区是否有容量 — 调用
    GET /v1/workspaces/{id}
    并检查
    capacityId
  • 务必指定
    -d <DatabaseName>
    — 仅FQDN不足以连接。
  • 务必使用
    -G
    --authentication-method
    — Fabric不支持SQL认证。
  • 先执行
    az login
    ActiveDirectoryDefault
    使用az会话。无会话会导致模糊的错误。
  • 脚本中添加
    SET NOCOUNT ON;
    — 抑制行数消息,避免破坏输出。
  • 多语句批处理使用
    -i file.sql
    (如CREATE PROCEDURE、带GO分隔符的事务)。
  • 为编写查询添加标签,使用
    OPTION (LABEL = 'ETL_description')
  • CTAS中使用显式
    CAST()
    — 控制输出类型。
  • 保持事务简短 — 长事务会增加冲突窗口。

AVOID

避免

  • ODBC sqlcmd (
    /opt/mssql-tools/bin/sqlcmd
    ) — requires ODBC driver. Use Go version.
  • Omitting
    -W
    in scripts — trailing spaces corrupt CSV.
  • Singleton
    INSERT ... VALUES
    at scale — creates tiny Parquet files. Use INSERT...SELECT, CTAS, or COPY INTO.
  • DROP TABLE IF EXISTS
    +
    CREATE TABLE
    to refresh — loses time-travel history. Use
    TRUNCATE TABLE
    +
    INSERT INTO
    .
  • MERGE in production — preview, table-level conflict detection. Use DELETE + INSERT.
  • ALTER COLUMN — not supported. Use CTAS workaround (Schema Evolution).
  • Variables in CTAS — not allowed. Wrap in dynamic SQL:
    EXEC sp_executesql N'CREATE TABLE ...'
    .
  • DML on Lakehouse/Mirrored DB SQLEP — read-only for table data. Only views/funcs/procs can be authored.
  • Concurrent UPDATE/DELETE on same table — snapshot isolation conflicts at table level. Serialize writes.
  • Hardcoded FQDNs — discover via REST API (Connection section).
  • MARS — not supported. Remove
    MultipleActiveResultSets
    from connection strings.
  • ODBC版sqlcmd
    /opt/mssql-tools/bin/sqlcmd
    )— 需要ODBC驱动。请使用Go版本。
  • 脚本中省略
    -W
    — 尾随空格会破坏CSV。
  • 大规模使用单条
    INSERT ... VALUES
    — 会创建极小的Parquet文件。请使用INSERT...SELECT、CTAS或COPY INTO。
  • 使用
    DROP TABLE IF EXISTS
    +
    CREATE TABLE
    刷新数据
    — 会丢失时间回溯历史。请使用
    TRUNCATE TABLE
    +
    INSERT INTO
  • 生产环境中使用MERGE — 预览功能,表级冲突检测。请使用DELETE + INSERT。
  • 使用ALTER COLUMN — 不支持。请使用CTAS替代方案(架构演进)。
  • CTAS中使用变量 — 不允许。请包装在动态SQL中:
    EXEC sp_executesql N'CREATE TABLE ...'
  • 对Lakehouse/镜像数据库SQLEP执行DML — 表数据为只读。仅可编写视图/函数/存储过程。
  • 对同一表并发执行UPDATE/DELETE — 快照隔离会导致表级冲突。请序列化写入操作。
  • 硬编码FQDN — 通过REST API发现(连接章节)。
  • 使用MARS — 不支持。从连接字符串中移除
    MultipleActiveResultSets

PREFER

优先选择

  • CTAS over
    CREATE TABLE
    +
    INSERT
    — parallel, single-operation.
  • INSERT ... SELECT
    over singleton INSERTs.
  • COPY INTO
    for external file ingestion — highest throughput.
  • DELETE + INSERT over MERGE for upserts in production.
  • TRUNCATE TABLE
    over
    DELETE FROM
    without WHERE — faster, preserves history.
  • -i file.sql
    over
    -Q "..."
    for anything beyond simple one-liners.
  • Piped here-doc for multi-statement batches without GO requirements.
  • CTAS + sp_rename for large-scale transforms instead of UPDATE.
  • sqlcmd (Go) -G
    over curl+token for SQL queries.
  • -Q
    (non-interactive exit) for agentic use.
  • -F vertical
    for exploration of wide tables.
  • Env vars (
    FABRIC_SERVER
    ,
    FABRIC_DB
    ) for script reuse.
  • 使用CTAS替代
    CREATE TABLE
    +
    INSERT
    — 并行执行,单步操作。
  • 使用
    INSERT ... SELECT
    替代单条INSERT
  • 使用
    COPY INTO
    进行外部文件Ingestion
    — 吞吐量最高。
  • 生产环境中使用DELETE + INSERT替代MERGE进行Upsert
  • 使用
    TRUNCATE TABLE
    替代无WHERE子句的
    DELETE FROM
    — 更快,保留历史。
  • 复杂操作使用
    -i file.sql
    替代
    -Q "..."
  • 无GO要求的多语句批处理使用管道here-doc
  • 大规模转换使用CTAS + sp_rename替代UPDATE
  • SQL查询使用
    sqlcmd (Go) -G
    替代curl+令牌
  • Agentic场景使用
    -Q
    (非交互式退出)。
  • 宽表探索使用
    -F vertical
  • 脚本重用使用环境变量
    FABRIC_SERVER
    ,
    FABRIC_DB
    )。

TROUBLESHOOTING

故障排查

SymptomFix
Error 24556/24706 snapshot conflictSerialize writes to same table; retry with backoff
COPY INTO auth errorGrant Storage Blob Data Reader on ADLS; or SAS in CREDENTIAL
COPY INTO from OneLake failsProvision workspace identity; check firewall rules
CTAS unexpected typesUse explicit
CAST()
in SELECT
Singleton INSERT poor perfRemediate: CTAS + drop + rename to consolidate Parquet
Proc CREATE fails with
-Q
Use
-i file.sql
(GO separators needed)
sp_rename on SQLEP failsOnly available on Warehouse, not Lakehouse/Mirrored DB
Deploy drops/recreates tableAvoid ALTER TABLE in DB project; apply manually
Login failed for user
Verify
-d
matches item name exactly (case-sensitive)
Cannot open server
/
Login timeout expired
Re-discover FQDN via REST API; check port 1433 / firewall
ActiveDirectoryDefault
failure
az login
expired —
az login --tenant <tenantId>
Garbled CSV /
(N rows affected)
in file
Add
-W -s"," -w 4000
; prepend
SET NOCOUNT ON;
sqlcmd
not found
Install Go version:
winget install sqlcmd
症状修复方案
错误24556/24706快照冲突序列化对同一表的写入;带退避重试
COPY INTO认证错误为ADLS授予Storage Blob Data Reader权限;或在CREDENTIAL中使用SAS
从OneLake执行COPY INTO失败配置工作区标识;检查防火墙规则
CTAS返回意外类型SELECT中使用显式
CAST()
单条INSERT性能差修复:CTAS + 删除 + 重命名以合并Parquet文件
使用
-Q
创建存储过程失败
使用
-i file.sql
(需要GO分隔符)
SQLEP上执行sp_rename失败仅数据仓库支持,Lakehouse/镜像数据库不支持
部署时删除/重建表DB项目中避免ALTER TABLE;手动应用变更
Login failed for user
验证
-d
指定的名称与项目名称完全匹配(区分大小写)
Cannot open server
/
Login timeout expired
通过REST API重新发现FQDN;检查端口1433/防火墙
ActiveDirectoryDefault
失败
az login
已过期 — 执行
az login --tenant <tenantId>
CSV乱码 / 文件中出现
(N rows affected)
添加
-W -s"," -w 4000
;开头添加
SET NOCOUNT ON;
sqlcmd
未找到
安装Go版本:
winget install sqlcmd