Independent and not affiliated with the FDA, MHRA, ISPE, PDA, or any agency. Get the appgoutham@madhadi.com
madhadi.comData Integrity & GxP Quality
Browse all topics → Articles Templates & Procedures Learning paths GlossaryScenariosToolsRegulatory ReferencesLearning PathsTopics About Start here
SOP Plug-and-play starting point CSV / CSA

SOP: Controlled Emergency Direct Database Edit

A plug-and-play standard operating procedure for the rare, unavoidable case of a direct database edit to GxP data: pre-execution QA approval, a scoped and reviewed SQL statement, before and after images, a witnessed transaction, and independent corroboration against the native database audit log, with a filled specimen.

Document type: SOP

Read and copy the template below into your own quality system. It is a generic starting point for your own internal use, provided as is, with no warranty; see the Terms and License. Adopting it does not by itself create compliance.

This is a ready-to-use SOP. Replace every <<FILL: ...>> placeholder with your own specifics, set your document numbers and dates, and route it through your normal document control, review, and approval. A worked filled specimen follows the template so you can see how a completed version reads. Use this procedure only when the application layer offers no path to correct the problem; verify each cited regulation against the current source before you rely on it.

Document control header

FieldEntry
Document titleControlled Emergency Direct Database Edit
Document number<<FILL: SOP-ID, e.g. SOP-IT-022>>
Version<<FILL: version, e.g. 1.0>>
Effective date<<FILL: effective date>>
Supersedes<<FILL: prior version or "New">>
Document owner<<FILL: role, e.g. Head of IT / Head of Data Integrity>>
Applies to<<FILL: sites / systems in scope>>

1. Purpose

This procedure defines the only route by which a GxP record may be altered directly at the database tier, bypassing the application, so that when this route is used, the resulting edit is fully reconstructable, pre-approved, witnessed, and independently corroborated. It exists because direct edits are occasionally the only way to correct a genuine defect (data corruption, a stuck workflow, an orphaned row from a migration defect) that the application itself cannot resolve, and an undocumented back-end edit is indistinguishable from falsification.

2. Scope

This procedure applies to every direct INSERT, UPDATE, or DELETE statement executed against a production database table holding GxP data, outside the normal application path. It does not apply to DBA activity that does not alter GxP business data (backup, restore of a non-GxP environment, performance tuning, schema changes under separate change control). Governance of who may hold direct database access at all is defined in <<FILL: SOP-ID for DBA governance and segregation of duties>>.

3. Responsibilities

RoleResponsibility
Requester (system owner or process owner)Identifies the defect, confirms no application-mediated fix exists, and raises the change
Database administrator (executor)Prepares the exact SQL statement, captures before and after images, executes under a witnessed transaction
Quality Assurance (witness and approver)Approves the change before execution, witnesses execution, confirms row count and value match the approval before commit is authorized
System ownerAssesses downstream impact of the edited data on calculations, release decisions, or submissions
Validation / IT securityConfirms the native database audit log corroborates the executed statement after the fact

4. Definitions

  • Before image: a saved query result showing the exact rows and values immediately before the edit.
  • After image: a saved query result showing the exact rows and values immediately after the edit, confirming the change did exactly what was authorized and nothing more.
  • Scoped statement: a SQL statement whose WHERE clause is reviewed in advance and confirmed to touch only the intended row(s), typically by primary key.
  • QA witness: a Quality Assurance representative, independent of the executor, present (in person or via a controlled remote session) during execution to attest that what ran matched what was approved.

5. Procedure

5.1 Confirm no application path exists

  1. The requester documents the defect and confirms, in writing, that no supported application function, administrative screen, or standard workflow can correct it.
  2. If an application path exists, use it. This procedure is not a shortcut around slower application-mediated fixes.

5.2 Raise the change and obtain pre-execution approval

  1. Raise a change record per <<FILL: SOP-ID for change control>> describing the defect, the business or compliance impact of not fixing it, the exact proposed SQL statement, the affected record(s) identified by primary key, and the rollback plan.
  2. Attach application-side evidence of the problem (screenshots, error logs, the stuck workflow state).
  3. QA and the system owner review and approve the change before any statement is executed. For a genuine emergency, use the expedited approval path defined in <<FILL: SOP-ID for change control>>; expedited means faster, not skipped.

5.3 Capture the before image

  1. Immediately before execution, the DBA runs and saves a SELECT of exactly the rows to be changed, capturing every column that will be affected.
  2. Attach the before image to the change record.

5.4 Execute under a witnessed transaction

  1. Open an explicit transaction (BEGIN TRANSACTION or the platform equivalent).
  2. Execute the exact statement reviewed and approved in section 5.2, no ad hoc modification.
  3. Run a verifying SELECT to confirm the new state and the number of rows affected.
  4. The QA witness confirms the row count matches expectation and the resulting values match the approved change before authorizing commit.
  5. If the row count or values do not match, ROLLBACK immediately and return to section 5.2 to re-plan; do not attempt to patch the statement mid-transaction.
  6. On confirmation, COMMIT.

5.5 Capture the after image and close the record

  1. Immediately after commit, run and save a SELECT of the same rows to serve as the after image.
  2. Attach the after image and the QA witness attestation to the change record.
  3. Within <<FILL: number>> business days, confirm the native database audit log recorded the statement, with a row count and account matching the change record; attach the audit-log excerpt.
  4. The system owner assesses whether the edited value feeds a calculation, a release decision, or a submission, and triggers a deviation or impact assessment per <<FILL: SOP-ID for deviation management>> if so.
  5. Close the change record with the approval, both images, the witness attestation, and the audit-log confirmation all attached.

6. Acceptance criteria

An emergency edit is defensible only when all of the following are true: QA approved the exact statement before execution; the statement was scoped to named rows by primary key; a before image and an after image were both captured; the edit ran inside a transaction with a verified row count before commit; a QA witness independent of the executor attested to the execution; the native database audit log independently corroborates the statement; and downstream data impact was assessed. Any one missing element makes the edit indistinguishable from an unauthorized change, regardless of intent.

7. References

21 CFR Part 11.10(e) (audit trails) and the general expectation that changes to electronic records be justified, approved, and traceable. EU GMP Annex 11, clause 9 (audit trails). PIC/S PI 041, Good Practices for Data Management and Integrity in Regulated GMP/GDP Environments.

Confirm the current version and clause numbers of each reference before issue.

8. Record generated: emergency database edit record

FieldEntry
Change record number<<FILL>>
System / database / table<<FILL>>
Defect description<<FILL>>
Confirmed no application path exists (who, how)<<FILL>>
Approved SQL statement<<FILL>>
Affected row(s), by primary key<<FILL>>
QA pre-approval (name, signature, date)<<FILL>>
Before image reference<<FILL: attachment ID>>
Execution date/time and DBA (executor)<<FILL>>
Row count affected (expected / actual)<<FILL>>
QA witness attestation (name, signature, date)<<FILL>>
After image reference<<FILL: attachment ID>>
Native audit log corroboration (reference, matches Y/N)<<FILL>>
Downstream impact assessment outcome<<FILL: none, or deviation number>>
Change record closed by (name, date)<<FILL>>

9. Revision history

VersionDateAuthorSummary of change
<<FILL: 1.0>><<FILL: date>><<FILL: author>>Initial issue.

10. Approvals

RoleNameSignatureDate
Author<<FILL>>
Reviewer (QA)<<FILL>>
Approver (Head of IT)<<FILL>>

Filled specimen

FieldEntry
Change record numberCHG-2026-0337
System / database / tableMES production database, table BATCH_PHASE
Defect descriptionEquipment cleaning status flag did not update after cleaning execution, blocking batch B-2026-0991 from advancing to the next phase; the application has no supported path to clear the flag once stuck
Confirmed no application path exists (who, how)J. Okafor (system owner) confirmed with the MES vendor’s support desk (ticket #48812) that no administrative screen can clear the flag
Approved SQL statementUPDATE BATCH_PHASE SET CLEAN_STATUS='VERIFIED' WHERE BATCH_ID='B-2026-0991' AND PHASE_ID=4
Affected row(s), by primary keyBATCH_ID=‘B-2026-0991’, PHASE_ID=4 (one row)
QA pre-approvalR. Gomez, signed, 14 July 2026 08:40
Before image referenceCHG-2026-0337-Attach-1 (CLEAN_STATUS=‘PENDING’)
Execution date/time and DBA (executor)14 July 2026 09:05, S. Lindqvist
Row count affected (expected / actual)1 / 1
QA witness attestationR. Gomez, signed, 14 July 2026 09:07, witnessed via screen-share
After image referenceCHG-2026-0337-Attach-2 (CLEAN_STATUS=‘VERIFIED’)
Native audit log corroborationDB-Audit-2026-0714-441, one UPDATE from account slindqvist against BATCH_PHASE at 09:05:12, matches
Downstream impact assessment outcomeNone; flag is a workflow gate, not a release-decision value; no deviation required
Change record closed byM. Alvarez, 15 July 2026

This is what a defensible emergency edit looks like end to end: pre-approved, scoped to one row, witnessed at the moment of execution, and corroborated by an independent log, so an inspector reviewing it sees a fully reconstructable action rather than a quiet fix.

Common inspection findings this SOP prevents

  • A back-end fix applied first, with the change paperwork completed afterward or not at all.
  • An UPDATE with a loose or missing WHERE clause that affects more rows than intended, discovered only later.
  • No before image, so the prior value can never be proven and the edit cannot be reversed with confidence.
  • No independent QA witness present at execution, only a signature added afterward.
  • The native database audit log never checked against the change record, so the two independent trails were never actually reconciled.

How to adapt this SOP

  1. Set your document number, owner, and effective date in the header.
  2. Point the cross-references in sections 2, 5.2, and 5.5 to your real DBA governance, change control, and deviation management procedures.
  3. Set the audit-log confirmation window in section 5.5 to match how quickly your platform’s audit log becomes available for review.
  4. If your organization requires a specific remote-witness tool or protocol, name it in section 5.4.
  5. Confirm every regulation in section 7 against the current published version before issue.
Use madhadi.com as an app Full screen, works offline, one tap from your home screen.