agentleFS
MathiasPaulenkoMathiasPaulenko/ai-toolkit/skills/sql-server/SKILL.md

sql-server

Skill2 starsChanged 3 months agoMITView on GitHub

Microsoft SQL Server development guide. Covers T-SQL syntax, stored procedures, indexing strategies, temporal tables, JSON support, Always Encrypted, and Azure SQL specifics.

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Azure Active Directory authentication for service principals.

    line 186
  2. Distinctive:

    Use serverless tier for intermittent workloads.

    line 188
  3. Distinctive:

    Use connection retry logic with exponential backoff (transient fault handling).

    line 190

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SQL Server

1. T-SQL Basics

SELECT with OFFSET/FETCH

SELECT id, name, email
FROM users
ORDER BY created_at DESC
OFFSET 40 ROWS FETCH NEXT 20 ROWS ONLY;  -- Page 3, 20 per page

MERGE (Upsert)

MERGE users AS target
USING staging_users AS source
ON target.email = source.email
WHEN MATCHED THEN
    UPDATE SET target.name = source.name, target.updated_at = GETDATE()
WHEN NOT MATCHED THEN
    INSERT (email, name, created_at)
    VALUES (source.email, source.name, GETDATE());

TRY/CATCH

BEGIN TRY
    BEGIN TRANSACTION;
    INSERT INTO orders (user_id, total) VALUES (1, 100.00);
    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION;
    THROW;  -- Re-raise the error
END CATCH;

2. Stored Procedures

CREATE PROCEDURE usp_GetUserOrders
    @UserId INT,
    @Status VARCHAR(20) = NULL,
    @PageNumber INT = 1,
    @PageSize INT = 20
AS
BEGIN
    SET NOCOUNT ON;

    SELECT o.id, o.total, o.status, o.created_at
    FROM orders o
    WHERE o.user_id = @UserId
      AND (@Status IS NULL OR o.status = @Status)
    ORDER BY o.created_at DESC
    OFFSET (@PageNumber - 1) * @PageSize ROWS
    FETCH NEXT @PageSize ROWS ONLY;

    SELECT COUNT(*) AS total_count
    FROM orders
    WHERE user_id = @UserId
      AND (@Status IS NULL OR status = @Status);
END;
GO

3. Indexing

TypeUse Case
ClusteredPrimary key; determines physical sort order
Non-clusteredAdditional lookup paths
FilteredIndex subset of rows (e.g., WHERE is_active = 1)
ColumnstoreAnalytical queries on large datasets
XML/JSONIndex XML columns or JSON paths
-- Filtered index for active users
CREATE NONCLUSTERED INDEX IX_users_active_email
ON users(email)
WHERE is_active = 1;

-- Covering index
CREATE NONCLUSTERED INDEX IX_orders_user_status_covering
ON orders(user_id, status)
INCLUDE (total, created_at);  -- No key lookup needed

4. JSON Support

-- Parse JSON
DECLARE @json NVARCHAR(MAX) = '[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]';

SELECT *
FROM OPENJSON(@json)
WITH (
    id INT '$.id',
    name VARCHAR(100) '$.name'
);

-- Store JSON
INSERT INTO events (data)
VALUES (JSON_OBJECT('action': 'login', 'user_id': 42));

-- Query JSON
SELECT id, JSON_VALUE(data, '$.action') AS action
FROM events
WHERE JSON_VALUE(data, '$.action') = 'login';

5. Temporal Tables (System-Versioning)

CREATE TABLE users (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(255),
    valid_from DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN,
    valid_to DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN,
    PERIOD FOR SYSTEM_TIME (valid_from, valid_to)
) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.users_history));

-- Query as of a point in time
SELECT * FROM users
FOR SYSTEM_TIME AS OF '2024-01-15';

6. Always Encrypted

-- Column encrypted with deterministic encryption (allows equality)
CREATE TABLE patients (
    id INT PRIMARY KEY,
    ssn VARCHAR(11) COLLATE Latin1_General_BIN2
        ENCRYPTED WITH (
            COLUMN_ENCRYPTION_KEY = CEK1,
            ENCRYPTION_TYPE = DETERMINISTIC,
            ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256'
        ),
    birth_date DATE
        ENCRYPTED WITH (
            COLUMN_ENCRYPTION_KEY = CEK1,
            ENCRYPTION_TYPE = RANDOMIZED,
            ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256'
        )
);

7. Python Integration (pyodbc)

import pyodbc

conn_str = (
    "DRIVER={ODBC Driver 17 for SQL Server};"
    "SERVER=myserver.database.windows.net;"
    "DATABASE=mydb;"
    "UID=myuser;PWD=mypassword"
)

with pyodbc.connect(conn_str) as conn:
    cursor = conn.cursor()
    cursor.execute(
        "EXEC usp_GetUserOrders ?, ?, ?, ?",
        (1, "completed", 1, 20),
    )
    rows = cursor.fetchall()

8. Azure SQL Specifics

  • Use Azure Active Directory authentication for service principals.
  • Enable hyperscale for databases > 100 GB.
  • Use serverless tier for intermittent workloads.
  • Configure firewall rules at server level, not database level.
  • Use connection retry logic with exponential backoff (transient fault handling).
# Connection retry with tenacity
from tenacity import retry, wait_exponential, stop_after_attempt

@retry(wait=wait_exponential(multiplier=1, min=4, max=10),
       stop=stop_after_attempt(3))
def execute_query(sql):
    with pyodbc.connect(conn_str) as conn:
        return conn.execute(sql).fetchall()

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.