get_table_data
Retrieve sample data from SQL Server tables with optional filtering conditions and row limits for data analysis and verification.
Instructions
Get sample data from a table with optional filtering and limiting
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional) | |
| limit | No | Maximum number of rows to return (optional, defaults to 100) | |
| schema | No | Schema name (optional, defaults to dbo) | |
| table_name | Yes | Name of the table | |
| where | No | WHERE clause conditions (optional) |
Implementation Reference
- Core handler function that builds and executes a paginated SELECT query to retrieve table data.async getTableData(tableName, database = null, schema = 'dbo', limit = 100, offset = 0) { let query; if (database) { query = ` SELECT * FROM [${database}].[${schema}].[${tableName}] ORDER BY (SELECT NULL) OFFSET ${offset} ROWS FETCH NEXT ${limit} ROWS ONLY `; } else { query = ` SELECT * FROM [${schema}].[${tableName}] ORDER BY (SELECT NULL) OFFSET ${offset} ROWS FETCH NEXT ${limit} ROWS ONLY `; } const result = await this.executeQuery(query, 'get_table_data'); return this.formatResults(result); }
- lib/tools/tool-registry.js:67-82 (schema)Tool definition including name, description, and input schema for validation.name: 'get_table_data', description: 'Get sample data from a table with optional filtering and limiting', inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table' }, database: { type: 'string', description: 'Database name (optional)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' }, limit: { type: 'number', description: 'Maximum number of rows to return (optional, defaults to 100)' }, where: { type: 'string', description: 'WHERE clause conditions (optional)' } }, required: ['table_name'] }
- index.js:287-296 (registration)Dispatch handler in main server that routes tool calls to the DatabaseToolsHandler.getTableData method.case 'get_table_data': return { content: await this.databaseTools.getTableData( args.table_name, args.database, args.schema, args.limit, args.offset ) };