How to retrieve field names from temporary table (SQL Server 2008)

前端 未结 7 1828
借酒劲吻你
借酒劲吻你 2020-12-01 01:01

I\'m using SQL Server 2008. Say I create a temporary table like this one:

create table #MyTempTable (col1 int,col2 varchar(10))

How can I r

7条回答
  •  生来不讨喜
    2020-12-01 01:48

    The temporary tables are defined in "tempdb", and the table names are "mangled".

    This query should do the trick:

    select c.*
    from tempdb.sys.columns c
    inner join tempdb.sys.tables t ON c.object_id = t.object_id
    where t.name like '#MyTempTable%'
    

    Marc

提交回复
热议问题