Home Forums SQL Server 2008 T-SQL (SS2K8) Table variable is not automatically dropped in TempDB RE: Table variable is not automatically dropped in TempDB

  • I made up a quick test to verify Gila's suggestion.

    Very interesting outcome.

    Whoever is curios try to run this:

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    create proc [dbo].

    as

    begin

    declare @i table (id int, NAME nvarchar(150))

    select 'during exec', * From tempdb.sys.tables ORDER BY create_date DESC, name

    end

    GO

    select 'after create', * From tempdb.sys.tables ORDER BY create_date DESC, name

    GO

    exec b

    GO

    select 'after exec', * From tempdb.sys.tables ORDER BY create_date DESC, name

    go

    exec b

    GO

    select 'after exec again', * From tempdb.sys.tables ORDER BY create_date DESC, name

    go

    DROP proc [dbo].

    GO

    select 'after drop', * From tempdb.sys.tables ORDER BY create_date DESC, name

    GO

    WAITFOR DELAY '00:01:00'

    select 'after 1 minute wait', * From tempdb.sys.tables ORDER BY create_date DESC, name

    GO

    On my desktop (being effectively idle at the time) the table variable disappeared only in the "after 1 minute" resultset.

    Very different from the behaviour on SQL2000: object is gone immediately after SP is completed.

    _____________
    Code for TallyGenerator