Use [iDBA]
GO
--Step 1 - create a SQL Server login
Create LOGIN [ClarkKent] WITH
PASSWORD = 'NotTheRealPassword'
--Step 2 -
create a Database user for the login
Create USER [ClarkKent] FOR
LOGIN [ClarkKent]
--Step 3: Create
a user-defined database role
CREATE ROLE [MyDevelopers]
--Step 4 - Add
the user-defined database role to the fixed database role
--allow the users
to read data
EXEC sp_addrolemember N'db_datareader',
N'MyDevelopers'
--Step 5 -
assign additional permissions to the database role
--allow the
users to see view proc and function definitions
Grant View Definition ON SCHEMA :: [dbo] To
[MyDevelopers]
-- Step 6:
finally add the user to the role:
EXEC sp_addrolemember N'MyDevelopers',
N'ClarkKent'
--step 7: test:
EXECUTE AS USER = 'ClarkKent'
--who am i?
SELECT
SUSER_NAME()
--do stuff
--change back
into superman
REVERT;
--clean up after
ourselves
/*
DROP ROLE
[MyDevelopers]
DROP USER
[ClarkKent]
DROP LOGIN
[ClarkKent]
*/
see http://www.sqlservercentral.com/Forums/Topic1259555-1526-1.aspx#bm1259574 for the original post.