SQL: Stored Procedure Contracts and Temp Tables
I’ve recently been writing about the need for stored procedures to have contracts . Temporary tables add another dimension to that discussion.
Tempory tables are visible within the scope where they are declared but also in sub-scopes. This means that you can declare a temp table in one stored procedure but access it in another stored procedure that is executed from within the first stored procedure.
There are two reasons that people do this. One reason is basically sloppy code, a bit like having all your variables global in a high level programming language. But the more appropriate reason is to avoid the overhead of moving large amounts of data around, and because we only have READONLY table valued parameters.
2026-05-08

