> For the complete documentation index, see [llms.txt](https://tester-ai.gitbook.io/en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tester-ai.gitbook.io/en/12.-developers-mistakes/8.-misunderstanding-the-relationship-between-code-and-data.md).

# 8. Misunderstanding the Relationship between Code and Data

One of the most critical aspects of programming is data management. A program serves as an interface for adding, editing, and deleting records. Even a small bug in the code can have a significant impact on the data, especially if validation is only done on the side of the program with the bug. New programmers may not notice the problem right away if a data bug affects a secondary functionality. This error can multiply programmatically for a long time before being detected.

What's worse is that fixing the code without fixing the data already created by the code can increase errors in the data to the point of no recovery. So, how do you protect yourself against this? You can use several levels of validation, including frontend, backend, transfer, and database. At a minimum, use built-in constraints in the database.

It's essential to know all types of constraints in the database and use them when creating new columns and tables. For instance,

**NOT NULL** places a constraint on a column so that it does not accept empty values. This is mandatory if your application assumes this value exists.

**UNIQUE** he uniqueness of a column value across the table, making it ideal for storing a user's login or email.

**CHECK** checks for an arbitrary expression, such as percentages, where you should check for an occurrence between 0 and 100.

**PRIMARY KEY** implies both uniqueness and a non-empty value, and every database table must have such a field to identify records.&#x20;

**FOREIGN KEY** tells you that the values in that column are contained in another table.

Another problem for beginners is that they can't think in transaction categories. If several operations change the same data source on which they all depend, they should be wrapped in a transaction that will be canceled if one of the operations produces an error.


---

# 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:

```
GET https://tester-ai.gitbook.io/en/12.-developers-mistakes/8.-misunderstanding-the-relationship-between-code-and-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
