sap-hana-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSAP HANA Developer CLI (hana-cli)
SAP HANA Developer CLI (hana-cli)
Related Skills
相关技能
- sap-cap-capire: Use for CAP database development, HDI container management, and CDS syntax comparison
- sap-btp-cloud-platform: Use for HANA Cloud operations, BTP integration, and cloud instance management
- sap-abap-cds: Use for comparing CDS syntax between CAP and ABAP or understanding HANA CDS features
- sap-datasphere: Use when working with SAP Datasphere integration or data warehousing scenarios
A developer-centric command-line interface for SAP HANA database development, particularly useful in non-SAP tooling environments like VS Code.
Repository: https://github.com/SAP-samples/hana-developer-cli-tool-example
npm Package: https://www.npmjs.com/package/hana-cli
Current Version: 3.202405.1 (April 2024)
Node.js Requirement: ≥20.19.0
- sap-cap-capire: 用于CAP数据库开发、HDI容器管理以及CDS语法对比
- sap-btp-cloud-platform: 用于HANA Cloud操作、BTP集成以及云实例管理
- sap-abap-cds: 用于对比CAP与ABAP的CDS语法,或理解HANA CDS特性
- sap-datasphere: 用于SAP Datasphere集成或数据仓库场景
一款面向开发者的命令行界面,专为SAP HANA数据库开发设计,在VS Code等非SAP工具环境中尤为实用。
代码仓库: https://github.com/SAP-samples/hana-developer-cli-tool-example
npm包: https://www.npmjs.com/package/hana-cli
当前版本: 3.202405.1(2024年4月)
Node.js要求: ≥20.19.0
Table of Contents
目录
Quick Start
快速开始
Installation
安装
bash
undefinedbash
undefinedInstall globally via npm (recommended)
通过npm全局安装(推荐)
npm install -g hana-cli
npm install -g hana-cli
Verify installation
验证安装
hana-cli version
undefinedhana-cli version
undefinedFirst Connection
首次连接
bash
undefinedbash
undefinedInteractive connection setup
交互式连接设置
hana-cli connect
hana-cli connect
Or specify connection directly
或直接指定连接信息
hana-cli connect -n "hostname:port" -u DBUSER -p PASSWORD --save
hana-cli connect -n "hostname:port" -u DBUSER -p PASSWORD --save
Using service key (HANA Cloud)
使用服务密钥(HANA Cloud)
hana-cli connectViaServiceKey
---hana-cli connectViaServiceKey
---MCP Integration (AI-Driven Database Operations)
MCP集成(AI驱动的数据库操作)
Overview
概述
The hana-mcp-server integration enables natural language database operations through Claude's Model Context Protocol. Use conversational queries alongside traditional CLI commands for a complete development workflow.
hana-mcp-server集成通过Claude的模型上下文协议(Model Context Protocol)支持自然语言数据库操作。可在传统CLI命令之外使用对话式查询,实现完整的开发工作流。
Setup
设置
1. Environment Variables
1. 环境变量
Required configuration (add to ~/.zshrc, ~/.bashrc, or project .env):
bash
export HANA_HOST="your-hana-host.hanacloud.ondemand.com"
export HANA_PORT="443"
export HANA_USER="DBADMIN"
export HANA_PASSWORD="your-password"
export HANA_ENCRYPT="true" # Optional, defaults to true
export HANA_DATABASE="" # Optional, for MDC tenant
export HANA_CONNECTION_TYPE="single-container" # Optional需配置以下环境变量(添加至~/.zshrc、~/.bashrc或项目的.env文件):
bash
export HANA_HOST="your-hana-host.hanacloud.ondemand.com"
export HANA_PORT="443"
export HANA_USER="DBADMIN"
export HANA_PASSWORD="your-password"
export HANA_ENCRYPT="true" # 可选,默认值为true
export HANA_DATABASE="" # 可选,适用于MDC租户
export HANA_CONNECTION_TYPE="single-container" # 可选2. Connection Types
2. 连接类型
- single-container (default): Standard HANA databases
- mdc-system: Multi-tenant system database
- mdc-tenant: Specific tenant in multi-tenant environment
- single-container(默认):标准HANA数据库
- mdc-system:多租户系统数据库
- mdc-tenant:多租户环境中的特定租户
When to Use: CLI vs MCP
使用场景:CLI vs MCP
| Scenario | Recommended Tool | Why |
|---|---|---|
| Exploratory queries, ad-hoc analysis | MCP | Natural language, no syntax needed |
| Automation scripts, CI/CD pipelines | CLI | Scriptable, consistent output |
| Learning database structure | MCP | Conversational discovery |
| Generating CDS/EDMX/OpenAPI output | CLI | Supports 17+ formats |
| Complex multi-step workflows | CLI | Fine-grained control |
| Quick data sampling and inspection | MCP | Faster for one-off queries |
| 场景 | 推荐工具 | 原因 |
|---|---|---|
| 探索式查询、临时分析 | MCP | 支持自然语言,无需语法知识 |
| 自动化脚本、CI/CD流水线 | CLI | 可编写脚本,输出一致 |
| 学习数据库结构 | MCP | 对话式探索 |
| 生成CDS/EDMX/OpenAPI输出 | CLI | 支持17种以上格式 |
| 复杂多步骤工作流 | CLI | 精细控制 |
| 快速数据采样与检查 | MCP | 一次性查询更高效 |
Example Natural Language Queries
自然语言查询示例
Schema & Table Discovery
架构与表发现
- "Show me all schemas in this HANA database"
- "List all tables in the SYSTEM schema"
- "What tables exist in the MY_APP schema?"
- "Show me all views in the PUBLIC schema"
- "显示此HANA数据库中的所有架构"
- "列出SYSTEM架构中的所有表"
- "MY_APP架构中有哪些表?"
- "显示PUBLIC架构中的所有视图"
Table Structure & Metadata
表结构与元数据
- "Describe the structure of the USERS table"
- "What columns does the ORDERS table have?"
- "Show me the data types for MY_TABLE"
- "What is the primary key of the CUSTOMERS table?"
- "描述USERS表的结构"
- "ORDERS表有哪些列?"
- "显示MY_TABLE的数据类型"
- "CUSTOMERS表的主键是什么?"
Data Sampling & Inspection
数据采样与检查
- "Sample 5 rows from the PRODUCTS table"
- "Show me the first 10 records from SALES_DATA"
- "Get sample data from ORDER_ITEMS table"
- "Display a few rows from MY_TABLE"
- "从PRODUCTS表中采样5行数据"
- "显示SALES_DATA的前10条记录"
- "获取ORDER_ITEMS表的样本数据"
- "显示MY_TABLE的若干行数据"
Query Execution
查询执行
- "How many rows are in the CUSTOMERS table?"
- "Show me distinct values in the STATUS column of ORDERS"
- "What is the maximum value in the PRICE column of PRODUCTS?"
- "Find all records in USERS where country is 'USA'"
- "CUSTOMERS表中有多少行数据?"
- "显示ORDERS表STATUS列的不同值"
- "PRODUCTS表PRICE列的最大值是多少?"
- "查找USERS表中国家为'USA'的所有记录"
System Performance & Monitoring
系统性能与监控
- "Check the HANA database status"
- "Show me system performance metrics"
- "What is the current database version?"
- "检查HANA数据库状态"
- "显示系统性能指标"
- "当前数据库版本是什么?"
MCP Tools Available
可用的MCP工具
The hana-mcp-server provides these MCP tools:
- : Enumerate all schemas
list_schemas - : Show tables in a schema
list_tables - : Get table structure and metadata
describe_table - : Execute SQL queries from natural language
query - : Retrieve sample rows
sample_data - : Database status and performance
system_info
hana-mcp-server提供以下MCP工具:
- :枚举所有架构
list_schemas - :显示架构中的表
list_tables - :获取表结构与元数据
describe_table - :将自然语言转换为SQL并执行
query - :获取样本行数据
sample_data - :数据库状态与性能信息
system_info
Example: MCP + CLI Workflow
示例:MCP + CLI工作流
bash
undefinedbash
undefined1. Use MCP to explore (natural language)
1. 使用MCP探索(自然语言)
"Show me all tables in the PRODUCTS schema"
"显示PRODUCTS架构中的所有表"
2. Use MCP to understand structure
2. 使用MCP了解结构
"Describe the PRODUCTS.INVENTORY table"
"描述PRODUCTS.INVENTORY表"
3. Use CLI for format conversion (precise output)
3. 使用CLI进行格式转换(精确输出)
hana-cli inspectTable -t INVENTORY -s PRODUCTS -o cds
hana-cli inspectTable -t INVENTORY -s PRODUCTS -o cds
4. Use CLI for HDI operations
4. 使用CLI执行HDI操作
hana-cli createContainer -c MY_CONTAINER
---hana-cli createContainer -c MY_CONTAINER
---Core Command Categories
核心命令分类
Database Object Inspection
数据库对象检查
| Command | Aliases | Purpose |
|---|---|---|
| | Inspect table structure |
| - | Inspect view definition |
| - | Inspect stored procedure |
| - | Inspect function definition |
| - | List all tables in schema |
| - | List all views in schema |
| - | List stored procedures |
| - | List functions |
| 命令 | 别名 | 用途 |
|---|---|---|
| | 检查表结构 |
| - | 检查视图定义 |
| - | 检查存储过程 |
| - | 检查函数定义 |
| - | 列出架构中的所有表 |
| - | 列出架构中的所有视图 |
| - | 列出存储过程 |
| - | 列出函数 |
Query Execution
查询执行
| Command | Aliases | Purpose |
|---|---|---|
| | Execute SQL query |
| | Execute stored procedure |
| - | Direct SQL execution |
| 命令 | 别名 | 用途 |
|---|---|---|
| | 执行SQL查询 |
| | 执行存储过程 |
| - | 直接执行SQL |
HDI Container Management
HDI容器管理
| Command | Aliases | Purpose |
|---|---|---|
| | List HDI containers |
| - | Create new container |
| - | Remove container |
| - | Enable HDI service |
| - | Administer HDI privileges |
| 命令 | 别名 | 用途 |
|---|---|---|
| | 列出HDI容器 |
| - | 创建新容器 |
| - | 删除容器 |
| - | 启用HDI服务 |
| - | 管理HDI权限 |
Cloud & BTP Operations
云与BTP操作
| Command | Aliases | Purpose |
|---|---|---|
| - | List HANA Cloud instances |
| - | Start cloud instance |
| - | Stop cloud instance |
| - | Configure BTP CLI |
| - | Display BTP target info |
| 命令 | 别名 | 用途 |
|---|---|---|
| - | 列出HANA Cloud实例 |
| - | 启动云实例 |
| - | 停止云实例 |
| - | 配置BTP CLI |
| - | 显示BTP目标信息 |
Output Formats
输出格式
The / option supports 17+ formats:
--output-o| Format | Use Case |
|---|---|
| Human-readable table (default) |
| JSON data |
| YAML format |
| CSV export |
| Excel file |
| CAP CDS definitions |
| HANA CDS format |
| HDB Table definitions |
| SQL DDL statements |
| OData EDMX metadata |
| OpenAPI/Swagger spec |
| GraphQL schema |
--output-o| 格式 | 使用场景 |
|---|---|
| 人类可读表格(默认) |
| JSON数据 |
| YAML格式 |
| CSV导出 |
| Excel文件 |
| CAP CDS定义 |
| HANA CDS格式 |
| HDB表定义 |
| SQL DDL语句 |
| OData EDMX元数据 |
| OpenAPI/Swagger规范 |
| GraphQL架构 |
Connection Configuration
连接配置
Connection credentials are searched in priority order:
- (with
default-env-admin.jsonflag)--admin - (via
.cdsrc-private.json)cds bind - file with VCAP_SERVICES
.env - File specified via parameter
--conn - in current/parent directories
default-env.json ~/.hana-cli/default.json
For connection templates, see .
templates/default-env.json连接凭据按以下优先级顺序查找:
- (配合
default-env-admin.json参数使用)--admin - (通过
.cdsrc-private.json获取)cds bind - 包含VCAP_SERVICES的文件
.env - 通过参数指定的文件
--conn - 当前/父目录中的
default-env.json ~/.hana-cli/default.json
连接模板可查看。
templates/default-env.jsonCommon Workflows
常见工作流
Inspect and Convert Table to CDS
检查表结构并转换为CDS格式
bash
undefinedbash
undefinedInspect table structure
检查表结构
hana-cli inspectTable -s MYSCHEMA -t MYTABLE
hana-cli inspectTable -s MYSCHEMA -t MYTABLE
Convert to CDS format
转换为CDS格式
hana-cli inspectTable -s MYSCHEMA -t MYTABLE -o cds
undefinedhana-cli inspectTable -s MYSCHEMA -t MYTABLE -o cds
undefinedMass Convert Schema Objects
批量转换架构对象
bash
undefinedbash
undefinedConvert all objects in schema to CDS
将架构中的所有对象转换为CDS格式
hana-cli massConvert -s MYSCHEMA
undefinedhana-cli massConvert -s MYSCHEMA
undefinedExecute Query with Export
执行查询并导出结果
bash
undefinedbash
undefinedRun query and export to JSON
执行查询并导出为JSON
hana-cli querySimple -q "SELECT * FROM MYTABLE" -o json
hana-cli querySimple -q "SELECT * FROM MYTABLE" -o json
Export to Excel file
导出为Excel文件
hana-cli querySimple -q "SELECT * FROM MYTABLE" -o excel -f ./output -n report
undefinedhana-cli querySimple -q "SELECT * FROM MYTABLE" -o excel -f ./output -n report
undefinedManage HDI Containers
管理HDI容器
bash
undefinedbash
undefinedList all containers
列出所有容器
hana-cli containers
hana-cli containers
Create new container
创建新容器
hana-cli createContainer -c MY_CONTAINER -g MY_GROUP
hana-cli createContainer -c MY_CONTAINER -g MY_GROUP
Create container users
创建容器用户
hana-cli createContainerUsers -c MY_CONTAINER
---hana-cli createContainerUsers -c MY_CONTAINER
---UI Commands
UI命令
Many commands have browser-based UI alternatives (suffix ):
UI- - Browse tables visually
tablesUI - - Manage containers in browser
containersUI - - Visual mass conversion
massConvertUI - - Query builder interface
querySimpleUI - - System dashboard
systemInfoUI
许多命令提供基于浏览器的UI替代方案(后缀为):
UI- - 可视化浏览表
tablesUI - - 在浏览器中管理容器
containersUI - - 可视化批量转换
massConvertUI - - 查询构建器界面
querySimpleUI - - 系统仪表板
systemInfoUI
Key Features
核心特性
- Multi-database support: HANA, PostgreSQL, SQLite backends
- Format conversion: 17+ output formats including CDS, EDMX, OpenAPI
- HDI management: Full container lifecycle management
- Cloud integration: SAP BTP CLI and HANA Cloud support
- Interactive prompts: Missing parameters prompted automatically
- Service key auth: Secure cloud authentication
- 多数据库支持:HANA、PostgreSQL、SQLite后端
- 格式转换:17种以上输出格式,包括CDS、EDMX、OpenAPI
- HDI管理:完整的容器生命周期管理
- 云集成:SAP BTP CLI与HANA Cloud支持
- 交互式提示:自动提示缺失的参数
- 服务密钥认证:安全的云认证方式
Detailed References
详细参考文档
For comprehensive documentation:
- All 91 Commands: See
references/command-reference.md - Connection & Security: See
references/connection-security.md - HDI Management: See
references/hdi-management.md - Output Formats: See
references/output-formats.md - Cloud Operations: See
references/cloud-operations.md - Database Inspection: See
references/db-inspection.md - Mass Operations: See
references/mass-operations.md - System Administration: See
references/system-admin.md - Web UI Interface: See
references/web-ui.md - Troubleshooting Guide: See
references/troubleshooting.md - Development Environment: See
references/development-environment.md - ABAP Programming Patterns: See
references/abap-programming.md
如需完整文档,请查看:
- 全部91条命令:查看
references/command-reference.md - 连接与安全:查看
references/connection-security.md - HDI管理:查看
references/hdi-management.md - 输出格式:查看
references/output-formats.md - 云操作:查看
references/cloud-operations.md - 数据库检查:查看
references/db-inspection.md - 批量操作:查看
references/mass-operations.md - 系统管理:查看
references/system-admin.md - Web UI界面:查看
references/web-ui.md - 故障排查指南:查看
references/troubleshooting.md - 开发环境:查看
references/development-environment.md - ABAP编程模式:查看
references/abap-programming.md
Troubleshooting
故障排查
Connection Issues
连接问题
bash
undefinedbash
undefinedCheck current connection status
检查当前连接状态
hana-cli status
hana-cli status
Test with explicit credentials
使用显式凭据测试连接
hana-cli connect -n "host:443" -u USER -p PASS --encrypt true
hana-cli connect -n "host:443" -u USER -p PASS --encrypt true
Use SSL trust store
使用SSL信任库
hana-cli connect --trustStore /path/to/certificate.pem
undefinedhana-cli connect --trustStore /path/to/certificate.pem
undefinedPermission Errors
权限错误
bash
undefinedbash
undefinedDiagnose privilege errors
诊断权限错误
hana-cli privilegeError
hana-cli privilegeError
View current user info
查看当前用户信息
hana-cli inspectUser
undefinedhana-cli inspectUser
undefinedVersion Compatibility
版本兼容性
- Node.js: Requires ≥20.19.0
- @sap/cds: Uses 9.4.4
- @sap/cds-dk: Requires ≥8.9 for cds bind
- Node.js:需要≥20.19.0
- @sap/cds:使用9.4.4版本
- @sap/cds-dk:需要≥8.9版本以支持cds bind
Bundled Resources
内置资源
Reference Documentation
参考文档
- - Complete command reference with all options
references/command-reference.md - - ABAP-specific programming patterns
references/abap-programming.md - - Quick start guide and examples
references/quick-start.md
- - 包含所有选项的完整命令参考
references/command-reference.md - - ABAP特定编程模式
references/abap-programming.md - - 快速入门指南与示例
references/quick-start.md
Scripts
脚本
- - HANA development environment setup script
scripts/hana-setup.sh - - Migration helper script for existing projects
scripts/migration-helper.sh
- - HANA开发环境设置脚本
scripts/hana-setup.sh - - 现有项目迁移辅助脚本
scripts/migration-helper.sh
Resources
相关资源
- GitHub: https://github.com/SAP-samples/hana-developer-cli-tool-example
- Intro Video: https://youtu.be/dvVQfi9Qgog
- Cloud Shells Demo: https://youtu.be/L7QyVLvAIIQ
- SAP HANA Cloud: https://help.sap.com/docs/hana-cloud
- SAP CAP: https://cap.cloud.sap/docs/
Last Updated: 2025-11-26 | Version: 1.1.0
- GitHub:https://github.com/SAP-samples/hana-developer-cli-tool-example
- 入门视频:https://youtu.be/dvVQfi9Qgog
- 云Shell演示:https://youtu.be/L7QyVLvAIIQ
- SAP HANA Cloud:https://help.sap.com/docs/hana-cloud
- SAP CAP:https://cap.cloud.sap/docs/
最后更新:2025-11-26 | 版本:1.1.0