简体   繁体   English

如何使用schemabinding创建存储过程?

[英]How to create a stored procedure with schemabinding?

I am trying to create a stored procedure with schemabinding but I am unable to do so. 我试图用schemabinding创建一个存储过程,但我无法这样做。

Error: 错误:

An invalid option was specified for the statement "CREATE/ALTER PROCEDURE" 为“CREATE / ALTER PROCEDURE”语句指定了无效选项

Is it even possible to create stored procedures with schema binding? 甚至可以使用模式绑定创建存储过程吗?

create procedure dbo.proc_GetIncome  (
@fromdate datetime,  
@todate datetime  )
with schemabinding
as  
begin
declare @from varchar(8)  
declare @to varchar(8)  

select @from = YEAR(@fromdate) * 10000 +MONTH(@fromdate) * 100 +DAY(@fromdate)  
select @to = YEAR(@todate) * 10000 +MONTH(@todate) * 100 +DAY(@todate)  

select accountid , las.acctnm ,sum(amt) as Amount from nbfcledger led left join tbl_LASClientmaster las on led.AccountID=las.LasAcctNo  
  where glcode='INTRND' and dr_cr='d' and     
valuedate >= @from and valuedate <= @to  
group by accountid,las.acctnm   
end

Schemabinding is only supported by, and required for, natively compiled stored procedures which were introduced only in SQL Server 2014. 仅仅在SQL Server 2014中引入的本机编译存储过程支持并且必需的模式绑定。

That is why you are getting the error in SQL Server 2008. 这就是您在SQL Server 2008中收到错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM