Handling IBAN and BBAN Logic During INSERT and UPDATE Operations
Overview
When migrating a banking or financial application from Oracle Database to Microsoft SQL Server, one of the most common challenges is trigger compatibility. Oracle and SQL Server implement triggers very differently, especially when it comes to row-level BEFORE triggers.
This article explains:
- Why Oracle
BEFORE INSERT OR UPDATEtriggers cannot be directly translated to SQL Server - How to correctly replicate Oracle trigger behavior in SQL Server
- A practical example using IBAN and BBAN banking fields
- Safe and clean migration patterns without altering business logic
The examples are fully anonymized while keeping real-world banking terminology intact.
The Business Rule (IBAN / BBAN)
In many banking systems, the following rules are common:
- If IBAN is NULL and BBAN is NOT NULL, then:
- Set
iban = bban
- Set
- If BBAN is NULL, then:
- Set
iban = '1234567890'(default or placeholder value)
- Set
These rules must apply automatically on INSERT and UPDATE.
Oracle Implementation (Source Behavior)
In Oracle, this logic is typically implemented using a row-level BEFORE trigger, allowing modification of incoming values before they are stored.
Oracle Example
CREATE OR REPLACE TRIGGER trg_UpdateIbanOnInsertOrUpdate
BEFORE INSERT OR UPDATE ON loans_accounts
FOR EACH ROW
BEGIN
IF :NEW.iban IS NULL AND :NEW.bban IS NOT NULL THEN
:NEW.iban := :NEW.bban;
END IF;
IF :NEW.bban IS NULL THEN
:NEW.iban := '1234567890';
END IF;
END;
Why This Works in Oracle
- Oracle allows direct modification of
:NEWvalues - The trigger fires before data is written
- Logic is applied per row
Why This Does NOT Work in SQL Server
Microsoft SQL Server does not support:
BEFOREtriggersFOR EACH ROW- Direct modification of
NEWrecords
Instead, SQL Server uses:
- Statement-level triggers
- Virtual tables:
insertedanddeleted
Because of this, Oracle triggers must be redesigned, not copied.
Correct SQL Server Approach
To replicate Oracle BEFORE INSERT OR UPDATE behavior without changing table structure or adding IDs, the best approach is:
✅ Use an INSTEAD OF INSERT, UPDATE Trigger
This allows SQL Server to:
- Intercept incoming data
- Apply IBAN/BBAN logic
- Insert or update rows correctly
SQL Server Trigger (Compatible Equivalent)
For loans_accounts
CREATE TRIGGER trg_UpdateIbanOnInsertOrUpdateLOANS
ON loans_accounts
INSTEAD OF INSERT, UPDATE
AS
BEGIN
INSERT INTO loans_accounts
SELECT
CASE
WHEN iban IS NULL AND bban IS NOT NULL THEN bban
WHEN bban IS NULL THEN '1234567890'
ELSE iban
END AS iban,
bban,
-- all remaining columns in correct order
col3,
col4,
col5
FROM inserted;
END;
For savings_accounts
CREATE TRIGGER trg_UpdateIbanOnInsertOrUpdateSVGS
ON savings_accounts
INSTEAD OF INSERT, UPDATE
AS
BEGIN
INSERT INTO savings_accounts
SELECT
CASE
WHEN iban IS NULL AND bban IS NOT NULL THEN bban
WHEN bban IS NULL THEN '1234567890'
ELSE iban
END AS iban,
bban,
-- all remaining columns in correct order
col3,
col4,
col5
FROM inserted;
END;
🔧 Important:
You must list all table columns explicitly in theINSERT INTOandSELECTstatements, in the exact same order.
Why This Pattern Is Correct
| Requirement | Oracle | SQL Server Solution |
|---|---|---|
| Modify incoming row values | :NEW.column | INSTEAD OF trigger |
| Per-row logic | FOR EACH ROW | inserted table |
| BEFORE semantics | Supported | Simulated |
| No schema changes | Yes | Yes |
| Banking logic preserved | Yes | Yes |
Best Practices for Banking Systems
- ✅ Keep IBAN/BBAN rules inside the database for data integrity
- ✅ Use
INSTEAD OFtriggers for Oracle migrations - ❌ Avoid
AFTERtriggers when values must be corrected before persistence - ❌ Do not rely on application-layer fixes for core financial identifiers
Common Migration Pitfalls
- Assuming
AFTER INSERTis equivalent toBEFORE INSERT - Forgetting that SQL Server triggers are statement-based
- Attempting to update the same table inside an
AFTERtrigger (can cause recursion) - Not handling multi-row inserts properly
SEO Keywords / Tags
oracle to sql server trigger migration,
oracle before trigger sql server,
iban bban database logic,
sql server instead of trigger,
oracle trigger conversion,
banking database migration,
iban bban sql trigger,
financial system sql server
Final Thoughts
Migrating Oracle triggers to SQL Server is not a copy-paste task—it requires understanding execution models. By using INSTEAD OF INSERT, UPDATE triggers, you can preserve critical banking rules such as IBAN and BBAN normalization without altering schemas or introducing technical debt.
This approach ensures data consistency, regulatory safety, and long-term maintainability in financial systems.


