sql-server – 将Table Valued参数传递给跨不同数据库的存储过程

我正在使用sql Server 2008.

如何将Table Valued参数传递到跨不同数据库的存储过程,但是相同的服务器?

我应该在两个数据库中创建相同的表类型吗?

请根据问题举例或链接.

谢谢你的帮助.

解决方法

回应此评论(如果我是正确的,并且无法在数据库之间使用TVP):

What choice do I have in this situation? Using XML type?

纯粹的方法是说如果两个数据库都使用相同的数据,它们应该合并到一个数据库中.实用主义者意识到这并不总是可行的 – 但是因为你可以明显地改变调用者和被调用者,所以可能只使用存储过程都知道的临时表.

I don’t believe it’s possible – you can’t reference a table type from another database,and even with identical type deFinitions in both DBs,a value of one type isn’t assignable to the other.

您不在数据库之间传递临时表.临时表始终存储在tempdb中,并且只要连接打开且临时表未被删除,您的连接就可以访问它.

因此,您在调用者中创建临时表:

CREATE TABLE #Values (ID int not null,ColA varchar(10) not null)
INSERT INTO #Values (ID,ColA)
/* Whatever you do to populate the table */
EXEC OtherDB..OtherProc

然后在被叫方:

CREATE PROCEDURE OtherProc
/* No parameter passed */
AS
    SELECT * from #Values

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...