liveBook · Manning

Stored procedure

As explained in AI for Everyday IT

A stored procedure is a named, executable program stored in a database and invoked to perform database operations.

A stored procedure is a named, executable database program that packages operations for reuse. In administration work, it can support performance analysis or automate a multi-step task. section 10.3 section 10.6.3

Useful roles include:

  • Analyzing execution count, average elapsed time, CPU time, and logical reads to find procedures needing optimization. section 10.3
  • Accepting parameters so one procedure can perform a repeatable task for different databases or file paths. section 10.6.3

Performance triage

Run a query that lists the ten procedures with the highest average execution time, then inspect execution count, CPU, and logical reads before optimizing. section 10.3

SELECT TOP 10
    DB_NAME(ps.database_id) AS DatabaseName,
    OBJECT_NAME(ps.[object_id], ps.database_id) AS StoredProcedure,
    ps.execution_count AS ExecutionCount,
    ps.total_elapsed_time / ps.execution_count AS AvgElapsedTime,
    ps.total_worker_time / ps.execution_count AS AvgCPU,
    ps.total_logical_reads / ps.execution_count AS AvgReads
FROM sys.dm_exec_procedure_stats AS ps
ORDER BY ps.total_elapsed_time / ps.execution_count DESC;

Use the listing as a compact SQL Server starting point for ranking procedures by average execution time. section 10.3

How AI for Everyday IT covers it

How deep it goes
Explains performance metrics and parameterized administration workflows, but does not develop procedure syntax generally.
Examples
Uses a procedure-statistics query and a parameterized procedure for moving database data and log files.
What it assumes
Assumes familiarity with SQL Server administration and database files rather than teaching those foundations from zero.
What you can do after
Build it from scratch with parameters, validation, connection handling, file movement, and reattachment logic.
How it connects
Connects stored procedures with SQL Server, performance tuning, parameters, database files, and operating-system commands.

Also explained in

Compare how 4 books explain stored procedure →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI for Everyday IT. The section links point to the parts of the book it draws on.