Export data from ClickHouse and import it into SQL Server while preserving schema, data types, and indexes.
Dump ClickHouse tables to CSV or Parquet with clickhouse-client
, copy files to the SQL Server host, then run BULK INSERT
or an SSIS package to load them. This minimizes network overhead and lets you parallel-load large tables.
1) Export schema
2) Map data types
3) Export data
4) Create target tables
5) Bulk load data
6) Recreate indexes & constraints
7) Validate counts & checksums
Use clickhouse-client --query="SELECT * FROM Orders FORMAT CSV" > orders.csv
. Repeat for each table or script multiple queries in parallel for speed.
Translate ClickHouse types: UInt32 → INT
, DateTime64 → DATETIME2
, Decimal(18,2) → DECIMAL(18,2)
. Always set NOT NULL
where ClickHouse columns lacked nullability.
BULK INSERT Orders FROM 'C:\data\orders.csv' WITH (FORMAT='CSV', FIRSTROW=2, FIELDTERMINATOR=',', ROWTERMINATOR='\n', TABLOCK)
. Use CHECK_CONSTRAINTS
and ERRORFILE
for safer loads.
After loading, run row counts: SELECT COUNT(*) FROM Orders
in both systems. For deeper checks, compare MD5 of sorted primary-key & critical numeric columns.
Add them only after data loads finish; doing so earlier slows BULK INSERT
drastically.
Yes. Wrap each step in PowerShell or Python, use sqlcmd
for DDL, and parallelize exports with GNU parallel
to hit near-wire speed.
Replicate last-minute changes with incremental exports (WHERE updated_at >= :last_sync
), schedule a short freeze, replay deltas, swap application connection strings, and monitor error rates.
Yes. Add a watermark column like updated_at
in ClickHouse, export only newer rows, and schedule periodic syncs until final cutover.
No direct equivalent. Recreate them as indexed views or pre-computed tables refreshed with SQL Agent jobs.