Create DB User and Assign Role in SQL Server

In some scenario we need to create the db user and assign the some db role to that user. here is the script which will create the user and role.

  1. USE Portal_PS;  
  2. GO  
  3. GRANT EXECUTE TO db_executor;  
  4. GO  
  5.   
  6. CREATE USER DBUser for LOGIN DBUser;  
  7. GO  
  8. EXEC sys.sp_addrolemember 'db_datareader','DBUser';  
  9. GO  
  10. EXEC sys.sp_addrolemember 'db_datawriter','DBUser';  
  11. GO  
  12. EXEC sys.sp_addrolemember 'db_executor','DBUser';  
  13. GO  
In this scripts we are giving the DBuser to three roles.
Ebook Download
View all
Learn
View all