Accessing a table in stored procedure or table valued function using a different users rights

Hi,

I am working on a project that completly run on SQL Server 2008. I have to write some stored procedures and table valued function with T-SQL or CLR for making some operations. In my database has several tables but users do not have right to access all of these tables. But users must access these tables to do these operations (For example inserting records to log table). DB administrator says that Log table can only be accessible from these stored procedure and table valued function for these users. Because some users added some illegal records to log table and change some other tables in the past. We want to control these user behaviors.

How can i do this
Thanks in advance
chelvaciAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jorge_torizResearch & Development ManagerCommented:
If you give them the EXECUTE permission on your stored procedures then, with your stored procedure they will be able to modify the content of your tables
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jorge_torizResearch & Development ManagerCommented:
Test with this
USE master
GO
CREATE LOGIN testSecurity
WITH PASSWORD = '1234', CHECK_POLICY = 'OFF', CHECK_EXPIRATION = 'OFF'
GO
USE AdventureWorks
GO
CREATE USER testSecurity
FOR LOGIN testSecurity
GO
CREATE TABLE Test(
  Id INT
)
GO
CREATE PROC pInsertIntoTest(
   @Id INT
)
AS
BEGIN
  INSERT INTO Test VALUES (@Id)
END
GO
GRANT EXECUTE ON pInsertIntoTest TO testSecurity
 
--Now log on as testSecurity and test your stored procedure
EXEC pInsertIntoTest 10
--Try to read with your testSecurity user
SELECT * FROM Test
--Try to insert with your testSecurity user
INSERT INTO Test VALUES(11)
--In both cases you will get an error
 
--Now log on as the db_owner (or a user within db_datareader role) and then execute this
SELECT * FROM Test
--You will see your "10" value inserted

Open in new window

0
chelvaciAuthor Commented:
Thank you very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.