Published on

February 26, 2016

Granting Permissions to Create/Alter Stored Procedures and Views in SQL Server

Have you ever wondered how to grant the ability to create or alter stored procedures and views in SQL Server? It’s a question that often comes up, and there are two major methods to accomplish this.

The Scalpel

If you’ve explored the permissions available in SQL Server, you may have noticed the “CREATE PROCEDURE” and “CREATE VIEW” permissions. At first glance, it seems like granting these permissions would solve the problem. However, it’s not as straightforward as it appears.

Granting a user the “CREATE VIEW” and “CREATE PROCEDURE” permissions alone will not give them the ability to create procedures or views. This may seem counterintuitive, but it makes sense when you think about it. While these permissions allow users to create objects, they don’t provide a place to store them.

In SQL Server, schemas act as containers for most objects in databases. In order to change a schema by adding an object to it, the user needs the “ALTER” permission on that schema. Therefore, to make the “CREATE” permissions work, you need to:

GRANT CREATE VIEW TO [UserName];
GRANT CREATE PROCEDURE TO [UserName];
GRANT ALTER ON SCHEMA::[dbo] TO [UserName];

By following these steps, the user with the specified username will be able to create, alter, and drop views and procedures within the “dbo” schema. The order in which you run these commands doesn’t matter.

The Sledgehammer

Another option is to add the user to the “db_ddladmin” role. This can be useful in certain situations, but it’s important to note that it grants far more permissions than just the ability to create or alter objects.

The “db_ddladmin” role provides the user with the ability to create, alter, and drop any object in the database, regardless of the schema. While this can be convenient, it’s often more permissions than you actually need to grant. It’s like using a sledgehammer to remove the wing from a fly.

Instead, it’s recommended to only grant the permissions that are actually required for the user. This ensures that they have the necessary access without granting unnecessary privileges.

Granting permissions to create or alter stored procedures and views in SQL Server requires a careful understanding of schemas and the appropriate permissions. By following the steps outlined above, you can provide users with the necessary access while maintaining security and control over your database.

Filed under: Microsoft SQL Server, Security, SQLServerPedia Syndication

Tagged: microsoft sql server, security

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.