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

Sql 如何使用schemabinding创建存储过程?,sql,sql-server,sql-server-2008,tsql,stored-procedures,Sql,Sql Server,Sql Server 2008,Tsql,Stored Procedures,我正在尝试使用schemabinding创建一个存储过程,但我无法这样做 错误: 为语句“CREATE/ALTER PROCEDURE”指定的选项无效 甚至可以使用模式绑定创建存储过程吗 create procedure dbo.proc_GetIncome ( @fromdate datetime, @todate datetime ) with schemabinding as begin declare @from varchar(8) declare @to varcha

我正在尝试使用schemabinding创建一个存储过程,但我无法这样做

错误:

为语句“CREATE/ALTER PROCEDURE”指定的选项无效

甚至可以使用模式绑定创建存储过程吗

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
创建过程dbo.proc\u GetIncome(
@fromdate日期时间,
@当前日期(时间)
诡计多端
作为
开始
从varchar声明@(8)
声明@to varchar(8)
选择@from=年(@fromdate)*10000+月(@fromdate)*100+天(@fromdate)
选择@to=年(@todate)*10000+月(@todate)*100+天(@todate)
选择accountid、las.acctnm、sum(amt)作为nbfcledger led左连接tbl_LASClientmaster las on led的金额。accountid=las.LasAcctNo
其中glcode='INTRND'和dr_cr='d'和

valuedate>=@from和valuedateSchemabinding仅受SQL Server 2014中引入的支持,并且是必需的


这就是SQL Server 2008中出现错误的原因。

您有什么版本的服务器?@Igor ms SQL Server 2008“普通”T-SQL存储过程不支持schemabinding-仅支持“视图”在SQL Server 2008中有一个schemabinding选项。正如您在联机丛书中看到的,SQL Server 2008中的存储过程没有schemabinding选项,我不知道这一点。非常感谢。顺便问一下,附近有什么工作吗?我希望防止任何人对已在此过程中使用的表进行任何更改,从而使过程不起作用。@Arbaaz我知道的唯一方法是拒绝此表的
ALTER
权限。