Changing Variable Value in a Database

A variable value can generally be changed using two approaches.

1) Through the Application (App ↔ Database Pair)

Flow:
User → Application → Business Logic / Validation → Database

Example:

user.balance += 50
save(user)

The application updates the database after applying its business rules.

Advantages:

  • ✓ Business rules are enforced
  • ✓ Validation and security checks occur
  • ✓ Audit logging may be recorded
  • ✓ Lower risk of corrupting data
  • ✓ Cache stays synchronized

Disadvantages:

  • ✗ Slightly slower due to application layer
  • ✗ Requires the application to be available

2) Directly Accessing the Database

Flow:
Administrator / Script → Database

Example:

UPDATE Users
SET balance = balance + 50
WHERE id = 1;

The database value is changed directly without going through application logic.

Advantages:

  • ✓ Faster execution
  • ✓ Useful for bulk updates
  • ✓ Helpful for emergency fixes
  • ✓ Easy automation via scripts

Disadvantages:

  • ✗ Bypasses application validation
  • ✗ May violate business rules
  • ✗ Can create cache inconsistencies
  • ✗ Higher risk of data corruption

Comparison

Aspect Through App Direct DB
Business Rules ✓ Applied ✗ Bypassed
Validation ✓ Yes ✗ No
Speed ✗ Slower ✓ Faster
Safety ✓ Higher ✗ Lower

Practical Guideline

  • Normal operations: Use the application layer.
  • Maintenance, migrations, emergency fixes: Use direct database access.
Architecture Rule:
Applications own the data logic, while databases own the data storage. Therefore, routine variable changes should normally go through the application, while direct database changes should be reserved for controlled administrative scenarios.

Comments

Popular posts from this blog

[MAIN PROGRAM] UNDONE HOUSEHOLD WORKs WEB-PROGRAM v2/MAIN

PENDING ITEMs [REVISION] v0