IT tutorials
 
Technology
 

SQL Server 2012 Security : Database Security (part 3) - Flexible Database Roles, Security Functions

3/28/2014 1:07:01 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

5. Flexible Database Roles

If your database consisted of just a couple of users, it would be very easy for you to manage permission for these users directly. However, in the real world, DBAs manage lots of users and, more commonly, many different types of users. A developer will have different requirements than a business analyst. If your organization has 35 developers and 70 business analysts, you have a lot of permissions to manage. To alleviate this burden, you can create a database role, add database users or other roles to this new role, and assign permissions to the role. Now, any time you have new developers, all you have to do is add their usernames to the role, and they have all the necessary permissions.

To create a database role, use the CREATE ROLE statement, as shown here:

USE AdventureWorks
GO
CREATE ROLE Developers AUTHORIZATION DevManager
GO

Here, you are creating a new role, Developers, and making the DevManager user the owner of this new role. As an owner, you can freely add and remove membership to the role.

To add users to the role, use the sp_addrolemember stored procedure as follows:

sp_addrolemember 'Developers', 'Bryan'

This assumes that there is a database user within the database named Bryan.

Once you defined a role, you can grant permission to the role using the GRANT statement as follows:

GRANT CREATE TABLE TO Developers

Note Even though DevManager may be the owner of the Developers role, DevManager would still need the ability to grant the CREATE TABLE permission in order for the previous statement to work. To do this, the DBA would issue the GRANT statement with the WITH GRANT OPTION clause as follows:

GRANT CREATE TABLE TO DevManager WITH GRANT OPTION

6. Security Functions

Now that you know how to grant, revoke, and deny permissions, I’ll introduce a series of functions that are designed to help you in managing security. Although most of this information is available in SQL Server Management Studio dialog boxes, the following functions and catalog views are useful if you prefer to issue Transact-SQL statements instead of using the UI.

fn_my_permissions() Function

You also granted CREATE TABLE permission to this role. If Bryan wanted to know what permissions he had within this database, he could use SQL Server Management Studio or simply leverage the fn_my_permissions function as follows:

SELECT * FROM fn_my_permissions(NULL, 'DATABASE');

For Bryan, this query would return the information in Table 3.

images

This function also works at the server instance level. By replacing the DATABASE word with SEVER, the function will return the server-level permissions that are granted to the login.

HAS_PERMS_BY_NAME Function

You also learned that users can be members of roles, and these roles can be members of other roles. In the end, if you wanted to really know what permissions a user had on an object, it would be difficult to trace through all these layers of indirection. The function tells you whether the current context has a specific permission. For example, if developer Bryan wanted to know whether he had SELCT permission on the Customers table, he could issue the following query:

SELECT HAS_PERMS_BY_NAME('Customers', 'OBJECT', 'SELECT')

This function will return a 1 or 0, indicating a true or false value, respectively.

If you wanted to know whether another user had a specific permission, you would have to be a sysadmin or have IMPERSONATE permission for the user in question. Provided one of those conditions are satisfied, you could find out whether Bryan has the SELECT permission by issuing the following:

EXECUTE AS USER=’Bryan’
GO
SELECT HAS_PERMS_BY_NAME('Customers', 'OBJECT', 'SELECT')
GO
 
Others
 
- SQL Server 2012 Security : Database Security (part 2) - Fixed Database Roles,Database Permissions
- SQL Server 2012 Security : Database Security (part 1) - Database Users, Schemas
- Windows Server 2012 : Performance Monitoring (part 8) - Resource Monitor - Network Tab
- Windows Server 2012 : Performance Monitoring (part 7) - Resource Monitor - Disk Tab
- Windows Server 2012 : Performance Monitoring (part 6) - Resource Monitor - Processes, Services, Associated Handles, Associated Modules , Memory Tab
- Windows Server 2012 : Performance Monitoring (part 5) - Resource Monitor - Overview Tab , CPU Tab
- Windows Server 2012 : Performance Monitoring (part 4) - Reports - Creating a User-Defined Report , Viewing Predefined System Reports
- Windows Server 2012 : Performance Monitoring (part 3) - Data Collector Sets
- Windows Server 2012 : Performance Monitoring (part 2) - Adding Counters with Performance Monitor
- Windows Server 2012 : Performance Monitoring (part 1) - Performance Monitor Overview
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us