Install
$ agentstack add skill-iambrzdev-enterprise-agent-skills-sqlserver-query-patterns ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
When to activate
- "This query is slow" or performance issues in SQL Server
- Writing or refactoring a Stored Procedure
- Index design or indexing strategy
- Reading or interpreting an execution plan
- Pagination in SQL Server
- Reporting queries with aggregations, CTEs, or window functions
The Optimization Workflow
- Know the data volume — row counts and table sizes
- Check existing indexes on all involved tables
- Write the query using set-based operations
- Review the estimated execution plan
- Identify operators above 15% cost
- Add or adjust indexes if needed
- Validate actual vs estimated rows
Index Strategy
-- Covering index: include all columns the query needs → eliminates Key Lookup
CREATE NONCLUSTERED INDEX IX_Orders_CustomerId_Covering
ON Orders (CustomerId)
INCLUDE (Status, Total, CreatedAt);
-- Filtered index: for queries that always filter by a known condition
CREATE NONCLUSTERED INDEX IXF_Orders_Pending
ON Orders (CreatedAt)
WHERE Status = 'pending';
Naming: IX_{Table}_{Columns} · Unique: UX_{Table}_{Columns} · Filtered: IXF_{Table}_{Condition}
T-SQL Patterns
-- ✅ EXISTS for existence checks
IF EXISTS (SELECT 1 FROM Orders WHERE CustomerId = @CustomerId AND Status = 'active')
-- ✅ Sargable date range (index-friendly)
WHERE CreatedAt >= '2024-01-01' AND CreatedAt = DATEADD(MONTH, -6, GETUTCDATE())
GROUP BY CustomerId
)
SELECT c.Name, r.OrderCount, r.TotalSpent
FROM Customers c
JOIN RecentOrders r ON c.Id = r.CustomerId;
Stored Procedure Template
CREATE OR ALTER PROCEDURE usp_GetOrdersByCustomer
@CustomerId INT,
@PageNumber INT = 1,
@PageSize INT = 20,
@Status NVARCHAR(50) = NULL
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF @CustomerId IS NULL OR @CustomerId <= 0
THROW 50001, 'CustomerId must be a positive integer.', 1;
SELECT o.OrderId, o.Total, o.Status, o.CreatedAt,
COUNT(*) OVER() AS TotalCount
FROM Orders o
WHERE o.CustomerId = @CustomerId
AND o.IsDeleted = 0
AND (@Status IS NULL OR o.Status = @Status)
ORDER BY o.CreatedAt DESC
OFFSET (@PageNumber - 1) * @PageSize ROWS
FETCH NEXT @PageSize ROWS ONLY;
END;
GO
Non-negotiables
- ❌ Never
SELECT *in stored procedures - ❌ Never cursors when set-based works
- ❌ Never functions on indexed columns in WHERE
- ❌ Never
NOLOCKas performance shortcut - ✅ Always
SET NOCOUNT ON - ✅ Always
SET XACT_ABORT ONin procedures that modify data - ✅ Use
GETUTCDATE()— store UTC, display local in app layer
Quick diagnostics
-- Missing indexes suggested by optimizer
SELECT mid.statement, mid.equality_columns, migs.avg_user_impact
FROM sys.dm_db_missing_index_details mid
JOIN sys.dm_db_missing_index_groups mig ON mid.index_handle = mig.index_handle
JOIN sys.dm_db_missing_index_group_stats migs ON mig.index_group_handle = migs.group_handle
WHERE mid.database_id = DB_ID()
ORDER BY migs.avg_user_impact DESC;
Reference files
references/indexing-strategy.md— Fragmentación, rebuild vs reorganize, mantenimiento
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: iamBrzDev
- Source: iamBrzDev/enterprise-agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.