SQL Server to Databricks: Redesign the Reporting Procedure
Preserve the business result and prove what happens on a rerun.
A procedure can produce the right total on a clean run and still leave finance with a broken report after a partial failure. Decide what must be published together, how a retry identifies the same business result, and what readers see while recovery is in progress.

- One business resultPreserve the invoice detail and regional totals.
- Safe rerunsTest partial failure and uncertain commit outcomes.
- One report releaseKeep every page on the same approved version.
A finance report can reconcile during migration testing and still be unsafe to release. The missing test is often an interruption between two writes, followed by a retry.
Consider a procedure that produces daily invoice detail and regional margin totals. A translation that loads the detail, stops before updating the summary, and then appends the detail again can pass a clean run and fail the first recovery attempt. Finance receives a report whose pages disagree, or whose totals include the same invoice twice.
When moving an existing SQL Server analytics warehouse to Databricks, approve the procedure’s behavior as well as its calculations. Define the input, the changes that must commit together, the identity of a retry, the reporting release, and the people allowed to run or read it. Those decisions determine which SQL features and orchestration steps belong in the target design.
Start with the report’s promise
Consider an Ontario distributor’s Canadian reporting operation.
Its SQL Server procedure prepares a daily margin pack from a completed warehouse extract. For September 30, the small test fixture contains four invoice lines: CAD 12,400 in net revenue, CAD 9,000 in recognized cost, and CAD 3,400 in margin. East contributes CAD 7,500 in revenue and CAD 2,100 in margin; West contributes CAD 4,900 and CAD 1,300.
The procedure must deliver both the detail and the two regional totals from the same approved input. If it cannot do that, the previous complete report remains available and displays its actual reporting date. A newer date must never conceal older or incomplete data.
Write that promise before converting code. Specify the business date and time zone, accepted source snapshot, invoice-line key, amount types, treatment of reversals, and response to missing costs or region mappings. Define what a correction means: a newly approved input produces a new release, while a retry of unchanged input reuses the existing release identity.
Inspect the SQL Server implementation and its scheduler together. An explicit transaction, SET XACT_ABORT, error handling, and the caller’s retry settings all affect observed behavior. Microsoft documents that XACT_ABORT ON rolls back a transaction on a runtime error; compile errors are outside that setting’s scope. A CATCH block can also hide an error from the caller unless it returns or raises it appropriately. Microsoft: XACT_ABORT, TRY…CATCH.
Choose from the current Databricks capabilities
Databricks supports SQL scripting and stored procedures. Scripting applies to Databricks SQL and Databricks Runtime 16.3 and above; procedures require Unity Catalog and apply to Databricks SQL and Runtime 17.0 and above. Individual features have additional requirements. For example, calling procedures through the Databricks ODBC driver requires version 2.11 or later. SQL scripting.
Transactions that write to Unity Catalog managed Delta tables became generally available on July 22, 2026. Current documentation still identifies transaction writes to managed Iceberg tables as Private Preview. Databricks release notes, transaction requirements.
For the example, a non-interactive BEGIN ATOMIC ... END block is a reasonable choice. Every table it writes must be a Unity Catalog managed table with catalog commits enabled. Supported compute includes a SQL warehouse, serverless compute, or a cluster running Runtime 18.0 or above. Interactive transactions use a SQL warehouse. DDL such as creating or altering tables belongs outside the transaction. Azure Databricks transactions.
The practical decision is whether the procedure’s SQL work fits a supported transaction boundary. A plain BEGIN ... END script does not establish that boundary. External report refreshes and notification services also need their own completion and recovery handling.
Give the business result a stable identity
KCM recommends treating the report as a versioned release. In the example, release R0930-v1 identifies the September 30 reporting date, frozen source batch B0930, and transformation version T1. The short labels stand for a controlled, collision-resistant identity scheme. Execution attempts A1 and A2 are operational records; they do not create different business releases.
Stage the completed input privately. Preserve the source extraction boundary and the mapping version used to interpret it. Do not let a retry silently switch to today’s customer classifications or a newer invoice extract.
Then use one atomic publication transaction to:
- Check whether this release already committed with the same input identity; if so, return its recorded result without writing again.
- Write the detail and regional summary under that release ID.
- Check key uniqueness, accepted amounts, and agreement between detail and summary.
- Record the committed release and change one reporting pointer to it.
Any failed validation must raise an error. Successful validation allows the four publication tables to commit together: detail, summary, release ledger, and reporting pointer. The ledger records the committed business result. Attempt failures are logged separately, because a log row written inside a rolled-back transaction will also disappear.
Use one controlled publisher for this report dataset, including scheduled runs, manual replays, and corrections. Restrict other writers, reject unexpected pointer state, and test concurrent starts. Databricks primary keys, foreign keys, and unique constraints are informational, so declaring a key does not enforce duplicate prevention. A ledger check without concurrency control is insufficient. Databricks constraints.
Interrupt it in two different places
First, fail after inserting the candidate’s four detail rows and before inserting its regional summary. In a naive append design, those four rows remain. Appending the same input again leaves eight rows, CAD 24,800 in revenue and CAD 6,800 in margin. A summary calculated from those duplicated rows can agree with the detail and still be wrong.
In the proposed atomic design, the failed transaction publishes none of its changes. The report pointer stays on the previous complete release. After confirming that the attempt ended and rolled back, retry the same release from the same frozen input. The expected result is four detail rows, two summary rows, CAD 12,400 revenue and CAD 3,400 margin. Databricks documents automatic rollback for failures in an atomic block. ATOMIC compound statement.
Second, let the transaction commit but lose the response to the caller. A timeout message is not enough evidence to classify the business result. Resolve the original statement’s status and inspect the release ledger. If R0930-v1 committed with the expected input, return that result without adding rows or moving the pointer again. If a later correction is already current, an old retry must not republish or automatically redeliver the older release.
If the original attempt is still running or its outcome cannot be established, hold the retry. An absent ledger row while a transaction remains in progress does not prove it is safe to start again. This is a recovery protocol to test, not an exactly-once guarantee for the entire reporting workflow.
Keep every report page on the same release
The report consumer reads the release pointer once when it starts and uses that release ID for every detail and summary query. Retain the associated rows for the report’s full lifetime. If each query independently asks for the latest release, a publication between queries can still produce a mixed report.
The report heading carries its business date and release ID. If publication fails, the previous date remains visible with a freshness warning. The operator can distinguish an available older report from a completed new report.
For an imported BI model, cached dashboard, file export, or email distribution, separately verify that downstream delivery completed for the intended release. A warehouse commit cannot certify an external refresh. Before a downstream retry, check its delivery record and that the release remains approved for delivery. Do not rebuild or append the business data just because an email or refresh failed.
Map responsibilities and access explicitly
Keep calculations and publication checks in SQL when that is the clearest maintainable design. Put scheduling, source readiness, attempt tracking, retry limits, and external delivery in orchestration with a named operator. Preserve fully qualified object references and test the target using the actual service and reader identities.
SQL Server execution context and ownership chaining need deliberate mapping. Databricks supports invoker security and, for Databricks SQL, definer security. Their privilege and name-resolution behavior differ; a successful administrator test does not establish the service account’s access. Microsoft execution context, Databricks CREATE PROCEDURE.
For this design, use a dedicated publisher identity and an explicitly chosen security mode. Report readers can read approved reporting views but cannot change release data or its pointer. Test both the allowed operation and an operation that should be denied. Record the invoking identity separately from procedure ownership. Authorized user and session user.
The migration decision becomes reviewable when the team can show a matching result, a controlled partial failure, a safe response to an uncertain outcome, a consistent report release, and the intended access boundaries. Use one representative procedure to produce that evidence before multiplying the pattern across a warehouse.
Bring the procedure, its scheduler definition, and one report to a focused redesign review with KCM’s Databricks consulting team.
Product documentation checked October 16, 2026. The worked design requires implementation and testing in the intended environment.
What must survive a rerun?
In this example, four invoice lines produce CAD 12,400 in revenue, CAD 9,000 in cost, and CAD 3,400 in margin. East and West summaries must come from the same frozen input as the detail. A naive append retry can leave eight lines and double revenue to CAD 24,800, even when a rebuilt summary agrees with that wrong detail.
The guide shows how to bind a release to immutable input and transformation versions; commit detail, summary, release record, and report pointer together; resolve a lost commit acknowledgement; and pin every report query to one release. After a correction is current, a retry of an older committed release cannot move the pointer back or automatically redeliver the older release.
Use the design and testing steps in the intended environment; the worked design is not a deployed script or guarantee of exactly-once delivery. Verify current Databricks feature, compute, table, and security requirements in the intended environment.
