Alexander Chigrikchigrik@hotmail.comAlexander Chigrik's Home
Roles are the new SQL Server 7.0 feature, which was not available in the previous versions. SQL Server roles act like Windows NT local groups. SQL Server 7.0 supports several different types of roles. There are:
Server roles are defined at the server level and exist outside of users databases. There are only fixed server roles, so you cannot add, delete or modify server role. You can only add users as a member of a server roles. There are seven fixed server roles:
sp_addsrvrolemember [@loginame =] 'login', [@rolename =] 'role'
sp_dropsrvrolemember [@loginame =] 'login', [@rolename =] 'role'
sp_helpsrvrole [[@srvrolename =] 'role']
In SQL Server 6.5 you can use database groups to simplify management of a large number of database users. For example, you can use database groups to grant and revoke permissions to more than one user at the same time. But database groups are no longer supported in SQL Server 7.0. SQL Server database roles act like SQL Server 6.5 database groups, but roles have some improvements: in SQL Server 6.5 each user can be a member of only one group (in addition to public group), but in SQL Server 7.0 each user can belong to many roles and the result users permissions are combined for all roles they're members of. There are three kinds of the database roles:
Fixed database roles are defined at the database level and exist in each database. You cannot add, delete or modify fixed database roles. You can only add users as a member of a fixed database roles. There are nine fixed database roles:
sp_addrolemember [@rolename =] 'role', [@membername =] 'security_account'
sp_droprolemember [@rolename =] 'role', [@membername =] 'security_account'
sp_helprolemember [[@rolename =] 'role']
The public role is a special database role to which every database user belongs. The public role contain default access permissions for any user who can access the database. This database role cannot be dropped.
Although the built-in database roles handle permissions for common database management tasks, it's likely that you will want to group users who have access to perform specific database functions. To create a new SQL Server role in the current database, you can use sp_addrole system stored procedure. This is the syntax: sp_addrole [@rolename =] 'role' [,[@ownername =] 'owner'] where @rolename - is the name of the database role. @ownername - is the owner of the new role. See this link for more information sp_addrole (T-SQL) To remove a SQL Server role from the current database, you can use sp_droprole system stored procedure. This is the syntax: sp_droprole [@rolename =] 'role' where @rolename - is the name of the role. See this link for more information sp_droprole (T-SQL)
sp_addrole [@rolename =] 'role' [,[@ownername =] 'owner']
sp_droprole [@rolename =] 'role'
Application roles are the SQL Server roles created to support the security needs of an application. Often database applications enforce their own security based on the application logic. For example, you can use application role with its own password to allow the particular user to obtain and modify any data only during specific hours. So, you can realize more complex security management within the application logic. To add a special type of role in the current database, which is used for application security, you can use sp_addapprole stored procedure. This is the syntax: sp_addapprole [@rolename =] 'role', [@password =] 'password' where @rolename - is the name of the application role. @password - is the password for the new application role. See this link for more information sp_addapprole (T-SQL) To remove an application role from the current database, you can use sp_dropapprole system stored procedure. This is the syntax: sp_dropapprole [@rolename =] 'role' where @rolename - is the name of the application role. See this link for more information sp_dropapprole (T-SQL) To change the password of an application role in the current database, you can use sp_approlepassword system stored procedure. This is the syntax: sp_approlepassword [@rolename =] 'role', [@newpwd =] 'password' where @rolename - is the name of the application role. @newpwd - is the new password for the application role. See this link for more information sp_approlepassword (T-SQL)
sp_addapprole [@rolename =] 'role', [@password =] 'password'
sp_dropapprole [@rolename =] 'role'
sp_approlepassword [@rolename =] 'role', [@newpwd =] 'password'
To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.
We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:
We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.
Steve Jones Editor, SQLServerCentral.com