# Database Tables

## Overview

The App Database stores data in Tables. A Database Table is like a spreadsheet. It's a collection of data about a specific topic, such as Customers, Products, etc.

{% embed url="<https://youtu.be/3h_bRxORBlY>" %}
Video: Database Features
{% endembed %}

***

## Table Fields

A Database Table is made up of smaller categories of data called fields (also known as a *Column* or *Attribute*).&#x20;

e.g. A Database Table about customers might have fields such as: *CustomerID*, *First Name*, *Last Name*, *Phone Number*, *Email Address* and *Notes*.

<div align="left"><figure><img src="/files/HwMDdhAyZaoNjUPonlOI" alt="" width="563"><figcaption><p>Example Database Table about Customers</p></figcaption></figure></div>

### Field Types

Fields are defined by specifying it's name and the type of data you want it to contain. The table below lists the supported field types:

<table><thead><tr><th width="139">Type</th><th width="124">Sub-Type</th><th>Description</th></tr></thead><tbody><tr><td>Text</td><td>Allow any text</td><td>Simple text</td></tr><tr><td></td><td>Multi-line</td><td>Simple text spanning multiple lines</td></tr><tr><td></td><td>Multi-line HTML</td><td>Formatted text spanning multiple lines</td></tr><tr><td></td><td>Email</td><td>Email addresses</td></tr><tr><td></td><td>Phone</td><td>Phone Numbers</td></tr><tr><td></td><td>Password</td><td>Passwords with encryption</td></tr><tr><td></td><td>List of Values</td><td>Allows only a Pre-defined set of simple text</td></tr><tr><td></td><td>Files</td><td>Used for uploading and associating files. This field will store information about the files.</td></tr><tr><td>Numeric</td><td>-</td><td>Integer numbers within the approx. range -2 million to +2 million (32-bit signed)</td></tr><tr><td>Numeric (decimals)</td><td>-</td><td>Real numbers within the range (64-bit double precision)</td></tr><tr><td>Date/Time</td><td>-</td><td>A timestamp containing the date and time.</td></tr><tr><td>Yes/No</td><td>-</td><td>Boolean values like true or false, yes or no, on or off, etc</td></tr><tr><td>Large Numeric</td><td>-</td><td>Integer numbers (64-bit signed)</td></tr></tbody></table>

### Unique Fields

A Database Table can have a single or a group of fields marked as unique.&#x20;

In the case of a single field being marked as unique, no two rows can have the same value for this field.

In case of a group of fields, the combination of values across these fields must be unique for each record in the table.

***

### ID Field

Every Database Table in Zingy gets an automatically assigned ID field. The value of this ID field is automatically generated and is guaranteed to be unique across all the records in the specific table.

***

## Table Records

Database Tables store data in the form of records. A record (also called a *Row* or *Tuple*) is an individual entry in the table.&#x20;

For example, in the Database Table about customers, each record would contain specific information about one customer which is the data of the fields: *CustomerID*, *First Name*, *Last Name*, *Phone Number*, *Email Address* and *Notes* .

<figure><img src="/files/I4ZpDp8PtySUHoewwZGn" alt=""><figcaption><p>Example records for the Customers table</p></figcaption></figure>

The above image shows a record selected in the *Customers* Database Table. The record is for the customer named *Max Mustermann*.&#x20;

***

## Creating a Database Table

In the App Editor, go to the **`Data`** tab and use the :heavy\_plus\_sign:**`New Table`** icon to add a new Database Table to your App.&#x20;

<figure><img src="/files/JYEgjVfIJiRq82qEgmWy" alt=""><figcaption><p>New Table icon</p></figcaption></figure>

In the screen that follows, you simply provide the name of the table (unique to your app) and add one or more fields by using the **`Add Field`** button.

<div><figure><img src="/files/uL1OuBbJbzuOzWZUzoVJ" alt=""><figcaption><p>Table Name when creating a table</p></figcaption></figure> <figure><img src="/files/hIv6ZWqsq7nRsJyqi4FL" alt=""><figcaption><p>Add Field button</p></figcaption></figure></div>

The image below shows the information required for adding a field to the table.

<div align="left"><figure><img src="/files/jbM9qGWBiBJZzYKAo1jy" alt="" width="563"><figcaption><p>Information required for each Field</p></figcaption></figure></div>

<table data-header-hidden><thead><tr><th width="141"></th><th></th></tr></thead><tbody><tr><td>Field Title</td><td>The general name for the field e.g. <em>Address Line 1</em>.</td></tr><tr><td>Type and Sub-Type</td><td>The type of data for the field. See <a href="#field-types">here</a> for more details.</td></tr><tr><td>Field ID</td><td>The Field ID gets automatically derived from the Field Title and is used internally to refer to the field.</td></tr><tr><td>Unique</td><td>Enable if no two rows can have the same value for this field. See <a href="#unique-fields">here</a> for more details.</td></tr><tr><td>Description</td><td>Optional text describing the field.</td></tr><tr><td>Values</td><td>For the List of Values sub-type for Text type fields, this contains a comma-separated text for the allowed values.</td></tr></tbody></table>

The the fields you want have been added click the **`Save Table`** button to create the table.

***

## Modifying a Table

{% hint style="danger" %}
Altering the structure of a table is irreversible and can be time-consuming, especially if the table already contains data.

We advise against making such changes unless absolutely necessary.
{% endhint %}

If you need to modify a table's structure e.g. to add new fields or remove fields, click on the table and select the **`Edit`** option from the popup menu.

<div align="left"><figure><img src="/files/4qbcZb7AvJQVuPsP80cb" alt="" width="339"><figcaption><p>Table menu: Edit option</p></figcaption></figure></div>

The image below shows an annotated example of the screen that shows for editing a Database Table.

<div align="left"><figure><img src="/files/WEae9xIIktPhLnxobnDs" alt="" width="563"><figcaption><p>Database Table edit screen showing the field edit button <mark style="color:red;"><strong>(1)</strong></mark>, field delete button <mark style="color:red;"><strong>(2)</strong></mark>, add field button <mark style="color:red;"><strong>(3)</strong></mark> and the Save table button <mark style="color:red;"><strong>(4)</strong></mark>.</p></figcaption></figure></div>

The table below explains the annotations in the image above.

<table data-header-hidden><thead><tr><th width="113"></th><th></th></tr></thead><tbody><tr><td><img src="/files/IoqOnKkO7xcjCNUgjg3r" alt=""></td><td>Edit a field's title, type, sub-type, etc. If the table contains data, any field type changes will result in the existing data being converted to the new field type. This maybe a lengthy process depending on the amount of records in the table.</td></tr><tr><td><img src="/files/pfbow9yA1VbS0O1XVab6" alt=""></td><td>Delete a field from the table. If the table contains data, this will result in the field being removed from all exiting records.This maybe a lengthy process depending on the amount of records in the table.</td></tr><tr><td><img src="/files/KstAGTj98WDlZ2sTlEjr" alt="" data-size="original"></td><td>Add a new field to the table. If the table contains data, this will result in the new field being added to all existing records and initialized with a default value depending on the type of the field. This maybe a lengthy process depending on the amount of records in the table.</td></tr><tr><td><img src="/files/XPIMOwaDRvyyDZgUEdIQ" alt=""></td><td>Save the changes and start the conversion process.</td></tr></tbody></table>

***

## Deleting a Table

{% hint style="danger" %}
Database Table delete is permanent and not reversible.
{% endhint %}

To delete a Database Table and it's data, click on the table and select the **`Delete`** option from the popup menu.

<div align="left"><figure><img src="/files/uqpPWOs4nG9oAN0XaVpn" alt="" width="303"><figcaption><p>Table menu: Delete option</p></figcaption></figure></div>

***

## Access (Security) Rules

To configure role based access for a Database Table, click on the table and select the **`Access (Security)`** option from the popup menu.

<div align="left"><figure><img src="/files/iv6PRSb8FKTb6VPyRjO1" alt="" width="365"><figcaption><p>Table menu: Access (Security) option</p></figcaption></figure></div>

Access rules can be configured for 4 types of operations (*View*, *Add*, *Modify* and *Delete*) as shown below:

<table><thead><tr><th width="138">Operation</th><th>Description</th></tr></thead><tbody><tr><td>View</td><td>Listing records, looking up records, etc</td></tr><tr><td>Add</td><td>Creating or adding new records</td></tr><tr><td>Modify</td><td>Editing records (NOTE: this also requires View permission)</td></tr><tr><td>Delete</td><td>Deleting records</td></tr></tbody></table>

<div align="left"><figure><img src="/files/WutZHvbXP72A4ZzYsYFJ" alt="" width="563"><figcaption><p>Table operation Access rules edit button</p></figcaption></figure></div>

By default all registered [Users](/app-editor/app-users.md) of the app and members of the Admin [group](/app-editor/app-user-groups.md) are allowed on the four operations (*View*/*Add*/*Modify*/*Delete*). You can change this by clicking on any of the **`Edit`** buttons highlighted in the image above.

<figure><img src="/files/ZGj73kzVKmAhHiAQpBf9" alt=""><figcaption><p>Access Rules modification showing group selection <mark style="color:red;"><strong>(1)</strong></mark>, role selection <mark style="color:red;"><strong>(2)</strong></mark>, group add button <mark style="color:red;"><strong>(3)</strong></mark> and the group delete icon <mark style="color:red;"><strong>(4)</strong></mark>.</p></figcaption></figure>

* To allow a [group](/app-editor/app-user-groups.md), select it <mark style="color:red;">**(1)**</mark>, choose the minimum role level <mark style="color:red;">**(2)**</mark> and click on the Add button <mark style="color:red;">**(3)**</mark>.&#x20;
* To grant public access to an operation, select the "Public" group.
* To remove a group click on the 'x' icon <mark style="color:red;">**(4)**</mark>. Note: The "Admin" group cannot be removed.


---

# Agent Instructions: 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://docs.zingy.ai/app-editor/data/database-tables.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.
