Database Introspection
Introspect database metadata to discover tables, columns, indexes, procedures, and more
The bx:dbInfo component allows you to introspect database metadata, providing detailed information about database structures, schemas, tables, columns, indexes, foreign keys, stored procedures, and version information. This is essential for dynamic database operations, schema discovery, and database management tools.
📋 Overview
Database introspection in BoxLang enables you to:
Discover Schemas - List all databases and schemas in a connection
List Tables - Retrieve all tables, views, and system tables
Inspect Columns - Get detailed column metadata including types, constraints, and keys
Analyze Indexes - View index information for performance optimization
Map Foreign Keys - Discover relationships between tables
Find Procedures - List available stored procedures
Check Versions - Retrieve database and JDBC driver version information
🔧 Basic Usage
The bx:dbInfo component requires two attributes:
type- The type of metadata to retrievename- The variable name to store results
bx:dbInfo
type="tables"
name="tableList"
datasource="myDB";
writeDump( tableList );📊 Metadata Types
Database Names (DBNAMES)
List all databases and schemas accessible through the connection:
Result Columns:
DBNAME- Database or schema nameTYPE- Either "CATALOG" or "SCHEMA"
Tables
Retrieve information about tables in the database:
Result Columns:
TABLE_CAT- Table catalog (may be null)TABLE_SCHEM- Table schema (may be null)TABLE_NAME- Table nameTABLE_TYPE- Table type (TABLE, VIEW, SYSTEM TABLE, etc.)REMARKS- Explanatory comment on the tablePlus additional database-specific columns
Common Filter Values:
TABLE- Regular tables (default)VIEW- Database viewsSYSTEM TABLE- System tablesGLOBAL TEMPORARY- Global temporary tablesLOCAL TEMPORARY- Local temporary tablesALIAS- Table aliasesSYNONYM- Table synonyms
Columns
Get detailed information about columns in a table:
Result Columns:
TABLE_CAT- Table catalogTABLE_SCHEM- Table schemaTABLE_NAME- Table nameCOLUMN_NAME- Column nameDATA_TYPE- SQL data type from java.sql.TypesTYPE_NAME- Data source dependent type nameCOLUMN_SIZE- Column sizeDECIMAL_DIGITS- Decimal digits (for numeric types)IS_NULLABLE- "YES", "NO", or ""COLUMN_DEF- Default valueIS_PRIMARYKEY- Boolean, true if primary keyIS_FOREIGNKEY- Boolean, true if foreign keyREFERENCED_PRIMARYKEY- Referenced column name (if foreign key)REFERENCED_PRIMARYKEY_TABLE- Referenced table name (if foreign key)Plus additional database-specific columns
Foreign Keys
Discover foreign key relationships for a table:
Result Columns:
PKTABLE_CAT- Primary key table catalogPKTABLE_SCHEM- Primary key table schemaPKTABLE_NAME- Primary key table namePKCOLUMN_NAME- Primary key column nameFKTABLE_CAT- Foreign key table catalogFKTABLE_SCHEM- Foreign key table schemaFKTABLE_NAME- Foreign key table nameFKCOLUMN_NAME- Foreign key column nameKEY_SEQ- Sequence number within foreign keyUPDATE_RULE- What happens on UPDATEDELETE_RULE- What happens on DELETEFK_NAME- Foreign key namePK_NAME- Primary key nameDEFERRABILITY- Can evaluation be deferred until commit
Indexes
Retrieve index information for a table:
Result Columns:
TABLE_CAT- Table catalogTABLE_SCHEM- Table schemaTABLE_NAME- Table nameNON_UNIQUE- Boolean, false if index values must be uniqueINDEX_QUALIFIER- Index catalogINDEX_NAME- Index nameTYPE- Index type (tableIndexStatistic, tableIndexClustered, etc.)ORDINAL_POSITION- Column sequence within indexCOLUMN_NAME- Column nameASC_OR_DESC- "A" for ascending, "D" for descendingCARDINALITY- Number of unique values in indexPAGES- Number of pages used for indexFILTER_CONDITION- Filter condition, if any
Stored Procedures
List stored procedures available in the database:
Result Columns:
PROCEDURE_CAT- Procedure catalogPROCEDURE_SCHEM- Procedure schemaPROCEDURE_NAME- Procedure nameREMARKS- Explanatory commentPROCEDURE_TYPE- Procedure type (procedureResultUnknown, procedureNoResult, procedureReturnsResult)
Database Version
Get version information about the database and JDBC driver:
Result Columns:
DATABASE_PRODUCTNAME- Database product name (e.g., "MySQL", "PostgreSQL")DATABASE_VERSION- Database version stringDRIVER_NAME- JDBC driver nameDRIVER_VERSION- JDBC driver versionJDBC_MAJOR_VERSION- JDBC major version numberJDBC_MINOR_VERSION- JDBC minor version number
🎯 Complete Examples
Dynamic Table Browser
Schema Documentation Generator
Table Relationship Mapper
Database Comparison Tool
🛠️ Component Attributes
type
string
Yes
Type of metadata: "dbnames", "tables", "columns", "foreignkeys", "index", "procedures", or "version"
name
string
Yes
Variable name to store the result query
datasource
string
No
Datasource name (uses default if not specified)
table
string
Conditional
Table name (required for "columns", "foreignkeys", "index")
pattern
string
No
Table name pattern using wildcards (%, _) or schema.table syntax
dbname
string
No
Database name (defaults to connection database)
filter
string
No
Table type filter (TABLE, VIEW, etc.) - only for type="tables"
💡 Best Practices
Pattern Matching
✅ Use wildcards for flexible table matching:
user_%matches all tables starting with "user_"✅ Specify schema when needed:
public.%for all tables in public schema✅ Cache metadata for static schemas to avoid repeated queries
Performance
✅ Filter by pattern instead of retrieving all tables
✅ Use specific queries (columns for one table vs all tables)
✅ Cache results for metadata that doesn't change often
✅ Limit scope with database and schema names
Error Handling
✅ Check table existence before querying columns
✅ Handle empty results gracefully
✅ Validate user input before using in patterns
✅ Test with different databases - metadata structure varies
Security
✅ Limit permissions - don't grant metadata access unnecessarily
✅ Sanitize patterns - prevent injection via pattern strings
✅ Audit usage - log metadata queries in production
✅ Filter sensitive tables from user-facing tools
🚫 Common Pitfalls
❌ Not handling NULL values in metadata
❌ Forgetting required attributes
❌ Not checking for empty results
🔗 Related Documentation
Datasources - Configure database connections
Querying - Execute SQL queries
bx:dbInfo Component - Complete component reference
Query Type Reference - Working with query results
Last updated
Was this helpful?
