Data Structures in AMPscript

There are two main types of data structures that you interact with when using AMPscript: data extensions and rowsets. These structures are closely related.

At the most basic level, a data extension is a table that contains data. A data extension can stand alone or can be related to other data extensions. You can manually import data extensions into Marketing Cloud Engagement, or you can automate the import through Automation Studio or the Marketing Cloud Engagement API.

A rowset contains one or more collections of data as rows. You can obtain rowsets by querying data extensions using AMPscript functions, such as LookupRows(). You can also create rowsets as needed (for example, by using the BuildRowSetFromJSON() function).

You can refer to an individual row in a rowset by using the Row() function. You can refer to an individual piece of data within a row by using the Field() function. AMPscript doesn’t allow you to output the contents of a rowset or row using functions such as v().

To prevent errors and unexpected issues, we recommend that you check to see if a rowset contains data before processing it in a For loop. The most common way to perform this check is by using the RowCount() function to determine how many rows the rowset contains. You can use the row count in the condition statement in the For loop.

Alternatively, you can use the Empty() and IsNull() functions to determine if the rowset is empty. Both of these functions return false if the rowset doesn't contain data.