describe_table
Retrieve schema information for SQL Server tables to understand column definitions, data types, and table structure for database analysis and query development.
Instructions
Get the schema information for a specific table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional) | |
| schema | No | Schema name (optional, defaults to dbo) | |
| table_name | Yes | Name of the table to describe |
Implementation Reference
- Main handler function that builds and executes SQL query to describe table schema using INFORMATION_SCHEMA views, detects primary keys, and returns formatted results.async describeTable(tableName, database = null, schema = 'dbo') { let query; if (database) { query = ` SELECT c.COLUMN_NAME as column_name, c.DATA_TYPE as data_type, c.IS_NULLABLE as is_nullable, c.COLUMN_DEFAULT as column_default, c.CHARACTER_MAXIMUM_LENGTH as max_length, c.NUMERIC_PRECISION as precision, c.NUMERIC_SCALE as scale, CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 'YES' ELSE 'NO' END as is_primary_key FROM [${database}].INFORMATION_SCHEMA.COLUMNS c LEFT JOIN [${database}].INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON c.TABLE_NAME = tc.TABLE_NAME AND c.TABLE_SCHEMA = tc.TABLE_SCHEMA AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' LEFT JOIN [${database}].INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk ON c.COLUMN_NAME = pk.COLUMN_NAME AND c.TABLE_NAME = pk.TABLE_NAME AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA AND tc.CONSTRAINT_NAME = pk.CONSTRAINT_NAME WHERE c.TABLE_NAME = '${tableName}' AND c.TABLE_SCHEMA = '${schema}' ORDER BY c.ORDINAL_POSITION `; } else { query = ` SELECT c.COLUMN_NAME as column_name, c.DATA_TYPE as data_type, c.IS_NULLABLE as is_nullable, c.COLUMN_DEFAULT as column_default, c.CHARACTER_MAXIMUM_LENGTH as max_length, c.NUMERIC_PRECISION as precision, c.NUMERIC_SCALE as scale, CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 'YES' ELSE 'NO' END as is_primary_key FROM INFORMATION_SCHEMA.COLUMNS c LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON c.TABLE_NAME = tc.TABLE_NAME AND c.TABLE_SCHEMA = tc.TABLE_SCHEMA AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk ON c.COLUMN_NAME = pk.COLUMN_NAME AND c.TABLE_NAME = pk.TABLE_NAME AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA AND tc.CONSTRAINT_NAME = pk.CONSTRAINT_NAME WHERE c.TABLE_NAME = '${tableName}' AND c.TABLE_SCHEMA = '${schema}' ORDER BY c.ORDINAL_POSITION `; } const result = await this.executeQuery(query, 'describe_table'); return this.formatResults(result); }
- lib/tools/tool-registry.js:38-50 (registration)Tool registration in DATABASE_TOOLS array, including name, description, and input schema parameters.{ name: 'describe_table', description: 'Get the schema information for a specific table', inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table to describe' }, database: { type: 'string', description: 'Database name (optional)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' } }, required: ['table_name'] } },
- lib/tools/tool-registry.js:41-49 (schema)Input schema definition for the describe_table tool, specifying parameters table_name (required), database, and schema.inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table to describe' }, database: { type: 'string', description: 'Database name (optional)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' } }, required: ['table_name'] }
- index.js:266-273 (handler)Dispatch handler in main server switch statement that routes describe_table calls to DatabaseToolsHandler.describeTable.case 'describe_table': return { content: await this.databaseTools.describeTable( args.table_name, args.database, args.schema ) };