Mary_99

last lab

Jan 15th, 2020
2,802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.21 KB | None | 0 0
  1. --1 Create three logins called ann, burt, and chuck.
  2. --The corresponding passwords are a1b2c3d4e5, d4e3f2g1h0, and f102gh285, respectively.
  3. --The default database is the sample database. After creating the logins, check their existence using the system catalog.
  4.  
  5.  
  6. CREATE LOGIN ann
  7. WITH PASSWORD = 'a1b2c3d4e5'
  8.  
  9. CREATE LOGIN burt
  10. WITH PASSWORD = 'd4e3f2g1h0'
  11.  
  12. CREATE LOGIN chuck
  13. WITH PASSWORD = 'f102gh285'
  14.  
  15. --2 Create three new database usernames for the logins in exercise 4. The new names are s_ann, s_burt, and s_charles.
  16.  
  17. CREATE USER s_ann FOR LOGIN [ann]
  18. CREATE USER s_burt FOR LOGIN [burt]
  19. CREATE USER s_chuck FOR LOGIN [chuck]
  20.  
  21. --3.Create a new user-defined database role called managers and add three members to the role.
  22. --After that, display the information for this role and its members.
  23.  
  24. CREATE ROLE manager
  25. ALTER ROLE manager ADD MEMBER s_ann
  26. ALTER ROLE manager ADD MEMBER s_burt
  27. ALTER ROLE manager ADD MEMBER s_chuck
  28.  
  29. --4. Using the GRANT statement, allow the user s_burt to create tables and the
  30. --user s_ann to create stored procedures in the sample database.
  31.  
  32. GRANT CREATE TABLE TO s_burt
  33. GRANT CREATE PROCEDURE TO s_ann
  34.  
  35. --5. Using the GRANT statement, allow the user s_charles to update the columns lname and fname of the employee table.
  36.  
  37. GRANT UPDATE(emp_lname , emp_fname)
  38. ON employee TO s_chuck
  39.  
  40. --6. Using the GRANT statement, allow the users s_burt and s_ann to read the values from the columns emp_lname and emp_fname
  41. --of the employee table. (Hint: Create the corresponding view first.)
  42.  
  43. CREATE VIEW hehe AS
  44. SELECT emp_lname , emp_fname FROM employee
  45. GRANT SELECT  ON hehe TO s_burt
  46.  
  47. --7. Using the GRANT statement, allow the user-defined role managers to insert new rows in the project table.
  48.  
  49. GRANT INSERT ON project TO manager
  50.  
  51.  
  52. --8. Revoke the SELECT rights from the user s_burt.
  53.  
  54. REVOKE SELECT ON hehe FROM s_burt
  55.  
  56. --9. Using Transact-SQL, do not allow the user s_ann to insert the new rows in
  57. --the project table either directly or indirectly (using roles).
  58.  
  59. DENY INSERT TO s_ann
  60.  
  61.  
  62.  
  63. --10. Display the existing information about the user s_ann in relation to the sample database.
  64. --(Hint: Use the system procedure sp_helpuser.)
  65.  
  66. EXEC sp_helpuser 's_ann'
Advertisement
Add Comment
Please, Sign In to add comment