sqldw-authoring-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUpdate 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
skill.check-updates- 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
- To find the workspace details (including its ID) from workspace name: list all workspaces and, then, use JMESPath filtering
- 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版本。
- 若本会话中已执行过检查,可跳过此步骤。
重要说明
- 要通过工作区名称查找工作区详情(包括ID):列出所有工作区,然后使用JMESPath过滤
- 要通过工作区ID、项目类型和项目名称查找项目详情(包括ID):列出该工作区中对应类型的所有项目,然后使用JMESPath过滤
SQL Endpoint Authoring — CLI Skill
SQL端点编写 — CLI技能
Table of Contents
目录
| Task | Reference | Notes |
|---|---|---|
| Finding Workspaces and Items in Fabric | COMMON-CLI.md § Finding Workspaces and Items in Fabric | Mandatory — READ link first [needed for finding workspace id by its name or item id by its name, item type, and workspace id] |
| Fabric Topology & Key Concepts | COMMON-CORE.md § Fabric Topology & Key Concepts | |
| Environment URLs | COMMON-CORE.md § Environment URLs | |
| Authentication & Token Acquisition | COMMON-CORE.md § Authentication & Token Acquisition | Wrong audience = 401; read before any auth issue |
| Core Control-Plane REST APIs | COMMON-CORE.md § Core Control-Plane REST APIs | Includes pagination, LRO polling, and rate-limiting patterns |
| OneLake Data Access | COMMON-CORE.md § OneLake Data Access | Requires |
| Definition Envelope | ITEM-DEFINITIONS-CORE.md § Definition Envelope | Definition payload structure |
| Per-Item-Type Definitions | ITEM-DEFINITIONS-CORE.md § Per-Item-Type Definitions | Support matrix, decoded content, part paths — REST specs, CLI recipes |
| Job Execution | COMMON-CORE.md § Job Execution | |
| Capacity Management | COMMON-CORE.md § Capacity Management | |
| Gotchas, Best Practices & Troubleshooting (Platform) | COMMON-CORE.md § Gotchas, Best Practices & Troubleshooting | |
| Tool Selection Rationale | COMMON-CLI.md § Tool Selection Rationale | |
| Authentication Recipes | COMMON-CLI.md § Authentication Recipes | |
Fabric Control-Plane API via | COMMON-CLI.md § Fabric Control-Plane API via az rest | Always pass |
OneLake Data Access via | COMMON-CLI.md § OneLake Data Access via curl | Use |
| SQL / TDS Data-Plane Access | COMMON-CLI.md § SQL / TDS Data-Plane Access | |
| Job Execution (CLI) | COMMON-CLI.md § Job Execution | |
| OneLake Shortcuts | COMMON-CLI.md § OneLake Shortcuts | |
| Capacity Management (CLI) | COMMON-CLI.md § Capacity Management | |
| Composite Recipes | COMMON-CLI.md § Composite Recipes | |
| Gotchas & Troubleshooting (CLI-Specific) | COMMON-CLI.md § Gotchas & Troubleshooting (CLI-Specific) | |
| Quick Reference | COMMON-CLI.md § Quick Reference | |
| Item-Type Capability Matrix | SQLDW-CONSUMPTION-CORE.md § Item-Type Capability Matrix | Shows read-only (SQLEP) vs read-write (DW) |
| Connection Fundamentals | SQLDW-CONSUMPTION-CORE.md § Connection Fundamentals | TDS, port 1433, Entra-only, no MARS |
| Supported T-SQL Surface Area (Consumption Focus) | SQLDW-CONSUMPTION-CORE.md § Supported T-SQL Surface Area | Read before writing T-SQL — includes data types (no |
| Read-Side Objects You Can Create | SQLDW-CONSUMPTION-CORE.md § Read-Side Objects You Can Create | Views, TVFs, scalar UDFs, procedures |
| Temporary Tables | SQLDW-CONSUMPTION-CORE.md § Temporary Tables | |
| Cross-Database Queries | SQLDW-CONSUMPTION-CORE.md § Cross-Database Queries | 3-part naming, same workspace only |
| Security for Consumption | SQLDW-CONSUMPTION-CORE.md § Security for Consumption | GRANT/DENY, RLS, CLS, DDM |
| Monitoring and Diagnostics | SQLDW-CONSUMPTION-CORE.md § Monitoring and Diagnostics | Includes query labels; DMVs (live) + |
| Performance: Best Practices and Troubleshooting | SQLDW-CONSUMPTION-CORE.md § Performance: Best Practices and Troubleshooting | Statistics, caching, clustering, query tips |
| REST API: Refresh SQL Endpoint Metadata | SQLDW-CONSUMPTION-CORE.md § REST API: Refresh SQL Endpoint Metadata | Force metadata sync when SQLEP is stale after ETL |
| System Catalog Queries (Metadata Exploration) | SQLDW-CONSUMPTION-CORE.md § System Catalog Queries | |
| Common Consumption Patterns | SQLDW-CONSUMPTION-CORE.md § Common Consumption Patterns | Reporting views, cross-DB analytics, temp table staging |
| Gotchas and Troubleshooting (Consumption) | SQLDW-CONSUMPTION-CORE.md § Gotchas and Troubleshooting Reference | 18 numbered issues with cause + resolution |
| Quick Reference: Consumption Capabilities | SQLDW-CONSUMPTION-CORE.md § Quick Reference: Consumption Capabilities | |
| Authoring Capability Matrix | SQLDW-AUTHORING-CORE.md § Authoring Capability Matrix | Read 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 Snapshots | SQLDW-AUTHORING-CORE.md § Time Travel and Warehouse Snapshots (DW Only) | FOR TIMESTAMP AS OF; 30-day retention; snapshots GA |
| Source Control and CI/CD | SQLDW-AUTHORING-CORE.md § Source Control and CI/CD (DW Only — Preview) | Git integration, SQL DB projects, deployment pipelines |
| Authoring Permission Model | SQLDW-AUTHORING-CORE.md § Authoring Permission Model | Contributor minimum for DDL/DML; Admin for GRANT |
| Authoring Gotchas and Troubleshooting | SQLDW-AUTHORING-CORE.md § Authoring Gotchas and Troubleshooting | 17-row issue/cause/resolution table |
| Common Authoring Patterns | SQLDW-AUTHORING-CORE.md § Common Authoring Patterns | Incremental load, SCD Type 1, SQLEP view layer |
| Quick Reference: Authoring Decision Guide | SQLDW-AUTHORING-CORE.md § Quick Reference: Authoring Decision Guide | Scenario → recommended approach lookup |
| Core Authoring via CLI | authoring-cli-quickref.md § Core Authoring via CLI | Table DDL, DML, data ingestion |
| Advanced Authoring Patterns via CLI | authoring-cli-quickref.md § Advanced Authoring Patterns via CLI | Transactions, schema evolution, stored procedures, time travel |
| Bash Templates | authoring-script-templates.md § Bash Templates | COPY INTO, ELT pipeline, upsert with retry, schema migration, time travel recovery, stored procedure |
| PowerShell Templates | authoring-script-templates.md § PowerShell Templates | COPY INTO ingestion, incremental upsert with retry |
| Tool Stack | SKILL.md § Tool Stack | |
| Connection | SKILL.md § Connection | FQDN discovery, reusable vars, PowerShell |
| Script Generation | authoring-cli-quickref.md § Script Generation | sqlcmd output flags, piped input, parameterized queries |
| Agentic Workflows | SKILL.md § Agentic Workflows | Start here — discover schema before any write |
| Monitoring Authoring Operations | authoring-cli-quickref.md § Monitoring Authoring Operations | Active DML/DDL, recent ETL, failed writes |
| Gotchas, Rules, Troubleshooting | SKILL.md § Gotchas, Rules, Troubleshooting | MUST DO / AVOID / PREFER checklists |
| Agent Integration Notes | authoring-cli-quickref.md § Agent Integration Notes | Platform-specific tips (Copilot CLI, Claude Code) |
| 任务 | 参考文档 | 说明 |
|---|---|---|
| 在Fabric中查找工作区和项目 | COMMON-CLI.md § 在Fabric中查找工作区和项目 | 必看 — 请先阅读链接内容 [需要通过工作区名称查找工作区ID,或通过项目名称、项目类型和工作区ID查找项目ID] |
| Fabric拓扑与核心概念 | COMMON-CORE.md § Fabric拓扑与核心概念 | |
| 环境URL | COMMON-CORE.md § 环境URL | |
| 认证与令牌获取 | COMMON-CORE.md § 认证与令牌获取 | 受众错误会导致401;遇到任何认证问题前请先阅读 |
| 核心控制平面REST API | COMMON-CORE.md § 核心控制平面REST API | 包含分页、LRO轮询和速率限制模式 |
| OneLake数据访问 | COMMON-CORE.md § OneLake数据访问 | 需要 |
| 定义信封 | 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 § 认证示例 | |
通过 | COMMON-CLI.md § 通过az rest调用Fabric控制平面API | 务必传递 |
通过 | COMMON-CLI.md § 通过curl访问OneLake数据 | 使用 |
| SQL / TDS数据平面访问 | COMMON-CLI.md § SQL / TDS数据平面访问 | |
| 作业执行(CLI) | COMMON-CLI.md § 作业执行 | |
| OneLake快捷方式 | COMMON-CLI.md § OneLake快捷方式 | |
| 容量管理(CLI) | COMMON-CLI.md § 容量管理 | |
| 复合示例 | COMMON-CLI.md § 复合示例 | |
| 注意事项与故障排查(CLI专属) | COMMON-CLI.md § 注意事项与故障排查(CLI专属) | |
| 快速参考 | COMMON-CLI.md § 快速参考 | |
| 项目类型能力矩阵 | SQLDW-CONSUMPTION-CORE.md § 项目类型能力矩阵 | 展示只读(SQLEP)与读写(DW)的区别 |
| 连接基础 | SQLDW-CONSUMPTION-CORE.md § 连接基础 | TDS、端口1433、仅支持Entra、不支持MARS |
| 支持的T-SQL功能范围(以消费为重点) | SQLDW-CONSUMPTION-CORE.md § 支持的T-SQL功能范围 | 编写T-SQL前请阅读 — 包含数据类型(不支持 |
| 可创建的只读端对象 | 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(实时)+ |
| 性能:最佳实践与故障排查 | SQLDW-CONSUMPTION-CORE.md § 性能:最佳实践与故障排查 | 统计信息、缓存、聚类、查询提示 |
| REST API:刷新SQL端点元数据 | SQLDW-CONSUMPTION-CORE.md § REST API:刷新SQL端点元数据 | ETL后SQLEP元数据过时,强制同步 |
| 系统目录查询(元数据探索) | SQLDW-CONSUMPTION-CORE.md § 系统目录查询 | |
| 常见消费模式 | 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/CD | SQLDW-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的 |
| 通过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 § 工具栈 | |
| 连接 | 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
工具栈
| Tool | Role | Install |
|---|---|---|
| Primary: Execute DDL/DML T-SQL. Standalone binary, no ODBC, built-in Entra ID auth. | |
| Auth ( | Pre-installed in most dev environments |
| Parse JSON from | Pre-installed or trivial |
Agent check — verify before first operation:bashsqlcmd --version 2>/dev/null || echo "INSTALL: winget install sqlcmd OR brew install sqlcmd"
| 工具 | 作用 | 安装方式 |
|---|---|---|
| 核心工具:执行DDL/DML T-SQL。独立二进制文件,无需ODBC,内置Entra ID认证。 | |
| 认证( | 多数开发环境已预装 |
| 解析 | 已预装或易于安装 |
Agent检查 — 首次操作前请验证:bashsqlcmd --version 2>/dev/null || echo "INSTALL: winget install sqlcmd OR brew install sqlcmd"
Authoring Scope by Item Type
按项目类型划分的编写范围
| Capability | Warehouse (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
--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
--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
--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
--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
undefinedbash
undefinedNon-interactive one-shot query
非交互式单次查询
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>" -G
-Q "SELECT TOP 10 * FROM dbo.FactSales"
-Q "SELECT TOP 10 * FROM dbo.FactSales"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>" -G
-Q "SELECT TOP 10 * FROM dbo.FactSales"
-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"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>"
--authentication-method ActiveDirectoryServicePrincipal
-U "<appId>"
-Q "SELECT COUNT(*) FROM dbo.FactSales"
undefinedSQLCMDPASSWORD="<clientSecret>"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>"
--authentication-method ActiveDirectoryServicePrincipal
-U "<appId>"
-Q "SELECT COUNT(*) FROM dbo.FactSales"
sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>"
--authentication-method ActiveDirectoryServicePrincipal
-U "<appId>"
-Q "SELECT COUNT(*) FROM dbo.FactSales"
undefinedReusable Connection Variables
可重用连接变量
bash
undefinedbash
undefinedSet 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
undefinedPowerShell / 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
undefined1. 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
undefinedAgentic Workflow
Agentic工作流步骤
- Discover → Run steps 1–4 to understand available tables/columns.
- Sample → on relevant tables.
SELECT TOP 5 - Formulate → Select pattern from SQLDW-AUTHORING-CORE.md (Table DDL through Common Authoring Patterns).
- Execute → or
$SQLCMD -Q "..."for multi-statement.$SQLCMD -i file.sql - Verify → Query affected table (,
SELECT COUNT(*)).SELECT TOP 5 - Optionally script → Generate reusable or
.shusing references/authoring-script-templates.md..ps1
- 发现 → 执行步骤1-4,了解可用的表/列。
- 采样 → 对相关表执行查询。
SELECT TOP 5 - 制定方案 → 从SQLDW-AUTHORING-CORE.md中选择合适的模式(从表DDL到常见编写模式)。
- 执行 → 使用或
$SQLCMD -Q "..."执行多语句操作。$SQLCMD -i file.sql - 验证 → 查询受影响的表(如,
SELECT COUNT(*))。SELECT TOP 5 - 可选:生成脚本 → 使用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 and check
GET /v1/workspaces/{id}.capacityId - Always — FQDN alone is insufficient.
-d <DatabaseName> - Always or
-G— SQL auth not supported on Fabric.--authentication-method - first —
az loginuses az session. No session → cryptic failure.ActiveDirectoryDefault - in scripts — suppresses row-count messages that corrupt output.
SET NOCOUNT ON; - Use for multi-statement batches (CREATE PROCEDURE, transactions with GO separators).
-i file.sql - Label authoring queries with .
OPTION (LABEL = 'ETL_description') - Use explicit in CTAS to control output types.
CAST() - Keep transactions short — long transactions increase conflict window.
- 创建仓库前验证工作区是否有容量 — 调用并检查
GET /v1/workspaces/{id}。capacityId - 务必指定— 仅FQDN不足以连接。
-d <DatabaseName> - 务必使用或
-G— Fabric不支持SQL认证。--authentication-method - 先执行—
az login使用az会话。无会话会导致模糊的错误。ActiveDirectoryDefault - 脚本中添加— 抑制行数消息,避免破坏输出。
SET NOCOUNT ON; - 多语句批处理使用(如CREATE PROCEDURE、带GO分隔符的事务)。
-i file.sql - 为编写查询添加标签,使用。
OPTION (LABEL = 'ETL_description') - CTAS中使用显式— 控制输出类型。
CAST() - 保持事务简短 — 长事务会增加冲突窗口。
AVOID
避免
- ODBC sqlcmd () — requires ODBC driver. Use Go version.
/opt/mssql-tools/bin/sqlcmd - Omitting in scripts — trailing spaces corrupt CSV.
-W - Singleton at scale — creates tiny Parquet files. Use INSERT...SELECT, CTAS, or COPY INTO.
INSERT ... VALUES - +
DROP TABLE IF EXISTSto refresh — loses time-travel history. UseCREATE TABLE+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 from connection strings.
MultipleActiveResultSets
- ODBC版sqlcmd()— 需要ODBC驱动。请使用Go版本。
/opt/mssql-tools/bin/sqlcmd - 脚本中省略— 尾随空格会破坏CSV。
-W - 大规模使用单条— 会创建极小的Parquet文件。请使用INSERT...SELECT、CTAS或COPY INTO。
INSERT ... VALUES - 使用+
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— parallel, single-operation.INSERT - over singleton INSERTs.
INSERT ... SELECT - for external file ingestion — highest throughput.
COPY INTO - DELETE + INSERT over MERGE for upserts in production.
- over
TRUNCATE TABLEwithout WHERE — faster, preserves history.DELETE FROM - over
-i file.sqlfor anything beyond simple one-liners.-Q "..." - Piped here-doc for multi-statement batches without GO requirements.
- CTAS + sp_rename for large-scale transforms instead of UPDATE.
- over curl+token for SQL queries.
sqlcmd (Go) -G - (non-interactive exit) for agentic use.
-Q - for exploration of wide tables.
-F vertical - Env vars (,
FABRIC_SERVER) for script reuse.FABRIC_DB
- 使用CTAS替代+
CREATE TABLE— 并行执行,单步操作。INSERT - 使用替代单条INSERT。
INSERT ... SELECT - 使用进行外部文件Ingestion — 吞吐量最高。
COPY INTO - 生产环境中使用DELETE + INSERT替代MERGE进行Upsert。
- 使用替代无WHERE子句的
TRUNCATE TABLE— 更快,保留历史。DELETE FROM - 复杂操作使用替代
-i file.sql。-Q "..." - 无GO要求的多语句批处理使用管道here-doc。
- 大规模转换使用CTAS + sp_rename替代UPDATE。
- SQL查询使用替代curl+令牌。
sqlcmd (Go) -G - Agentic场景使用(非交互式退出)。
-Q - 宽表探索使用。
-F vertical - 脚本重用使用环境变量(,
FABRIC_SERVER)。FABRIC_DB
TROUBLESHOOTING
故障排查
| Symptom | Fix |
|---|---|
| Error 24556/24706 snapshot conflict | Serialize writes to same table; retry with backoff |
| COPY INTO auth error | Grant Storage Blob Data Reader on ADLS; or SAS in CREDENTIAL |
| COPY INTO from OneLake fails | Provision workspace identity; check firewall rules |
| CTAS unexpected types | Use explicit |
| Singleton INSERT poor perf | Remediate: CTAS + drop + rename to consolidate Parquet |
Proc CREATE fails with | Use |
| sp_rename on SQLEP fails | Only available on Warehouse, not Lakehouse/Mirrored DB |
| Deploy drops/recreates table | Avoid ALTER TABLE in DB project; apply manually |
| Verify |
| Re-discover FQDN via REST API; check port 1433 / firewall |
| |
Garbled CSV / | Add |
| Install Go version: |
| 症状 | 修复方案 |
|---|---|
| 错误24556/24706快照冲突 | 序列化对同一表的写入;带退避重试 |
| COPY INTO认证错误 | 为ADLS授予Storage Blob Data Reader权限;或在CREDENTIAL中使用SAS |
| 从OneLake执行COPY INTO失败 | 配置工作区标识;检查防火墙规则 |
| CTAS返回意外类型 | SELECT中使用显式 |
| 单条INSERT性能差 | 修复:CTAS + 删除 + 重命名以合并Parquet文件 |
使用 | 使用 |
| SQLEP上执行sp_rename失败 | 仅数据仓库支持,Lakehouse/镜像数据库不支持 |
| 部署时删除/重建表 | DB项目中避免ALTER TABLE;手动应用变更 |
| 验证 |
| 通过REST API重新发现FQDN;检查端口1433/防火墙 |
| |
CSV乱码 / 文件中出现 | 添加 |
| 安装Go版本: |