Runtime verified Test scripts included

Syntax

DeleteData(dataExt, columnName1, valueToDelete1[, columnNameN, valueToDeleteN, ...])  →  number

Parameters

Name Type Required Description
dataExt string Yes Name or external key of the data extension to delete from
columnName1 string Yes First column to match on
valueToDelete1 string | number Yes Value the first column must equal
columnNameN string No Further match columns, each paired with a value
valueToDeleteN string | number No Value for the corresponding further column

Example

%%[
  VAR @rows
  SET @rows = DeleteData("AMP_VERIFY_SCRATCH", "Id", "X1")
]%%
Deleted: %%=v(@rows)=%%

Renders Deleted: 1 when a row with Id X1 exists. Reading back in a later render confirms it is gone: rows=[0].

Delete on a composite criterion by adding more column/value pairs:

%%[
  DeleteData("Contacts", "Region", "EU", "Status", "inactive")
]%%

Return value

number — the count of rows deleted. A no-match returns 0 and deletes nothing: DeleteData("AMP_VERIFY_SCRATCH", "Id", "NOPE") returned 0. The twin DeleteDE performs the same delete but returns an empty string.

Behaviour

Ordered column/value match pairs. Arguments after dataExt are read as column, value, column, value, …; every pair must match for a row to be deleted. This is the *Data argument shape.

A no-match is a silent no-op — no error, no abort, 0 returned.

Deletes are visible immediately to fresh reads. Confirm a delete with RowCount(LookupRows(...)) in a subsequent render; the AMPscript within-render read cache means a row read earlier in the same render may still appear until the render ends.

Show test script
%%[
  VAR @b, @r
  SET @b = RequestParameter("b")

  IF @b == "zzz" THEN
    OutputLine(Concat("CTRL=[alive]"))
  ENDIF

  IF @b == "safe" THEN
    InsertData("AMP_VERIFY_SCRATCH", "Id", "X1", "FirstName", "Xena", "Score", 1)
    SET @r = DeleteData("AMP_VERIFY_SCRATCH", "Id", "X1")
    OutputLine(Concat("DeleteData ret=[", @r, "]"))
    /* a no-match returns 0 */
    OutputLine(Concat("DeleteData nomatch ret=[", DeleteData("AMP_VERIFY_SCRATCH", "Id", "NOPE"), "]"))
  ENDIF

  IF @b == "read" THEN
    OutputLine(Concat("X1 rows=[", RowCount(LookupRows("AMP_VERIFY_SCRATCH", "Id", "X1")), "]"))
  ENDIF
]%%

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next No

See also