Skip to content
/ tablemd Public

TableMD is a lightweight utility that extracts schema metadata from Oracle and SQL Server databases and generates table dictionary files in Markdown format. It supports both single table and pattern queries (e.g., ABC%), making it easy to document, share, and version-control database structures.

Notifications You must be signed in to change notification settings

pigsly/tablemd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# TableMD

**TableMD** 是一個簡單的 **資料字典產生工具**,可從 **Oracle****SQL Server** 擷取表格結構,輸出成 Markdown 文件。

輸出格式如下:

```markdown
## 表格名稱:TXD2BV01LOG

| 欄位  | 資料型別 | 長度/精度 | Nullable | 預設值 | 主鍵 | 外鍵             | 說明       |
|-------|----------|-----------|----------|--------|------|------------------|------------|
| COL_A | VARCHAR2 | 50        | N        |        | Y    |                  | 使用者代號 |
| COL_B | NUMBER   | 10,0      | Y        | 0      |      | FK → `OTHER.COL` | 訂單編號   |

功能特點

  • 支援 Oracle (SID 或 ServiceName)SQL Server (ODBC Driver 17/18)

  • 可輸出單一表格或 LIKE 多表格(如 ABC%)。

  • 每張表格輸出到獨立檔案:

    • Oracle → output/<ORA_USER>/TABLE_<NAME>.md

    • SQL Server → output/<DBNAME>/TABLE_<NAME>.md

  • 已存在的檔案會直接覆蓋。

  • 使用 Poetry 管理依賴。


安裝

  1. 安裝 Poetry(需 Python 3.11+)。

  2. 安裝依賴:

    poetry install
  3. 確認安裝成功:

    poetry run python tablemd.py --help

設定檔 (tablemd.properties)

在專案根目錄建立 tablemd.properties

Oracle 範例

DB_TYPE=oracle
OUTPUT_BASE=output

ORA_HOST=127.0.0.1
ORA_PORT=1521
ORA_SID=ORCL
# ORA_SERVICE=ORCLPDB1
ORA_USER=APPS
ORA_PWD=your_password
ORA_SCHEMA=APPS

SQL Server 範例

DB_TYPE=sqlserver
OUTPUT_BASE=output

MSSQL_DRIVER=ODBC Driver 18 for SQL Server
MSSQL_SERVER=127.0.0.1
MSSQL_PORT=1433
MSSQL_DBNAME=ERP
MSSQL_USER=sa
MSSQL_PWD=your_password

# 若遇到憑證信任錯誤,請加上
MSSQL_ENCRYPT=yes
MSSQL_TRUST_SERVER_CERTIFICATE=yes

使用方式

Windows

使用批次檔:

tablemd.bat TXD2BV01LOG
tablemd.bat ABC%%

直接用 Poetry 執行:

poetry run python tablemd.py TXD2BV01LOG
poetry run python tablemd.py ABC%

執行結果

檔案會輸出到 output/<ID>/ 目錄下:

output/
└── APPS/
    ├── TABLE_TXD2BV01LOG.md
    └── TABLE_ABC123.md

注意事項

  • Oracle:

    • ORA_SCHEMATABLE_NAME 會自動轉大寫比對。

    • 確保已安裝 Oracle Instant Client 並加到 PATH

  • SQL Server:

    • 建議使用 ODBC Driver 18

    • 若伺服器憑證非受信任 CA,可設 MSSQL_TRUST_SERVER_CERTIFICATE=yes

  • 所有 .bat.properties 檔請存成 UTF-8 (無 BOM)ANSI


待辦事項

  • 增加 Debug 模式(印出實際 SQL)。

  • 增加 poetry run tablemd 指令入口。

  • 支援 PostgreSQL / MySQL。


readme 資料字典索引 Sample

授權

MIT License

About

TableMD is a lightweight utility that extracts schema metadata from Oracle and SQL Server databases and generates table dictionary files in Markdown format. It supports both single table and pattern queries (e.g., ABC%), making it easy to document, share, and version-control database structures.

Topics

Resources

Stars

Watchers

Forks