Describe the different type of roles in SQL Server.
Describe the different type of roles in SQL Server.
563
15-Jul-2024
Updated on 16-Jul-2024
Ashutosh Kumar Verma
16-Jul-2024SQL Server Roles
A role is a set of permissions. Functions help simplify route planning. For example, instead of assigning permissions to individual users, you can group permissions into roles and add users to those roles.
SQL Server Role Type
SQL Server provides you with three main role types,
Server-level Roles – manage the permissions on SQL Server, like changing server configuration.
Database Level Roles – Manage permissions on databases such as creating tables and querying data.
Application level Role– Allow applications to run with their own, user-like permissions.
SQL Server provides two types for each role,
Fixed server roles are created roles provided by SQL Server. These functions have fixed licenses.
User-defined roles creates a role that you define to meet a specific security need.
Adding a user to a Role
First, create a new login called
testLoginNow, switch the current database to
MyCollegeDband create a user fortestLoginloginThen, connect to the
MyCollegeDbdatabase using userMyUser. UserMyUsercan view theMyCollegeDbdatabase but cannot see any database objects.After that, add the user
MyUserto thedb_datareaderrole.db_datareaderis a fixed database role. Thedb_datareaderrole allows all members to read data from all user tables and views in the database. Technically, it is equivalent to the followingGRANTstatementIn this example,
DATABASEis a class type that comes after::indicating a separable that is a database. Following are the available class types,Finally, switch the connection to the user
MyUserand select data from thedbo.Employeestable,Also, Read: How to create user-defined role in SQL Server Database?