Overview
The DDL import system uses sophisticated SQL parsing to extract:- Table definitions
- Column types and constraints
- Primary keys and foreign keys
- Indexes (including composite indexes)
- Check constraints
- Default values
- Comments
- Views
- Enum types
- Alter table statements
Supported SQL Dialects
ChartDB includes specialized parsers for different SQL dialects:PostgreSQL
Full PostgreSQL syntax including arrays, custom types, and extensions
MySQL
MySQL and MariaDB with engine specifications and charset
SQL Server
T-SQL syntax with SQL Server-specific features
Oracle
Oracle PL/SQL DDL statements
SQLite
SQLite syntax with virtual tables and triggers
Generic SQL
Standard SQL for other databases
PostgreSQL DDL Import
ChartDB’s PostgreSQL parser is the most comprehensive, supporting advanced PostgreSQL features.Basic Table Import
Advanced PostgreSQL Features
- Array Types
- Custom Types & Enums
- Check Constraints
- Composite Keys
- Index Types
- Schemas
PostgreSQL array types are fully supported:Arrays are imported with
isArray: true attribute.ALTER TABLE Support
PostgreSQL ALTER TABLE statements are fully parsed:MySQL DDL Import
MySQL syntax is fully supported with dialect-specific features:MySQL-Specific Features
Storage Engines
Storage Engines
Engine specifications are recognized:
Character Sets
Character Sets
Charset and collation settings:
Auto Increment
Auto Increment
AUTO_INCREMENT columns are marked with
increment: true:Backtick Quoting
Backtick Quoting
MySQL backtick identifiers are properly handled:
SQL Server DDL Import
T-SQL syntax with SQL Server-specific features:T-SQL Features
IDENTITY(seed, increment)columnsNVARCHARandNCHARUnicode types- Bracketed identifiers
[table_name] GETDATE(),NEWID()functionsDATETIME2,DATETIMEOFFSETtypes
Oracle DDL Import
Oracle PL/SQL DDL statements:Oracle-Specific Features
VARCHAR2andNUMBERtypesSEQUENCESfor auto-incrementSYSDATEand other Oracle functions- PL/SQL block syntax handling
Preprocessing and Cleanup
The DDL importer includes sophisticated preprocessing:Statement Splitting
SQL is split into individual statements by semicolons, accounting for:
- Quoted strings
- Function bodies ($$, )
- Nested blocks
Foreign Key Parsing
Foreign keys are extracted from multiple sources:- Inline Constraints
- Table-Level Constraints
- Named Constraints
- ALTER TABLE
View Support
Views are imported as special tables:isView: true and positioned separately on the canvas.
Complex Import Example
Error Handling and Validation
The DDL parser includes robust error handling:Syntax Error Recovery
Syntax Error Recovery
If a statement fails to parse, the error is logged but other statements continue processing.
Type Mapping
Type Mapping
Unknown data types are preserved as-is and can be edited in the diagram editor.
Constraint Validation
Constraint Validation
Check constraint expressions are validated before import:
Circular Dependencies
Circular Dependencies
Foreign key cycles are detected and handled gracefully.
Best Practices
Import Performance
The DDL parser is optimized for large schemas:| Schema Size | Parse Time | Notes |
|---|---|---|
| < 10 tables | < 100ms | Instant |
| 10-50 tables | 100-500ms | Fast |
| 50-200 tables | 0.5-2s | Good |
| 200+ tables | 2-5s | Acceptable |
Troubleshooting
Foreign Keys Not Detected
Foreign Keys Not Detected
Ensure referenced tables are defined before the referencing table, or use ALTER TABLE statements after all tables are created.
Indexes Missing
Indexes Missing
Make sure CREATE INDEX statements come after the table definitions.
Types Not Recognized
Types Not Recognized
Custom types must be defined before they’re used in table definitions. Use CREATE TYPE statements.
Parser Fails
Parser Fails
Check for syntax errors in your DDL. Try importing smaller sections to isolate problematic statements.
Next Steps
DBML Import
Learn about DBML format
Export Options
Export your diagram to different formats
