# Usage – Data Copy (Variant B / Checkpointing) ## Preconditions 1. **Target database exists** (e.g. UTF-8 collation) 2. **Target schema is deployed** (tables, constraints, indexes, views, procs, triggers, users/roles etc.) 3. You can connect to the SQL Server instance with sufficient permissions. ## Run Open `scripts/migrate_copy_checkpoint.sql` in SSMS. At the top configure: - `@SourceDb` (default: `sysdb_UTF8`) - `@TargetDb` (default: `sysdb_utf8_jr`) Optional behavior: - `@Mode` - `RESUME` (default): skip tables already marked `DONE` - `RESET`: reset state and rerun all tables - `@StopOnError` - `1` (default): stop on first table error - `0`: continue with next tables; check `dbo.MigrationState` afterwards - `@BatchSize` - used for tables with `IDENTITY (int/bigint)` to copy in chunks Execute the script. ## Monitoring The script prints progress like: - `... | TABLE_START | dbo.TableX` - `... | TABLE_DONE | dbo.TableX | Old=... New=...` - `... | TABLE_FAILED | dbo.TableX | Error ...` In target DB you also have: - `dbo.MigrationState` (table-level status) - `dbo.MigrationCopyLog` (append-only log) Useful queries: ```sql USE sysdb_utf8_jr; SELECT * FROM dbo.MigrationState ORDER BY Status, TableSchema, TableName; SELECT TOP 200 * FROM dbo.MigrationCopyLog ORDER BY LogId DESC; ``` ## Rerun behavior Each table is copied as: 1. `DELETE FROM target.table` 2. `INSERT INTO target.table SELECT ... FROM source.table` So reruns are safe. The checkpoint state enables resuming.