SQL存储过程编译 [英] SQL Stored procedure Compilation
本文介绍了SQL存储过程编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要添加存储过程中用于不同结果集的条件.
此SP将只编译一次还是每次我从UI调用sp时都编译一次?
即
I am adding if conditions in stored procedure for different results set.
will this SP compiled only once or every time it will compile whenever i will call sp from UI?
i.e
Create Procedure MyExample
(
@key varchar(10)
)
as
if @key='abc'
begin
select * from MyTable1
end
If @key='xyz'
begin
select * from MyTable2
end
推荐答案
SP在创建时被编译",无法解释.但是,如果需要动态部件,可以使用动态查询执行,如此处所述:在存储过程中构建动态SQL [
The SP is "compiled" on creation, it is not interpreted. But you can use dynamic query execution if you want dynamic parts, like described here: Building Dynamic SQL In a Stored Procedure[^]
这篇关于SQL存储过程编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文