如何使特定用户可以访问存储过程

时间:2016-06-04 06:43:53

标签: sql-server stored-procedures

我使用SSMS 10.50访问SQL Server 2008 R2和我是SQL编码的新手。我的登录ID是SA。我创建了一个存储过程,我想让它由特定用户执行。但我没有这样做。

当我写这些行时,

<title>Barry bounce</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.js"></script>

  </head>
  <body ng-app="myApp">


<div class="main" ng-controller="MainController">
<span ng-model="barry.test1"> </span


</div>

<!-- Modules -->
<script src="js/app.js"></script>

<!-- Controllers -->

<script src="js/controllers/MainController.js"></script>

  </body>
</html>

我收到此错误

create proc GetCustomerDetailsCompanyWise
    (@comp varchar(40))
as
begin
    grant execute on GetCustomerDetailsCompanyWise to [sgp\deepak.b]
    execute AS USER='sgp\deepak.b'; 

    select * 
    from DD_Customer 
    where Company = @comp;
end 

exec GetCustomerDetailsCompanyWise 'Google'

你能解释一下我可能做错了什么,我该如何解决?

2 个答案:

答案 0 :(得分:2)

首先创建程序

create proc GetCustomerDetailsCompanyWise
    (@comp varchar(40))
as
begin
    select * 
    from DD_Customer 
    where Company = @comp;
end
go

然后授予权限

grant execute on GetCustomerDetailsCompanyWise to [sgp\deepak.b];
go

然后尝试运行它。

答案 1 :(得分:0)

REVERT;之前添加end以恢复到之前的用户状态。然后从SP中删除grant语句。然后创建SP。然后运行:

grant connect on TEMP to [sgp\deepak.b];
grant select on TEMP to [sgp\deepak.b];
grant execute on GetCustomerDetailsCompanyWise to [sgp\deepak.b];