SHARE
TWEET

Untitled

a guest Apr 19th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Create the Login
  2. ```SQL
  3. CREATE LOGIN [Login]
  4.     WITH PASSWORD = 'password'
  5. GO
  6. ```
  7.  
  8. # Create the User
  9. ```SQL
  10. CREATE USER [User]
  11.     FOR LOGIN [Login]
  12.     WITH DEFAULT_SCHEMA = dbo
  13. GO
  14. ```
  15.  
  16. # Assign the Roles
  17. ```SQL
  18. ALTER ROLE db_datareader ADD MEMBER [User];
  19. ```
  20.  
  21. # Check the Roles
  22. ```SQL
  23. SELECT DP1.name AS DatabaseRoleName,  
  24.    isnull (DP2.name, 'No members') AS DatabaseUserName  
  25.  FROM sys.database_role_members AS DRM  
  26.  RIGHT OUTER JOIN sys.database_principals AS DP1  
  27.    ON DRM.role_principal_id = DP1.principal_id  
  28.  LEFT OUTER JOIN sys.database_principals AS DP2  
  29.    ON DRM.member_principal_id = DP2.principal_id  
  30. WHERE DP1.type = 'R'
  31. ORDER BY DP1.name;  
  32. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top