- Schema and table names
- Column names (supports composite keys)
- Primary key definitions from
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
Database Editions
ChartDB supports multiple SQL Server versions:- SQL Server 2017+: Modern query using
STRING_AGGfor better performance - SQL Server 2016 and below: Compatible query using
STUFFandFOR XML PATH
Smart Query Import
The SQL Server Smart Query extracts complete schema metadata using JSON functions and system catalogs.SQL Server 2017+ Query
For SQL Server 2016 and below, ChartDB uses
STUFF with FOR XML PATH instead of STRING_AGG.What the Smart Query Retrieves
Foreign Keys (fk_info)
Foreign Keys (fk_info)
- Schema and table names (from
sys.schemas,sys.tables) - Column names
- Foreign key constraint names
- Referenced schema, table, and column
- Delete and update referential actions (CASCADE, SET NULL, SET DEFAULT, NO ACTION)
- Full FK definition using
delete_referential_action_descandupdate_referential_action_desc
Primary Keys (pk_info)
Primary Keys (pk_info)
Columns (cols)
Columns (cols)
- Data types (normalized to lowercase)
- Character maximum length (including VARCHAR(MAX) as -1)
- Numeric precision and scale
- Ordinal position
- Nullable constraints
- Default values (with proper escaping)
- Collation names
- Identity column detection using
COLUMNPROPERTY()
Indexes (indexes)
Indexes (indexes)
- Index names and types (CLUSTERED, NONCLUSTERED, XML, SPATIAL)
- Indexed columns
- Unique constraint flags
- Sort direction (ASC/DESC) via
is_descending_key - Column position in composite indexes
Tables (tbls)
Tables (tbls)
- Schema and table names
- Row counts (from
sys.partitions) - Table type (USER_TABLE, VIEW)
- Creation date
Check Constraints
Check Constraints
- Schema and table names
- Constraint expressions from
sys.check_constraints
SQL Export
Export your ChartDB diagrams to production-ready T-SQL scripts.Export Features
- Schema Creation: IF NOT EXISTS checks with dynamic SQL
- Data Type Support:
- NVARCHAR, VARCHAR with MAX support
- DECIMAL, NUMERIC with precision/scale
- DATETIME2, DATETIME
- VARBINARY(MAX) for large binary data
- BIT for boolean values
- Identity Columns: IDENTITY(1,1) for auto-increment
- Constraints:
- Primary keys as table constraints
- Foreign keys with referential actions
- Check constraints
- Unique constraints
- Indexes:
- Separate CREATE INDEX statements
- Support for up to 32 columns (SQL Server limit)
- Warning comments for truncated indexes
- Bracket Quoting: Proper [identifier] quoting for reserved words
- Default Values: Special handling for SQL Server syntax:
((0))→0(N'value')→N'value'(getdate())→getdate()
Export Example
SQL Server-Specific Features
Identity Columns
SQL Server uses IDENTITY for auto-increment:- Detects identity columns via
COLUMNPROPERTY() - Adds IDENTITY(1,1) to appropriate columns on export
- Removes default values when IDENTITY is present
VARCHAR(MAX) and NVARCHAR(MAX)
SQL Server supports MAX length for variable-length types:Multi-Schema Support
SQL Server has full schema support:dbo if not specified.
Referential Actions
Supported ON DELETE/ON UPDATE actions:- NO ACTION (default)
- CASCADE
- SET NULL
- SET DEFAULT
Index Limitations
SQL Server limits:- Maximum 32 columns per index
- Maximum 900 bytes for clustered index key size
- Maximum 1700 bytes for non-clustered index key size
Best Practices
Troubleshooting
Permission denied errors
Permission denied errors
Ensure your database user has SELECT permissions on:
sys.foreign_keyssys.tablessys.columnssys.schemassys.indexessys.check_constraintsINFORMATION_SCHEMA.COLUMNSINFORMATION_SCHEMA.KEY_COLUMN_USAGE
STRING_AGG not recognized
STRING_AGG not recognized
You’re using SQL Server 2016 or below. ChartDB automatically uses the compatible query with STUFF and FOR XML PATH.
Index creation fails
Index creation fails
Check if you’re exceeding SQL Server’s index limits:
- 32 columns maximum
- 900 bytes for clustered index keys
- 1700 bytes for non-clustered index keys
Schema creation fails
Schema creation fails
Ensure you have CREATE SCHEMA permission. ChartDB uses dynamic SQL with EXEC for schema creation.
