创建一个临时表,要想获得这个临时表的列数,需要到 tempdb 中查询,因为 SQL Server 的临时表及其元数据是存放在 tempdb 数据库中的。
create table #t(id int, name varchar(30))
在 SQL Server 2000 中获得临时表的列数:
select count(*) from tempdb.dbo.syscolumns where id = object_id('tempdb..#t')
在 SQL Server 2005 中获得临时表的列数:
select count(*) from tempdb.sys.columns where object_id = object_id('tempdb..#t')