如何确定 MS SQL Server 2005 中表值变量的内部名称 [英] How to determine internal name of table-valued variable in MS SQL Server 2005
问题描述
可以使用
select @TableName = [Name]
from tempdb.sys.tables
where [Object_ID] = object_id('tempDB.dbo.#t1')
如何找到表值变量的名称,即由
How can I find the name of a table valued variable, i.e. one declared by
declare @t2 as table (a int)
目的是能够获取关于表的元信息,使用类似
the purpose is to be able to get meta-information about the table, using something like
select @Headers = dbo.Concatenate('[' + c.[Name] + ']')
from sys.all_columns c
inner join sys.tables t
on c.object_id = t.object_id
where t.name = @TableName
虽然对于临时表,您必须查看 tempdb.sys.tables
而不是 sys.tables
.你在哪里寻找表值变量?
although for temp tables you have to look in tempdb.sys.tables
instead of sys.tables
. where do you look for table valued variables?
我现在意识到我不能做我想做的事情,那就是编写一个通用函数来将表值变量格式化为 html 表.首先,在 sql server 2005 中你不能传递表值参数:
I realize now that I can't do what I wanted to do, which is write a generic function for formatting table valued variables into html tables. For starters, in sql server 2005 you can't pass table valued parameters:
http://www.sqlteam.com/article/sql-server-2008-table-valued-parameters
此外,在 sql server 2008 中,参数必须是强类型的,因此您将始终知道列的数量和类型.
moreover, in sql server 2008, the parameters have to be strongly typed, so you will always know the number and type of columns.
推荐答案
我不相信你可以,因为表变量是在内存中创建的,而不是在 tempdb 中.
I don't believe you can, as table variables are created in memory not in tempdb.
这篇关于如何确定 MS SQL Server 2005 中表值变量的内部名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!