- Always define a primary key
- Use auto-incrementing integers for most tables
- Use UUIDs for distributed systems
- Name PK fields consistently:
idor{table}_id
Table Management
ChartDB provides intuitive tools for creating and managing database tables directly on the canvas.Creating Tables
Using the Context Menu
The quickest way to create a table:Select 'New Table'
Click New Table from the menu. A new table will be created at the clicked position.
ChartDB automatically assigns tables to the appropriate schema based on your database type. For PostgreSQL, new tables use the
public schema by default. For MySQL, the default database schema is used.Table Position
Tables are positioned at the exact point where you right-clicked. You can:- Drag tables to reposition them
- Use the auto-layout feature to organize tables automatically
- Snap tables to grid (if enabled)
Table Edit Mode
Double-click on any table or click the Edit option from the table context menu to enter edit mode.Editing Table Properties
Table Name
Table Name
- Click on the table name at the top
- Type the new name
- Press Enter to save
- Use lowercase with underscores (snake_case):
user_profiles - Use plural nouns:
orders,customers - Avoid special characters and spaces
Schema Assignment
Schema Assignment
For databases that support schemas (PostgreSQL, SQL Server):
- Select the schema from the dropdown
- Create new schemas if needed
- Leave empty for default schema
Table Color
Table Color
Customize table appearance:
- Click the color picker
- Choose from preset colors
- Colors help visually group related tables
#b067e9(Purple)#ff6b8a(Pink)#4dee8a(Green)#ffe374(Yellow)#7175fa(Blue)#42e0c0(Teal)#ff6363(Red)#8a61f5(Violet)#b0b0b0(Gray - for views)
Table Type
Table Type
Toggle between regular table and view:
- Regular tables: Standard database tables
- Views: Database views (rendered in gray)
- Materialized Views: For supported databases
Comments
Comments
Add documentation to your tables:
- Click the comments field
- Enter descriptive text about the table’s purpose
- Comments are included in SQL exports
Managing Fields
Adding Fields
While in edit mode:Field Properties
The field name. Use snake_case naming convention:
user_idcreated_atemail_address
The data type. Available types depend on your database:Common Types:
INT,BIGINT,SMALLINT(integers)VARCHAR(n),TEXT(strings)DECIMAL(p,s),NUMERIC(decimals)DATE,TIMESTAMP,DATETIME(temporal)BOOLEAN(true/false)JSON,JSONB(PostgreSQL)UUID(PostgreSQL)ENUM(MySQL, PostgreSQL)
Mark this field as part of the primary key. Multiple fields can be selected for composite primary keys.
Enforce unique values for this field across all rows.
Allow NULL values. Uncheck to make the field NOT NULL.
Enable auto-increment for integer fields (AUTO_INCREMENT in MySQL, SERIAL in PostgreSQL).
For PostgreSQL: mark field as an array type (e.g.,
INTEGER[]).For VARCHAR and CHAR types, specify the maximum length:
VARCHAR(255)CHAR(4)
For DECIMAL/NUMERIC types, the total number of digits:
DECIMAL(10, 2)- precision is 10
For DECIMAL/NUMERIC types, the number of decimal places:
DECIMAL(10, 2)- scale is 2
Default value for the field:
'active'(string)0(number)CURRENT_TIMESTAMP(function)NULL
Character collation for string fields:
utf8mb4_general_ci(MySQL)en_US.UTF-8(PostgreSQL)
Field-level documentation and comments.
Check constraint expression:
age >= 0status IN ('active', 'inactive')
Field Toggles
Quick toggles for common field attributes:PK
Primary KeyToggle primary key status
U
UniqueToggle unique constraint
NN
Not NullToggle nullable status
Reordering Fields
Fields can be reordered by:- Clicking and dragging the field handle (⋮)
- Moving fields up or down in the list
- The order affects both display and SQL export
Deleting Fields
To delete a field:- Hover over the field in edit mode
- Click the delete (trash) icon
- Confirm the deletion
Table Context Menu
Right-click on a table (outside edit mode) to access:Duplicate Table
Creates a copy of the table:
- Appends
_copyto the table name - Copies all fields and their properties
- Positions the copy slightly offset from the original
- Does NOT copy relationships
Add Relationship
Starts relationship creation mode with this table as the source. Click on another table to complete the relationship.
Indexes
Manage table indexes for performance optimization:Creating Indexes
Primary Key Indexes
Primary key fields automatically create a PRIMARY index:Check Constraints
Add validation rules to your tables:Creating Check Constraints
Table Width
Tables can be resized to accommodate long field names:- Minimum width: 224px
- Medium width: 337px
- Maximum width: 450px
Expanding/Collapsing Tables
Tables with many fields can be collapsed to save canvas space:- Tables show up to 10 fields when collapsed
- Click Show more to expand and see all fields
- Click Show less to collapse
- The
expandedproperty is saved with your diagram
Working with Views
Creating Database Views
Views are virtual tables based on queries:Views in ChartDB represent the structure of the view’s output, not the underlying query. For SQL export, views are exported as
CREATE VIEW statements.Best Practices
Naming Conventions
Naming Conventions
Tables:
- Use plural nouns:
users,orders,products - Snake_case:
user_profiles,order_items
- Snake_case:
first_name,created_at - Use
_idsuffix for foreign keys:user_id,product_id - Use
_atsuffix for timestamps:created_at,updated_at
Primary Keys
Primary Keys
Data Types
Data Types
- Use appropriate sizes:
SMALLINTfor small numbers,BIGINTfor large - Use
VARCHAR(n)with realistic limits, notVARCHAR(255)everywhere - Use
TEXTfor unlimited length strings - Use
DECIMALfor currency, notFLOAT
Constraints
Constraints
- Mark fields as NOT NULL when appropriate
- Use UNIQUE constraints for email, username, etc.
- Add check constraints for business rules
- Document constraints with comments
Comments
Comments
Add comments to:
- Tables explaining their purpose
- Complex fields requiring clarification
- Business rules and constraints
- Data retention policies
Common Patterns
Timestamps Pattern
Soft Delete Pattern
UUID Primary Key Pattern
Next Steps
Managing Relationships
Connect tables with foreign key relationships
Keyboard Shortcuts
Speed up your workflow with shortcuts
Using Areas
Organize tables into logical groups
Adding Notes
Document your schema with notes
