> For the complete documentation index, see [llms.txt](https://docs.os.uk/os-downloads/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.os.uk/os-downloads/products/addresses-and-names-portfolio/addressbase/addressbase-getting-started-guide/working-with-cou-data.md).

# Working with COU data

All the AddressBase products are available as a full supply or a COU. A COU means you will only be supplied with the features which have changed since your last supply. The following sections provide guidance on how you could potentially manage a COU supply of AddressBase and AddressBase Plus data.

{% hint style="info" %}
If you receive a tile supply, you will receive Change Chunks. This means if a record within your tile has changed, all of the records in that tile will be provided to you as inserts, and no updates or deletes will be issued.
{% endhint %}

{% hint style="info" %}
Tiles are only available for GB supplies, so this does not apply to AddressBase Plus Islands.
{% endhint %}

## Types of change <a href="#bookmark39" id="bookmark39"></a>

At a high-level, there are three types of change found within a COU:

* Deletes (CHANGE\_TYPE ‘D’) are objects that have ceased to exist in your AOI since the last product refresh.
* Inserts (CHANGE\_TYPE ‘I’) are objects that have been newly inserted into your AOI since the last product refresh.
* Updates (CHANGE\_TYPE ‘U’) are objects that have been updated in your AOI since the last product refresh.

## High-level COU implementation model <a href="#bookmark40" id="bookmark40"></a>

The diagram below shows how to implement an AddressBase, AddressBase Plus and AddressBase Plus Islands COU within a database.

<figure><img src="/files/Aot50YpiBtuGxX3YdxCI" alt="High-level COU implementation model"><figcaption><p>High-level COU implementation model</p></figcaption></figure>

## High-level COU implementation model – with archiving <a href="#bookmark41" id="bookmark41"></a>

Before a COU is applied, there may be a business requirement to archive existing address records. The table below shows how to implement archiving with an AddressBase COU within a database.

<figure><img src="/files/W6FrfrUpsBkQsZxHSmyw" alt="High-level COU implementation model on how to create archive tables and apply a COU"><figcaption><p><em>High-level COU implementation model on how to create archive tables and apply a COU</em></p></figcaption></figure>

## Applying COU to tables <a href="#bookmark42" id="bookmark42"></a>

Within AddressBase and AddressBase Plus there will be no records with the same UPRN. This can be tested by checking the number of records that have the same UPRN. The following SQL code would notify you of any duplicates:

```sql
SELECT uprn, COUNT(uprn) AS NumOccurrences FROM addressbase_plus
GROUP BY uprn
HAVING ( COUNT(uprn) > 1 );
```

This query should return 0 rows, and this confirms that there are no duplicates. As there are no duplicate records, we can use the UPRN to apply the COU.

Once confirmed, the following steps can be taken to apply the COU (without archiving):

Initially delete the existing records that will be updated and deleted:

{% code overflow="wrap" %}

```sql
DELETE FROM addressbaseplus WHERE uprn IN (SELECT uprn FROM addressbaseplus_cou WHERE change_type != 'I');
```

{% endcode %}

Insert the new updated records and the new inserted records:

{% code overflow="wrap" %}

```sql
INSERT INTO addressbaseplus SELECT * FROM addressbaseplus _cou WHERE change_type != 'D';
```

{% endcode %}

Where there is a business requirement to keep the records that are being Updated and Deleted in a separate archive table, the following SQL will create an Archive Table. It will populate with records that are being Updated and Deleted from the live AddressBase or AddressBase Plus table.

The following command creates an archive table of the records that are being updated and deleted from the existing table.

If this table already exists, you can simply use INSERT INTO rather than CREATE TABLE.

{% code overflow="wrap" %}

```sql
CREATE TABLE addressbaseplus_archive AS SELECT * FROM addressbaseplus
WHERE uprn IN (SELECT uprn FROM addressbaseplus_cou WHERE change_type != 'I');
```

{% endcode %}

The following command then deletes the records from the existing table, which are either updates or deletions:

{% code overflow="wrap" %}

```sql
DELETE FROM addressbaseplus
WHERE uprn IN (SELECT uprn FROM addressbaseplus_cou WHERE change_type!= 'I');
```

{% endcode %}

The following command then inserts the new insert records and the new updated records into the live table:

{% code overflow="wrap" %}

```sql
INSERT INTO addressbaseplus SELECT * FROM addressbaseplus_cou WHERE change_type != 'D';
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.os.uk/os-downloads/products/addresses-and-names-portfolio/addressbase/addressbase-getting-started-guide/working-with-cou-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
