• Kenneth Wymore (11/23/2010)


    How often are global temp tables actually used? I recall reading about them when I started using SQL Server but I can't remember ever seeing one used in production.

    I've never seen GTTs in production code, too. However, I often use them when I test my T-SQL code.

    For example, there is a long-running stored procedure which returns a dataset, and I'm doing an optimized version of that procedure. I want to run a test to ensure that, given specified parameters, both procedures return the same dataset.

    I open two SSMS windows, in one of them I run the following script:

    CREATE TABLE ##result1 (...);

    INSERT ##result1

    EXEC dbo.Old_Procedure @param1 = value1, ...

    In the other window, I run the following script:

    CREATE TABLE ##result2 (...);

    INSERT ##result2

    EXEC dbo.New_Procedure @param1 = value1, ...

    Both procedures execute in parallel, and I can compare the datasets without making junk permanent tables.