避免在同一张桌子上重复选择的有效方法 [英] Efficient method to avoid repeated select on same table

查看:51
本文介绍了避免在同一张桌子上重复选择的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要在表dbo.test上执行select语句,该表具有约4000条记录的数据.我需要在SP中以不同的条件执行8次select statemnt,并且需要将8个不同的记录集插入到8个不同的故事中.能否为我的疑问提供解决方案

我可能需要在SP中临时存储数据,或者更好地在表(dbo.test)本身上执行select statemnt 8次.
如果最好将临时存储在我的SP中,哪种方法会比较有效(使用临时表或表变量或任何其他方法),我需要创建一个SP来执行上述操作.

预先感谢

Hi,
I need to perform select statement on table dbo.test,which is having data aroung 4000 records.And i need to perform the select statemnt around 8 times in my SP with differenct conditions and need to insert the 8 differenct record set to 8 different tales.Can you please provide solutions to my doubt

May i need to temporary store data in SP,or its better to perform the select statemnt 8 times on the table (dbo.test) itself.
If its better to store temporary in my SP, Which method will be efficient (using temp table or table variable or any other method) I need to create a SP to perform the above action.

Thanks in advance

推荐答案

如果您要从选择中返回一组记录以供以后在同一SP中重新使用,则应使用临时表.出于性能和多用户的原因,表变量(可能是原始表中指示已选择"的字段)不是一个好主意:为了以防万一,您必须一开始就清除所有变量,然后设置它们需要,然后在SP的末尾将其全部清除.
If your are returning a set of records from your select to re-use later within the same SP, then you should use a temporary table. A table variable (presumably a field in the original table which indicates "selected") would not be a good idea, for performance and multi-user reasons: You would have to clear them all at the start just in case, set the ones you want, then clear them all at the end of the SP.


这篇关于避免在同一张桌子上重复选择的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆