Skip to content

SQL Server 2012: How to create a Server Role?

Recently, during one of my missions, a client asked me to give him access rights to the SQL Server logs from SSMS to his application managers. As you know, you must grant the role “securityadmin” to have such rights. However, with this role you can also manage logins, CREATE DATABASEs and change passwords.

These are “too many rights” for an IT manager, but there seems to be no other way 😥  … or is there?

Of course, SQL Server 2012 can resolve this problem! How?

  •  Since SQL Server 2012, you can create your own server roles.

Step 1: Create a user for my demo

I can create a simple SQL server user with the right to be owner of the famous AdventureWorks Database.

Createuser1

I can connect to SSMS (SQL Server Management Studio) with this account.

 Connection

Let’s try to look up the SQL Server Logs…

ReadingLogsError

In the error message, we can read:

“Only members of the securityadmin role can execute this stored procedure” Error 15003

Naturally, the easiest way is to give “securityadmin” role to my user Appli_Responsable, but I don’t want this user to be able to create new databases or new users.
My new choice is to do my own role to read the logs:-D

Step 2: Create a new server role

Connect to your instance with sysadmin rights and then you can use the wizard or type directly in a query.

In my example, I created the server role “ReadingSQLServerLogs”

I then granted the “VIEW SERVER STATE” to my role and the “CONNECT” by default.

These rights are sufficient to read the logs.

AddRole

Now, we can grant this role to the user Appli_Responsable like this:

GiveRoleToUser

Step 3: Read the Logs

Let’s connect my user and…hohoho…:-)…I can read logs!

ReadLogFile

To finish my demo, I tried to create a database and a user and I cannot … not enough rights!

These two pictures are proof:

CreateDatabase

CreateUser

Conclusion

I just wanted to present this new simple and useful feature to you. I hope this gives you some good ideas for the security of your databases in the future!

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Stéphane Haby

Stéphane Haby

Stéphane Haby has more than 20 years of experience in Microsoft solutions, specializing in the installation, migration, best practices, and performance analysis of Microsoft SQL Server, as well as Microsoft Business Intelligence solutions (SharePoint, Office) and .NET development for the banking sector. A former Microsoft Most Valuable Professional (MVP) and early adopter of Microsoft Team System in France, he has authored several technical articles. He holds Microsoft Certified Solutions Associate (MCSA) and Expert (MCSE) for SQL Server, MCTS, MCITP for SQL Server 2008, and ITIL V3 Foundation certifications. His industry experience covers chemicals and pharma, banking, and financial services.View Author posts

182 posts since April 2011

Most read in Database

The Database posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *