存储过程 函数 预编译
书本上,网络上一直在强调存储过程有预编译,执行起来会比单独的SQL语句快,这个好理解。
那自定义函数呢?网上有说它有预编译,有说它没有预编译的。书本上也没有给出一个明确的说法。
在下初学SQLserver不清楚到底是怎么一个情况。想请教一下大家。
[解决办法]
Select Newid();
GO
Create function dbo.fn(@n int)returns int/*C51634A6-6FA3-45FF-BA76-EC82CEB6A498*/
as
Begin
return @n+1;
End
Select *
From sys.syscacheobjects
Where sql like '%C51634A6-6FA3-45FF-BA76-EC82CEB6A498%'
select dbo.fn(number) as vl
From master..spt_values
Where type = 'P'
And number < 11
---------------------------------------
11074Compiled PlanProc539148966121212324347303000000216Create function fn(@n int)returns int/*C51634A6-6FA3-45FF-BA76-EC82CEB6A498*/ as Begin return @n+1; End
14500Compiled PlanAdhoc719910009120-224454347303000000182Select * From sys.syscacheobjects Where sql like '%C51634A6-6FA3-45FF-BA76-EC82CEB6A498%'