# š¤ MCP SQL Server General Interaction Guide
## Universal Database Communication Patterns for AI Assistants
---
## š Table of Contents
1. [Overview](#overview)
2. [Understanding MCP Database Operations](#understanding-mcp-database-operations)
3. [Effective Prompt Patterns](#effective-prompt-patterns)
4. [Database Discovery & Exploration](#database-discovery--exploration)
5. [Data Retrieval Patterns](#data-retrieval-patterns)
6. [Data Modification Patterns](#data-modification-patterns)
7. [Analytics & Reporting Patterns](#analytics--reporting-patterns)
8. [Database Administration Patterns](#database-administration-patterns)
9. [Troubleshooting & Debugging](#troubleshooting--debugging)
10. [Advanced MCP Techniques](#advanced-mcp-techniques)
11. [Best Practices & Safety](#best-practices--safety)
12. [Quick Reference](#quick-reference)
---
## šÆ Overview
This guide provides universal patterns for communicating with **MCP (Model Context Protocol) SQL Server** tools. These patterns work with any database schema and help you get the most effective results from AI-powered database interactions.
### **What This Guide Covers:**
- ā
**Universal prompt patterns** that work with any database
- ā
**MCP-optimized communication** techniques
- ā
**Safe database interaction** practices
- ā
**Performance-focused** query strategies
- ā
**Error handling** and troubleshooting
### **What This Guide Doesn't Cover:**
- ā Project-specific database schemas
- ā Business logic implementation
- ā Application development patterns
- ā Database design principles
---
## š§ Understanding MCP Database Operations
### **MCP Database Tool Operations:**
MCP SQL Server tools typically support these core operations:
#### **1. CREATE Operations:**
```
Purpose: Create database objects (tables, indexes, views, procedures)
MCP Usage: Structure and schema management
Best For: Initial setup, schema modifications
```
#### **2. READ Operations:**
```
Purpose: Query and retrieve data (SELECT statements)
MCP Usage: Data exploration, reporting, analysis
Best For: Information gathering, reporting
```
#### **3. UPDATE Operations:**
```
Purpose: Modify existing data (INSERT, UPDATE statements)
MCP Usage: Data maintenance, record updates
Best For: Data entry, corrections, bulk updates
```
#### **4. DELETE Operations:**
```
Purpose: Remove data (DELETE statements)
MCP Usage: Data cleanup, record removal
Best For: Maintenance, data purging
```
### **How MCP Processes Your Requests:**
```
Your Prompt ā MCP Analysis ā SQL Generation ā Database Execution ā Results
```
**Key Point:** MCP translates natural language into SQL operations, so clear communication is essential.
---
## š£ļø Effective Prompt Patterns
### **1. The CLEAR Pattern:**
**C**ontext - **L**ocation - **E**xpected - **A**ction - **R**equirements
#### **Good Example:**
```
"I need to analyze customer data (Context) from the sales database (Location).
I expect to see purchase patterns (Expected) by retrieving (Action)
all orders from the last 6 months with customer details (Requirements)."
```
#### **Poor Example:**
```
"Show me some data"
```
### **2. The SMART Pattern:**
**S**pecific - **M**easurable - **A**ctionable - **R**elevant - **T**ime-bound
#### **Good Example:**
```
"Show me the top 10 products (Specific & Measurable)
by sales volume (Actionable & Relevant)
from Q4 2024 (Time-bound)"
```
### **3. The SCOPE Pattern:**
**S**elect - **C**onditions - **O**rder - **P**agination - **E**xclusions
#### **Good Example:**
```
"Select all employee records (Select)
where department is 'IT' and status is active (Conditions)
ordered by hire date descending (Order)
limit to first 20 results (Pagination)
excluding terminated employees (Exclusions)"
```
---
## š Database Discovery & Exploration
### **Schema Discovery Prompts:**
#### **Database Overview:**
```
"What databases are available on this server?"
"Show me the current database name and version"
"List all schemas in the current database"
"Display database size and basic statistics"
```
#### **Table Discovery:**
```
"List all tables in the database"
"Show me table names with their row counts"
"Display tables created in the last 30 days"
"Find tables containing the word 'user' in their name"
```
#### **Column Analysis:**
```
"Describe the structure of the [table_name] table"
"Show me all columns in [table_name] with their data types"
"List all foreign key relationships for [table_name]"
"Find columns that might contain email addresses across all tables"
```
#### **Relationship Discovery:**
```
"Show me all foreign key relationships in the database"
"Display table relationships as a summary"
"Find tables that reference [table_name]"
"Show me the relationship between [table1] and [table2]"
```
### **Data Profiling Prompts:**
#### **Data Quality Assessment:**
```
"Check for null values in [table_name]"
"Find duplicate records in [table_name] based on [column_name]"
"Show data distribution for [column_name] in [table_name]"
"Identify potential data quality issues in [table_name]"
```
#### **Statistical Analysis:**
```
"Show basic statistics for numeric columns in [table_name]"
"Display value frequency for [column_name]"
"Find the date range of records in [table_name]"
"Show minimum, maximum, and average values for [column_name]"
```
---
## š Data Retrieval Patterns
### **1. Basic Queries:**
#### **Simple Selection:**
```
"Show me all records from [table_name]"
"Display the first 10 rows from [table_name]"
"Get all columns from [table_name] where [condition]"
"Show unique values from [column_name] in [table_name]"
```
#### **Filtered Queries:**
```
"Show records from [table_name] where [column] equals '[value]'"
"Display records from [table_name] created after [date]"
"Find records in [table_name] where [column] contains '[text]'"
"Get records from [table_name] where [column] is null"
```
### **2. Advanced Queries:**
#### **Joins and Relationships:**
```
"Show data from [table1] joined with [table2] on [relationship]"
"Display all records from [table1] with their related [table2] data"
"Find [table1] records that don't have corresponding [table2] records"
"Show a combined view of [table1], [table2], and [table3]"
```
#### **Aggregations:**
```
"Count total records in [table_name]"
"Show sum of [column_name] grouped by [group_column]"
"Display average [column_name] for each [category_column]"
"Find maximum and minimum values of [column_name] by [group_column]"
```
### **3. Time-Based Queries:**
#### **Date Filtering:**
```
"Show records from [table_name] from the last 7 days"
"Display data from [table_name] between [start_date] and [end_date]"
"Find records created this month in [table_name]"
"Show year-over-year comparison for [table_name]"
```
#### **Trending Analysis:**
```
"Show monthly trends for [table_name] records"
"Display daily activity patterns in [table_name]"
"Find seasonal patterns in [table_name] data"
"Show growth rate analysis for [table_name]"
```
---
## āļø Data Modification Patterns
### **1. Adding Data:**
#### **Single Record Insertion:**
```
"Add a new record to [table_name] with [field1]='[value1]', [field2]='[value2]'"
"Insert a new [entity_type] with the following details: [details]"
"Create a new entry in [table_name] using these values: [values]"
```
#### **Bulk Data Insertion:**
```
"Insert multiple records into [table_name] with these values: [data_set]"
"Bulk load data into [table_name] from the following dataset: [data]"
"Add several new records to [table_name] in one operation"
```
### **2. Updating Data:**
#### **Single Record Updates:**
```
"Update record with ID [id] in [table_name] to set [field]='[new_value]'"
"Change [field_name] to '[new_value]' for record where [condition]"
"Modify the [field_name] field in [table_name] for [specific_record]"
```
#### **Bulk Updates:**
```
"Update all records in [table_name] where [condition] to set [field]='[value]'"
"Change [field_name] to '[new_value]' for all records matching [criteria]"
"Bulk update [table_name] records created before [date] to set [field]='[value]'"
```
### **3. Data Cleanup:**
#### **Removing Records:**
```
"Delete the record with ID [id] from [table_name]"
"Remove all records from [table_name] where [condition]"
"Delete duplicate records from [table_name] based on [criteria]"
```
#### **Archiving Data:**
```
"Move old records from [table_name] to [archive_table] where [condition]"
"Archive records older than [timeframe] from [table_name]"
"Soft delete records in [table_name] by setting [status_field]='inactive'"
```
---
## š Analytics & Reporting Patterns
### **1. Summary Reports:**
#### **Basic Statistics:**
```
"Generate a summary report for [table_name] showing key metrics"
"Create an overview of [table_name] with counts, averages, and totals"
"Show dashboard-style metrics for [table_name]"
"Display key performance indicators from [table_name]"
```
#### **Comparative Analysis:**
```
"Compare [metric] between [group1] and [group2] in [table_name]"
"Show before and after analysis for [table_name] around [date]"
"Display performance comparison across [category_field] in [table_name]"
"Generate variance analysis for [metric_field] by [group_field]"
```
### **2. Trend Analysis:**
#### **Time Series:**
```
"Show [metric] trends over time from [table_name]"
"Display monthly progression of [field_name] in [table_name]"
"Create a time series analysis for [table_name] data"
"Show seasonal patterns in [table_name] over the last [timeframe]"
```
#### **Growth Analysis:**
```
"Calculate growth rate for [metric] in [table_name]"
"Show period-over-period changes in [table_name]"
"Display compound growth analysis for [field_name]"
"Generate trend forecasting data from [table_name]"
```
### **3. Distribution Analysis:**
#### **Data Distribution:**
```
"Show distribution of [field_name] values in [table_name]"
"Display frequency analysis for [category_field] in [table_name]"
"Create a histogram of [numeric_field] from [table_name]"
"Show percentile analysis for [metric_field] in [table_name]"
```
#### **Correlation Analysis:**
```
"Find correlation between [field1] and [field2] in [table_name]"
"Show relationship patterns between [table1] and [table2]"
"Display cross-tabulation of [field1] by [field2] in [table_name]"
"Generate correlation matrix for numeric fields in [table_name]"
```
---
## š ļø Database Administration Patterns
### **1. Performance Analysis:**
#### **Query Performance:**
```
"Show slow-running queries on the database"
"Display query execution statistics for [table_name] operations"
"Find performance bottlenecks in database operations"
"Show index usage statistics for [table_name]"
```
#### **Resource Utilization:**
```
"Display database size and storage usage"
"Show table sizes ordered by space consumption"
"Find largest tables and their growth trends"
"Display memory and CPU usage patterns"
```
### **2. Maintenance Operations:**
#### **Index Management:**
```
"Show index information for [table_name]"
"Display fragmented indexes that need rebuilding"
"List missing indexes that could improve performance"
"Show index usage statistics across all tables"
```
#### **Statistics Updates:**
```
"Update table statistics for [table_name]"
"Refresh database statistics for optimal performance"
"Show when statistics were last updated for [table_name]"
"Display outdated statistics across all tables"
```
### **3. Security and Permissions:**
#### **Access Control:**
```
"Show current user permissions on [table_name]"
"Display all users with access to [database_name]"
"List table-level permissions for [user_name]"
"Show role assignments for database users"
```
#### **Audit and Compliance:**
```
"Show recent access logs for [table_name]"
"Display failed login attempts and security events"
"List all administrative actions performed today"
"Show data modification audit trail for [table_name]"
```
---
## šØ Troubleshooting & Debugging
### **1. Error Diagnosis:**
#### **Connection Issues:**
```
"Test database connectivity and show connection status"
"Display current database connection information"
"Show active connections and their status"
"Test query execution time and performance"
```
#### **Data Issues:**
```
"Find inconsistent data in [table_name]"
"Check referential integrity for [table_name]"
"Identify orphaned records in [table_name]"
"Validate data constraints in [table_name]"
```
### **2. Performance Debugging:**
#### **Slow Query Analysis:**
```
"Analyze query performance for [specific_operation]"
"Show execution plan for queries on [table_name]"
"Find blocking queries and lock contention"
"Display wait statistics and bottlenecks"
```
#### **Resource Monitoring:**
```
"Show current database load and resource usage"
"Display active queries and their resource consumption"
"Find queries consuming the most CPU or memory"
"Show I/O statistics for database operations"
```
### **3. Data Validation:**
#### **Integrity Checks:**
```
"Validate all foreign key relationships in the database"
"Check for constraint violations in [table_name]"
"Find records that violate business rules in [table_name]"
"Verify data consistency between related tables"
```
#### **Quality Assessment:**
```
"Identify potential data quality issues across all tables"
"Find incomplete records in [table_name]"
"Show data completeness statistics for [table_name]"
"Detect anomalies in [table_name] data patterns"
```
---
## š Advanced MCP Techniques
### **1. Complex Query Composition:**
#### **Multi-Step Operations:**
```
"First, show me the structure of [table_name], then display sample data"
"Create a summary of [table_name], followed by detailed analysis"
"Check data quality in [table_name], then suggest improvements"
"Analyze [table_name] performance, then recommend optimizations"
```
#### **Conditional Logic:**
```
"If [table_name] has more than 1000 records, show a sample; otherwise, show all"
"Depending on data volume in [table_name], choose appropriate analysis method"
"Based on [table_name] structure, suggest the best query approach"
"Adapt the query strategy based on [table_name] characteristics"
```
### **2. Dynamic Analysis:**
#### **Adaptive Queries:**
```
"Analyze [table_name] and determine the most relevant metrics to display"
"Based on [table_name] data patterns, suggest useful queries"
"Examine [table_name] and recommend appropriate visualizations"
"Study [table_name] structure and propose optimization strategies"
```
#### **Contextual Operations:**
```
"Considering the current database load, optimize this query for [table_name]"
"Based on [table_name] size, choose between detailed or summary analysis"
"Adapt the reporting approach based on [table_name] data characteristics"
"Optimize query execution based on current system performance"
```
### **3. Iterative Refinement:**
#### **Progressive Analysis:**
```
"Start with basic analysis of [table_name], then dive deeper based on findings"
"Begin with overview of [table_name], then focus on interesting patterns"
"Initial assessment of [table_name], followed by targeted investigation"
"Broad analysis first, then narrow down to specific issues in [table_name]"
```
#### **Feedback-Driven Queries:**
```
"Show [table_name] summary, then let me specify which areas to explore further"
"Display [table_name] overview, then I'll indicate what needs deeper analysis"
"Present [table_name] metrics, then guide me to the most important insights"
"Provide [table_name] baseline, then help me identify areas of interest"
```
---
## š Best Practices & Safety
### **1. Safe Query Practices:**
#### **Always Include These Elements:**
```
ā
Specific table names and column references
ā
Clear filtering conditions and limits
ā
Explicit result set size expectations
ā
Time boundaries for date-based queries
ā
Backup considerations for modification operations
```
#### **Never Do These Things:**
```
ā Request operations without WHERE clauses on large tables
ā Ask for unlimited result sets without pagination
ā Perform bulk modifications without explicit confirmation
ā Query sensitive data without proper authorization
ā Execute operations that could impact system performance
```
### **2. Performance Considerations:**
#### **Efficient Query Patterns:**
```
"Limit results to top N records when exploring large tables"
"Use indexed columns in WHERE clauses for better performance"
"Specify only needed columns instead of SELECT * for large tables"
"Include appropriate time ranges for date-based queries"
"Use EXISTS instead of IN for subqueries when possible"
```
#### **Resource Management:**
```
"Monitor query execution time and cancel if taking too long"
"Consider table size before requesting full data scans"
"Use sampling techniques for analysis of very large tables"
"Batch large operations to avoid system overload"
"Schedule heavy operations during off-peak hours"
```
### **3. Data Protection:**
#### **Sensitive Data Handling:**
```
"Exclude personally identifiable information from general queries"
"Mask or anonymize sensitive data in analysis results"
"Use appropriate access controls for confidential information"
"Log and audit access to sensitive data tables"
"Follow data retention policies for query results"
```
#### **Change Management:**
```
"Always test modifications on small datasets first"
"Create backups before performing bulk data changes"
"Document all significant data modifications"
"Use transactions for multi-step data operations"
"Verify changes before committing large updates"
```
---
## ā” Quick Reference
### **Essential Prompt Templates:**
#### **Discovery:**
```
"Show me [what] from [where] [conditions]"
"List all [objects] in [location] [filters]"
"Describe [object] structure and [characteristics]"
"Find [items] that [criteria]"
```
#### **Analysis:**
```
"Analyze [data] for [purpose] [timeframe]"
"Compare [metric] between [groups] [period]"
"Show [trend/pattern] in [data] over [time]"
"Calculate [statistic] for [dataset] [conditions]"
```
#### **Modification:**
```
"Update [table] set [field]=[value] where [condition]"
"Insert into [table] values [data]"
"Delete from [table] where [condition]"
"Modify [records] in [table] [specifications]"
```
### **Common MCP Response Patterns:**
#### **What MCP Does Well:**
```
ā
Translates natural language to SQL
ā
Handles complex multi-table operations
ā
Provides detailed explanations of operations
ā
Suggests optimizations and best practices
ā
Handles error recovery and alternative approaches
```
#### **What to Clarify for MCP:**
```
š Ambiguous table or column references
š Unclear filtering criteria or conditions
š Vague time ranges or date specifications
š Unspecified result set size expectations
š Missing context for business logic
```
### **Emergency Patterns:**
#### **Quick Diagnostics:**
```
"Show current database status and health"
"Display active connections and blocking queries"
"Find long-running operations that might need attention"
"Show recent errors and system messages"
```
#### **Performance Issues:**
```
"Identify current performance bottlenecks"
"Show queries consuming the most resources"
"Display wait statistics and lock information"
"Find tables with high contention or blocking"
```
---
## š Getting Help
### **When MCP Needs More Information:**
- Provide specific table and column names
- Clarify business context and requirements
- Specify expected result formats and sizes
- Include relevant time ranges and filters
- Explain the purpose of the analysis
### **When to Escalate Beyond MCP:**
- Complex business logic implementation
- Database schema design decisions
- Performance tuning requiring system changes
- Security policy implementations
- Cross-system integration requirements
---
## šÆ Success Metrics
### **Effective MCP Interaction Indicators:**
ā
**Clear Results:** MCP provides exactly what you need
ā
**Efficient Queries:** Operations complete quickly
ā
**Accurate Data:** Results match your expectations
ā
**Safe Operations:** No unintended data changes
ā
**Learning:** MCP explains its approach and suggests improvements
### **Continuous Improvement:**
- Refine prompts based on MCP responses
- Build a library of effective patterns
- Share successful approaches with team
- Document lessons learned from interactions
- Adapt techniques as MCP capabilities evolve
---
**Document Version:** 1.0
**Last Updated:** December 2024
**Compatibility:** Universal MCP SQL Server Tools
**Target Audience:** All database users working with MCP systems
---
*This guide is designed to evolve with MCP technology. Please contribute improvements and share effective patterns with the community.*