> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chartdb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Adding Tables and Fields

> Learn how to add and manage tables and fields in ChartDB to visualize your database schema effectively.

<Frame>
  <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/tables.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=1367352e8debf5bdc2b5b565393c5ede" width="2880" height="1532" data-path="docs/images/tables.png" />
</Frame>

ChartDB provides a visual and intuitive way to add tables and fields to your database diagram.

## Add New Tables

To add new tables, you can use the sidebar or interact directly with the canvas.

<Steps>
  <Step title="Click the 'Add Table' icon in the Sidebar" icon="plus">
    First, **navigate to the *Tables* section** in the ChartDB sidebar and click the 'Add Table' icon.
    This instantly creates a new table in your diagram with a randomly generated name and a single default field.

    <Frame>
      <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/add-new-table.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=3bbcac31af91a2156b94b4f16d3f6c75" width="2868" height="630" data-path="docs/images/add-new-table.png" />
    </Frame>
  </Step>

  <Step title="Duplicate Existing Table via Sidebar" icon="clone">
    1. **Access table actions** by clicking the settings icon <Icon icon="ellipsis-vertical" iconType="solid" size={16} /> next to the table name in the sidebar.
    2. **Select 'Duplicate Table'** from the table actions menu.

           <Frame>
             <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/table-actions.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=0757a99720783a4ce345d11d82adb95e" width="590" height="574" data-path="docs/images/table-actions.png" />
           </Frame>
  </Step>

  <Step title="Duplicate or Add Table via Right-Click on Canvas" icon="computer-mouse">
    You can also quickly add or duplicate tables directly on the canvas using the right-click context menu.

    1. **Right-click anywhere on the canvas.**
    2. **Select 'New Table'** to add a brand new table, or **'Duplicate Table'** after selecting an existing table to clone it.

    <Frame>
      <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/new-table-new-relationship.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=2b7e8def6f9f62a64c3a5e0721e5607d" width="1348" height="954" data-path="docs/images/new-table-new-relationship.png" />
    </Frame>
  </Step>
</Steps>

You can also **edit table names directly on the canvas** by double-clicking the table name. This provides a quick and intuitive way to rename tables as you are visualizing your diagram.

## Managing Schemas

In ChartDB, tables are organized within **Schemas**. Schemas act like folders, providing a way to structure and group your tables, especially in databases like PostgreSQL and MSSQL that support them.

<Frame caption="A diagram with multiple schemas">
  <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/schemas.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=539958d99f45d8616b6452f6fba4c8de" width="952" height="620" data-path="docs/images/schemas.png" />
</Frame>

Schemas will only be displayed in the sidebar if your imported database is configured with schemas.
By default, only the `public` schema is displayed when schemas are present in your database.
New tables added using the **Add Table** functionality will be placed within the currently active schema, which defaults to the `public` schema if not otherwise specified.

## Add New Fields

Whether you're refining your schema or adding new attributes, here’s how to add fields to your tables in ChartDB.

<Steps>
  <Step title="Click the 'Add Field' Button" icon="square-plus">
    1. **Scroll to the bottom** of the specific table's details section in the
       sidebar. 2. **Click the 'Add Field' button**.
  </Step>

  <Step title="Click the Fields section '+' Icon" icon="plus">
    1. **Expand the 'Fields' section** for the specific table in the sidebar.
    2. **Click the '+' icon** next to the 'Fields' header.

           <Frame>
             <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/add-new-field.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=b98e60d057339aa20029b7630ee595bb" width="680" height="534" data-path="docs/images/add-new-field.png" />
           </Frame>
  </Step>
</Steps>

Similar to tables, you can **edit field names directly on the canvas** by double-clicking the field name within a table. This allows for in-place editing of field names directly in your diagram.

This will instantly add a new field to your selected table with a default name (e.g., `field_4`) and a default data type.

## Configure Field Attributes

Once you've added a new field or need to modify an existing one, ChartDB provides configurable field attributes.

<AccordionGroup>
  <Accordion title="Field Name" icon="i-cursor">
    To rename a field, simply click on the current field name in the sidebar and type in the new desired name.
  </Accordion>

  <Accordion title="Data Type" icon="bars">
    To change a field's data type, click the dropdown menu next to the current data type. This will display a list of available data types supported by your imported database.

    <Frame>
      <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/field-types.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=379bfece6ceb03435e3fde7f8e914cd6" width="642" height="748" data-path="docs/images/field-types.png" />
    </Frame>

    <Note>
      Available data types are determined by the database you imported into ChartDB.
    </Note>
  </Accordion>

  <Accordion title="Nullability" icon="n">
    By default, new fields are often set as nullable. To toggle a field's
    nullability, click the 'N' icon next to the field.
  </Accordion>

  <Accordion title="Primary Key" icon="key">
    To designate a field as a primary key, click the 'P' icon next to the field.
  </Accordion>

  <Accordion title="Unique Constraint and Comments" icon="comment-dots">
    Click the three dots icon <Icon icon="ellipsis" iconType="solid" size={16} /> next to the field to access additional attributes. Check the 'Unique' checkbox to enforce a unique constraint. Use the 'Comments' text area to add field-level comments.

    <Frame>
      <img src="https://mintcdn.com/buckledev/Nk8pE0k5UNFAdU1u/docs/images/field-attributes.png?fit=max&auto=format&n=Nk8pE0k5UNFAdU1u&q=85&s=70a086febb5ee5444c9b6b694ab84dfe" width="482" height="596" data-path="docs/images/field-attributes.png" />
    </Frame>

    <Note>
      Field-level comments are distinct from table-level comments, which can be added in the table's top-level settings.
    </Note>
  </Accordion>
</AccordionGroup>
