---
title: "SQL-MVC-004: Delete context rows"
summary: Deletes all context rows for a given application and session.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-MVC-004: Delete context rows

Deletes all `Context` rows for a given application and session. This statement is invoked from two call sites: (a) inside `clsContext.RetrieveContext`, immediately after [SQL-MVC-002](SQL-MVC-002-retrieve-cross-application-context.md)'s read, to consume/clear the handed-off context rows for the source application and session; and (b) inside `clsContext.SaveContext`, executed before the loop of inserts ([SQL-MVC-001](SQL-MVC-001-insert-context-value.md)) to clear any prior rows for the current application and session before re-saving — a delete-then-reinsert ("upsert via replace") pattern.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-MVC-004 |
| **Operation type** | Delete |
| **Execution method** | Inline SQL (`SqlCommand.ExecuteNonQuery`) |
| **Database** | SQL Server (catalog `NETFRAMEWORK`) |
| **Schema** | `[unqualified]**` |
| **Command type** | Text |
| **Business object** | N/A (Application layer) |
| **Criteria property** | N/A (Application layer) |
| **Lifecycle method** | N/A (Application layer) |
| **Application class** | `clsContext.clsContextRepository.Delete(inAppName, inSessionID)` — called from `clsContext.RetrieveContext` and `clsContext.SaveContext` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@AppName` | Input | `SqlDbType.VarChar` | 50 | Application name whose context rows are removed; bound from `inAppName`. |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | Session identifier whose context rows are removed; bound from `inSessionID`. |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [Context](../database-tables.md#context) | DELETE | `AppName`, `SessionID` |

## Sample SQL

```sql
-- Delete all context rows for the given application and session
Delete Context
Where
AppName = @AppName and SessionID = @SessionID
```

## Operations and processes
- [Cross-application context hand-off](../operations/cross-application-context-hand-off.md)
- [Cross-application navigation](../operations/cross-application-navigation.md)

## Business rules
- [BR-MVC-005: Cross-application context transfer only across distinct applications](../business-rules.md#br-mvc-005-cross-application-context-transfer-only-across-distinct-applications)

No contention/rowcount validation exists after the delete in either call path.

> **Note:** Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- SAIF.Presentation.Web.MVC\clsContext.vb
