Thursday, August 14, 2008

EXECUTE AS Clause (SQL Server 2005)

In sql server 2005, it is possible to run a proc/function with the credentials of an other user by using "execute as". However it has some limitations (http://msdn.microsoft.com/en-us/library/ms188354.aspx)


create table tbl_test (id int)
go
create proc proc_test
WITH execute as 'm7805'
as
insert into tbl_test values(8)
go
grant execute on proc_test to m7805_2


with user m7805_2:
insert into tbl_test values(8)
The INSERT permission was denied on the object 'tbl_test', database 'pubs', schema 'dbo'.
select * from tbl_test
The SELECT permission was denied on the object 'tbl_test', database 'pubs', schema 'dbo'.

exec proc_test --inserts the record

No comments: