AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Sqlserver Query Patterns

skill-iambrzdev-enterprise-agent-skills-sqlserver-query-patterns · by iamBrzDev

>

No reviews yet
0 installs
12 views
0.0% view→install

Install

$ agentstack add skill-iambrzdev-enterprise-agent-skills-sqlserver-query-patterns

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No 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.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-iambrzdev-enterprise-agent-skills-sqlserver-query-patterns)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
4mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

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 →
Are you the author of Sqlserver Query Patterns? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

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

  1. Know the data volume — row counts and table sizes
  2. Check existing indexes on all involved tables
  3. Write the query using set-based operations
  4. Review the estimated execution plan
  5. Identify operators above 15% cost
  6. Add or adjust indexes if needed
  7. 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 NOLOCK as performance shortcut
  • ✅ Always SET NOCOUNT ON
  • ✅ Always SET XACT_ABORT ON in 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.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.