SELECT
t.name AS table_name,
c.name AS column_name,
tp.name AS data_type,
CASE WHEN ic.column_id IS NOT NULL THEN 'PRI' ELSE '' END as column_key
FROM sys.tables t
JOIN sys.columns c ON t.object_id = c.object_id
JOIN sys.types tp ON c.user_type_id = tp.user_type_id
LEFT JOIN sys.indexes i ON t.object_id = i.object_id AND i.is_primary_key = 1
LEFT JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id AND c.column_id = ic.column_id
ORDER BY t.name, c.column_id;
Step 3 Paste the results from the above query
Step 4 Describe what you want to query
Example Query
See how the AI generates SQL from natural language
-- Find all customers who made purchases over $1000 last month
SELECT c.name, SUM(o.amount) as total_spent
FROM customers c
JOIN orders o ON c.id = o.customer_id
WHERE o.date >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY c.id
HAVING total_spent > 1000;