我想知道在存储过程中使用Views, Temp Tables and Direct Queries
的性能。我应该使用什么来提高性能。查看/查询/临时表
我有一个表,每当触发器被触发时被创建。我知道这个触发器会在非常罕见的情况下被触发,并且在安装时只会触发一次。
现在我必须在很多地方使用触发器创建的表来获取数据,并且我确认没有人在该表中进行任何更改。即ReadOnly
表。
我不得不与多个表一起使用这个表中的数据的加入,结果取作进一步查询说
select * from triggertable
使用临时表
select ... into #tx from triggertable join t2 join t3 and so on
select a,b, c from #tx --do something
select d,e,f from #tx ---do somethign
--and so on
--around 6-7 queries in a row in a stored procedure.
使用浏览
create view viewname
(
select ... from triggertable join t2 join t3 and so on
)
select a,b, c from viewname --do something
select d,e,f from viewname ---do somethign
--and so on
--around 6-7 queries in a row in a stored procedure.
此视图也可用于其他地方。所以,我会在数据库中,而不是在SP
要创建通过直接查询
select a,b, c from select ... into #tx from triggertable join t2 join t3 join ... --do something
select a,b, c from select ... into #tx from triggertable join t2 join t3 join ... --do something
.
.
--and so on
--around 6-7 queries in a row in a stored procedure.
现在,我可以创建所有即将查询视图/临时表/直接查询使用。
在这种情况下最好使用什么。
是的,可触发表的来源将始终相同。它将始终具有相同的列号和相同的名称。只有我需要的是在不同的存储过程的多个地方使用该表的子集。即使我提到的这个观点也可能在多个程序中使用。 – 2010-06-10 08:30:00