Search code examples
sql-servert-sqlsql-server-2000

Get structure of temp table (like generate sql script) and clear temp table for current instance


How do I get structure of temp table then delete temp table. Is there a sp_helptext for temp tables? Finally is it possible to then delete temp table in same session or query window?

Example:

select *
into #myTempTable  -- creates a new temp table
from tMyTable  -- some table in your database

tempdb..sp_help #myTempTable

Reference.


Solution

  • You need to use quotes around the temp table name and you can delete the temp table directly after using drop table ....

    select *
    into #myTempTable  -- creates a new temp table
    from tMyTable  -- some table in your database
    
    exec tempdb..sp_help '#myTempTable'
    
    drop table #myTempTable