【发布时间】:2014-05-04 05:49:56
【问题描述】:
我有一个这样的存储过程:
ALTER PROCEDURE [dbo].[IBS_fetchrequested]
@tid integer = null,
@Tbaroced dbo.TBarcode readonly
as
begin
SET NOCOUNT ON;
if (select COUNT(*) from Khanger_tbl
where tid = @tid and requested = 1 and delivered = 0) > 0
begin
select
t.TBarcode, k.HBarcode as keyloc
from
Khanger_tbl k
inner join
transaction_tbl t on k.transactid = t.transactID
where
tid = @tid
and requested = 1
and delivered = 0
and t.Tbarcode not in (select carid from @Tbaroced)
and t.status = 3
end
end
在我的数据库中,我有大约 2 条缺失记录。如果我在 Khanger_tbl 中的 tid 上添加索引,我的存储过程性能会提高吗?如何提高这些存储过程的性能?还有什么技巧吗?
感谢任何帮助!
如果我添加一个索引,它将如何影响我的插入和更新? 我该如何优化这个?
【问题讨论】:
-
where子句中引用的列(tid、requested、delivered、status、barcode),它们属于哪些表? -
tid,requested,delivered 属于 Khanger_tbl 和 status,barcode 属于 transaction_tbl
-
为什么在运行查询之前检查表中是否存在记录?
标签: sql-server sql-server-2008 stored-procedures