anyhow, for the function:
Main Topics
Browse All TopicsHi,
Is there ANY way to create an inline table function that impersonates someone else?
More Details:
Specifically, I want to create a table "TableA" that a user does NOT have permission to see/modify in any way. Then, I want to create a function called FunctionA along the lines of this:
CREATE FUNCTION FunctionA()
RETURNS TABLE
WITH EXECUTE AS N'dbo'
AS
RETURN (SELECT * FROM TableA where TableA.UserName = user_name())
GO
This would create a function that I could use JUST like a table, but which would only let me see/modify/delete the records that were associated with MY username. All other data would be filtered out by the function and since my username would NOT have access to the table directly - I would have secure access to my data only. Does that make any sense?
Anyway - I've been going around and around with INLINE TABLE functions (which don't seem to allow WITH EXECUTE AS) and MULTILINE table functions which don't seem to allow INSERT INTO in the way that INLINE TABLE functions do.
Any suggestions?
Thanks.
EJ
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yeah - that's what I've been playing with. If I run the following insert statement on FunctionA and I have permission to insert into the underlying table - then everything works great. What I'm trying to create is a Function (or view) that I can insert into as below, where I _DON'T_ have access to the underlying table, but am still able to insert data into the view or function by controlling permissions on THAT object instead. Does that make sense?
I CAN insert into a function - I've done it. You can (at least in 2005) insert into an inline table function. I have the following function and I can insert into it:
CREATE FUNCTION [Test] ()
RETURNS TABLE
AS
RETURN SELECT ID FROM foo WHERE username = user_name();
GO
I suppose from SQL Server's point of view (no pun intended :), this basically is a view - but since it's a function I can pass parameters into it - and I can use it like a regular table, selecting, inserting and deleting from it...
That being said, if I deny select/insert on the table, but allow it on the view, that works? I'll be able to insert into the view, but not into the table? That's fantastic. I'll give that a try - thanks.
EJ
Business Accounts
Answer for Membership
by: angelIIIPosted on 2008-06-30 at 13:49:55ID: 21902923
actually, a VIEW would do just the same.
Select allOpen in new window