/database-sqlserver:generating-table-descriptionfrom database-sqlserver
Use when generating table description documentation from SQL view files. Use when user says "產生資料表描述", "文件化檢視表", "更新 TableDescription", "由 view 產欄位對照". Use when user wants to document view-to-table field mappings for a SQL Server database.
Ships in database-sqlserver. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
從 SQL 檢視表(View)檔案解析欄位映射、關聯關係及計算邏輯,產生標準化的 Markdown 資料表結構說明文件。
核心原則: 嚴格按照主表、關聯表、計算欄位分組。每個欄位都必須正確歸類。
FROM 語句提取主表名稱LEFT JOIN 語句提取所有關聯表及其關聯條件逐行解析,提取:
原始欄位 AS 新欄位名稱 映射-- 中文說明 (原始欄位) [關聯表] {選項值}-- 訂單、-- 時間)必須按以下順序分為三類:
| 類別 | 判斷依據 | 表格欄位 |
|---|---|---|
| 主表欄位 | 來自 FROM 主表 | 原始欄位名稱 / 新欄位名稱 / 說明 / 關聯 / 範例 |
| 關聯表欄位 | 來自 LEFT JOIN 表,按字母排序 | 原始欄位名稱 / 新欄位名稱 / 說明 / 關聯 / 範例 |
| 計算欄位 | 含 CASE WHEN / CONVERT(BIT / ISNULL / DATEDIFF | 欄位名稱 / 說明 / 計算邏輯 / 範例 |
輸出格式:
# 資料表結構說明
## 資料表:{主表名} ({中文說明})
| 原始欄位名稱 | 新欄位名稱 | 說明 | 關聯 | 範例 |
| ------------ | ---------- | ---- | ---- | ---- |
## 資料表:{關聯表名} ({說明})
| 原始欄位名稱 | 新欄位名稱 | 說明 | 關聯 | 範例 |
| ------------ | ---------- | ---- | ---- | ---- |
## 計算欄位
| 欄位名稱 | 說明 | 計算邏輯 | 範例 |
| -------- | ---- | -------- | ---- |
表名.欄位){...} 包含在說明中-- ,欄位名稱)CONVERT(BIT, CASE WHEN ...)):提取 CASE WHEN 條件作為計算邏輯SEMP, PEMP)需統一處理從 SELECT 語句中提取 原始欄位 AS 新欄位名稱 的映射關係:
ORD_MST.ORD_NO AS OrderIdORD_NO,新欄位名稱 = OrderId從註解中提取欄位說明:
-- 訂單編號 (ORD_NO)訂單編號,原始欄位確認 = ORD_NOA. JOIN 語句
LEFT JOIN CUST WITH(NOLOCK) -- 客戶
ON ORD_MST.CUST_NO = CUST.CUST_NO
提取:關聯表 = CUST,關聯欄位 = CUST_NO
B. 註解中的關聯標記
-- 客戶編號 (CUST_NO) [CUST]
提取:關聯 = CUST.CUST_NO
C. 外鍵關聯格式
-- 業務人員編號 [EMP].[EMP_NO]
提取:關聯 = EMP.EMP_NO
A. 計算欄位識別關鍵字:CASE WHEN、CONVERT(BIT,、ISNULL(、DATEDIFF(
B. 布林型計算欄位
,ISNULL(CONVERT(BIT, CASE WHEN ORD_MST.STATUS_FLG = 'C' THEN 1 ELSE 0 END), 0) AS IsCanceled
ORD_MST.STATUS_FLG = 'C'A. 大括號內的選項值
-- 訂單狀態代碼 (STATUS_FLG) {未結=O,結案=Y,暫停=P,作廢=C}
說明須包含選項值的完整內容。
B. 方括號內的關聯說明
-- 文件編號 [外部系統訂單編號]
說明須包含業務描述的完整內容。
範例 1 — 基本欄位轉換
SQL:ORD_MST.ORD_NO AS OrderId -- 訂單編號 (ORD_NO)
| 原始欄位名稱 | 新欄位名稱 | 說明 | 關聯 | 範例 |
|---|---|---|---|---|
| ORD_NO | OrderId | 訂單編號 |
範例 2 — 含關聯資訊的欄位
SQL:ORD_MST.CUST_NO AS CustomerId -- 客戶編號 (CUST_NO) [CUST]
| 原始欄位名稱 | 新欄位名稱 | 說明 | 關聯 | 範例 |
|---|---|---|---|---|
| CUST_NO | CustomerId | 客戶編號 | CUST.CUST_NO |
範例 3 — 含選項值的欄位
SQL:ORD_MST.TYPE1 AS OrderTypeName -- 訂單類型名稱 (TYPE1) {標準/急件}
| 原始欄位名稱 | 新欄位名稱 | 說明 | 關聯 | 範例 |
|---|---|---|---|---|
| TYPE1 | OrderTypeName | 訂單類型名稱 {標準/急件} |
範例 4 — 計算欄位
SQL:,ISNULL(CONVERT(BIT, CASE WHEN ORD_MST.STATUS_FLG = 'C' THEN 1 ELSE 0 END), 0) AS IsCanceled -- 已取消
| 欄位名稱 | 說明 | 計算邏輯 | 範例 |
|---|---|---|---|
| IsCanceled | 已取消 | ORD_MST.STATUS_FLG = 'C' |
沒有原始欄位的情況:對於直接來自關聯表的欄位,原始欄位名稱使用關聯表的欄位名稱:
,SOT.OrderTypeCode -- 訂單類型代碼
原始欄位名稱 = OrderTypeCode
複雜的計算邏輯:提取核心條件作為計算邏輯,忽略 ISNULL、CONVERT 等包裝函數:
,CASE WHEN ORD_MST.STATUS_FLG != 'Y' OR ORD_MST.OK_DATE IS NULL THEN NULL
ELSE DATEDIFF(DAY, GETDATE(), ORD_MST.OK_DATE) END AS RemainingDays
計算邏輯 = DATEDIFF(DAY, GETDATE(), ORD_MST.OK_DATE)
多表同名欄位:優先使用主表的欄位;若來自關聯表則在說明中標註來源表。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub kerryhuang/kerryhuang-plugins --plugin database-sqlserver6 skills in this plugin
/ef-migrationUse when 建立 / 套用 / 回復 EF Core migration、跑 `dotnet ef` 指令、切換目標資料庫連線、migration 失敗診斷。管理 SQL Server 上的 Entity Framework Core 資料庫 Migration。觸發:「建 migration」「套用 migration」「回滾 migration」「dotnet ef」「migration 失敗」。/migration-troubleshootUse when diagnosing special EF Core migration situations — ModelSnapshot 衝突、歷史紀錄遺失、資料庫已套用但 migration 對不上、生產緊急回滾判斷。一般失敗修復循環走 ef-migration skill。觸發:「migration 對不上」「snapshot 衝突」「緊急回滾」「migration 診斷」。/syncing-db-entitiesUse when adding new DB tables/views to an EF Core project, syncing entity changes from the database, fixing Entity precision / nullable / MaxLength that drifted from the DB actual schema, or user says "加表", "同步 Entity", "scaffold", "efcpt", "更新實體", "re-scaffold", "重新產生 Entity". Also trigger when reading a file with header `// <auto-generated> This file has been auto generated by EF Core Power Tools.` that needs modification — manual edits will be overwritten, must go through efcpt./table-conventionsUse when writing or reviewing SQL Server table (CREATE TABLE) scripts, or user says "資料表慣例", "table 命名規則", "怎麼建表", "table convention". Provides a convention framework for table file structure, column naming, audit columns, and alter scripts. 觸發:撰寫 `Table/**/*.sql` DDL 時。/view-conventionsUse when writing or reviewing SQL Server view (CREATE VIEW) scripts, or user says "檢視表慣例", "view 命名規則", "怎麼建 view", "view convention". Provides a convention framework for view file structure, SELECT column formatting, JOIN style, and naming. 觸發:撰寫 `View/**/*.sql` DDL 時。