tableCopy β
Command:
tableCopy
Category: Schema Tools
Status: Production Ready
Description β
Copies table structure and/or data from one table to another, with optional filtering capabilities. This is useful for creating table backups, copying data subsets, or migrating tables between schemas.
Syntax β
hana-cli tableCopy [options]Aliases β
tablecopycopyTablecopytable
Command Diagram β
Parameters β
Positional Arguments β
This command has no positional arguments.
Options β
| Option | Alias | Type | Default | Description |
|---|---|---|---|---|
--sourceTable | -st | string | - | Source table name. |
--targetTable | -tt | string | - | Target table name. |
--sourceSchema | -ss | string | **CURRENT_SCHEMA** | Source schema name. |
--targetSchema | -ts | string | **CURRENT_SCHEMA** | Target schema name. |
--structureOnly | -so | boolean | false | Copy table structure only. |
--dataOnly | -do | boolean | false | Copy data only (target table must exist). |
--where | -w | string | - | SQL WHERE clause (without WHERE). |
--limit | -l | number | - | Maximum number of rows to copy. |
--batchSize | -b, --batch | number | 1000 | Batch size for row inserts. |
--dryRun | -dr, --preview | boolean | false | Accepted preview flag for dry-run workflows. |
--timeout | --to | number | 3600 | Operation timeout in seconds. |
--profile | -p | string | - | Connection profile to use. |
Connection Parameters β
| Option | Alias | Type | Default | Description |
|---|---|---|---|---|
--admin | -a | boolean | false | Use admin connection settings. |
--conn | - | string | Config-dependent | Override connection file. |
Troubleshooting β
| Option | Alias | Type | Default | Description |
|---|---|---|---|---|
--disableVerbose | --quiet | boolean | false | Reduce verbose output. |
--debug | -d | boolean | false | Enable debug output. |
Copy Modes β
The command operates in three modes:
1. Both Structure and Data (Default) β
- Creates target table
- Copies all data
- Use when creating a complete copy
2. Structure Only (--structureOnly) β
- Creates empty target table
- No data copied
- Use for creating table templates
- Conflict: Cannot be used with
--dataOnly
3. Data Only (--dataOnly) β
- Target table must already exist
- Only copies data
- Use for refreshing existing tables
- Conflict: Cannot be used with
--structureOnly
Filtering Options β
WHERE Clause (--where) β
- Filters rows during copy
- SQL WHERE clause syntax (without the WHERE keyword)
- Examples:
STATUS = 'ACTIVE'AMOUNT > 1000 AND CURRENCY = 'USD'CREATE_DATE >= '2024-01-01'
LIMIT (--limit) β
- Limits total number of rows copied
- Applied after WHERE filter
- Useful for:
- Testing with sample data
- Creating partial copies
- Avoiding timeouts on large tables
Output Format β
Starting table copy from PRODUCTION.CUSTOMERS to PRODUCTION.CUSTOMERS_BACKUP
Copying table structure
Table structure copied successfully
Copying table data
Read 25,432 rows from source table
Processed 1000 of 25432 rows
Processed 2000 of 25432 rows
...
Processed 25432 of 25432 rows
25,432 rows copied successfully
Table copy complete. Source: CUSTOMERS, Target: CUSTOMERS_BACKUP, Rows copied: 25432
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββ¬βββββββββββ¬βββββββββββββββ¬ββββββββββββββββ
β SOURCE β TARGET β STRUCTURE_COPIED β ROWS_COPIED β MODE β WHERE_FILTER β LIMIT_APPLIED β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββΌβββββββββββΌβββββββββββββββΌββββββββββββββββ€
β PRODUCTION.CUSTOMERSβ PRODUCTION.CUSTOMERS_BACKUPβ YES β 25432 β BOTH β NONE β NONE β
βββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββ΄βββββββββββ΄βββββββββββββββ΄ββββββββββββββββStructure Copy Details β
When copying structure, the following are included:
- β Column names and data types
- β Column order
- β NOT NULL constraints
- β DEFAULT values
- β Primary keys
- β Unique constraints
- β Indexes
Note: Foreign keys, triggers, and complex constraints may not be copied.
Examples β
1. Basic Table Copy β
Copy entire table (structure and data):
hana-cli tableCopy -st CUSTOMERS -tt CUSTOMERS_BACKUP2. Cross-Schema Copy β
Copy table from one schema to another:
hana-cli tableCopy \
-st ORDERS \
-ss PRODUCTION \
-tt ORDERS \
-ts ARCHIVE3. Structure Only β
Copy just the table structure without data:
hana-cli tableCopy \
-st EMPLOYEES \
-tt EMPLOYEES_TEMPLATE \
-so4. Data Only β
Copy data to an existing table:
hana-cli tableCopy \
-st TRANSACTIONS \
-tt TRANSACTIONS_COPY \
-do5. Filtered Copy with WHERE Clause β
Copy only specific rows:
hana-cli tableCopy \
-st SALES \
-tt SALES_2024 \
-w "YEAR = 2024 AND STATUS = 'COMPLETED'"6. Limited Row Copy β
Copy only first N rows (useful for testing):
hana-cli tableCopy \
-st LARGE_TABLE \
-tt SAMPLE_TABLE \
-l 100007. Batch Processing β
Copy large table with custom batch size:
hana-cli tableCopy \
-st BIG_DATA_TABLE \
-tt BIG_DATA_COPY \
-b 50008. Combined Filters β
Combine WHERE clause and LIMIT:
hana-cli tableCopy \
-st USERS \
-tt ACTIVE_USERS_SAMPLE \
-w "STATUS = 'ACTIVE'" \
-l 10009. Cross-Schema with Filter β
Copy filtered data between schemas:
hana-cli tableCopy \
-st EVENTS \
-ss LOGS \
-tt RECENT_EVENTS \
-ts REPORTING \
-w "EVENT_DATE >= ADD_DAYS(CURRENT_DATE, -7)"Use Cases β
- Table Backup: Create quick backups before updates or deletes
- Data Archiving: Copy historical data to archive tables
- Test Data: Create smaller test datasets from production tables
- Schema Migration: Move tables between schemas
- Data Sampling: Extract representative samples for analysis
- Table Refresh: Update development tables with production data
- Data Transformation: Copy filtered/subset data for processing
Performance Considerations β
- Batch Size: Adjust based on row size and network
- Small rows (< 100 bytes): Use larger batches (5000+)
- Large rows (> 1KB): Use smaller batches (500-1000)
- Indexes: Target table indexes created automatically affect insert speed
- Network: Cross-system copies slower than same-system
- WHERE Clause: Complex filters may slow down the source query
- Parallel Operations: Consider splitting large tables by partition
Prerequisites β
- SELECT privilege on source table
- CREATE TABLE privilege on target schema (for structure copy)
- INSERT privilege on target table (for data copy)
- Sufficient disk space for target table
Notes β
- Target table created using
CREATE TABLE ... LIKEsyntax - If target exists and
dataOnlynot set, command fails - Column compatibility checked automatically
- NULL values handled appropriately
- Large tables should use appropriate batch size
- Consider using LIMIT for initial testing
- WHERE clause must be valid SQL
- Timeout should account for data volume
Error Handling β
Common Errors β
Target table already exists β
- Use
--dataOnlyto append to existing table - Or drop the target table first
Source table not found β
- Verify table name and schema
- Check case sensitivity
- Ensure connection to correct database
Permission denied β
- Check privileges on source and target
- May need table-level or schema-level grants
Out of memory β
- Reduce batch size
- Use WHERE clause to copy in smaller chunks
- Consider copying by partition
Timeout exceeded β
- Increase timeout parameter
- Use LIMIT to copy in stages
- Optimize WHERE clause
Best Practices β
- Test First: Use LIMIT on first run to verify setup
- Monitor Progress: Watch the row count output
- Batch Sizing: Tune batch size for optimal performance
- Filters: Apply WHERE clauses to reduce data volume
- Timing: Run large copies during off-peak hours
- Verification: Check row counts after copy completion
- Cleanup: Remove intermediate tables after testing
- Documentation: Document purpose of copied tables
Related Commands β
export- Export data after validation or copy.import- Load exported data into a target environment.tables- List and verify source/target tables.
See the Commands Reference for other commands in this category.