I have a requirement in SQL Server 2008 in development database
- Only DBA’s ( who are database owners ) can create, alter tables .
Developer’s should not create or alter tables . - Developers can create/alter Stored Procedure/User Defined functions
in dbo schema and can execute SP/UDF. - Developers should have SELECT,INSERT,DELETE,UPDATE on tables (
tables in dbo schema
How to achieve this using GRANT statement
Found a sample solution from Google, but still have issue
CREATE LOGIN testdev WITH PASSWORD = 'sldkjlkjlkj 987kj//'
CREATE USER testdev
GRANT ALTER ON SCHEMA::dbo TO testdev
GRANT CREATE PROCEDURE TO testdev
GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::dbo TO testdev
CREATE TABLE mysig (a int NOT NULL)
EXECUTE AS USER = 'testdev'
go
CREATE PROCEDURE slaskis AS PRINT 12
go
CREATE TABLE hoppsan(a int NOT NULL) -- FAILS!
go
INSERT mysig (a) VALUES(123)
go
REVERT
go
DROP PROCEDURE slaskis
DROP TABLE mysig
DROP USER testdev
DROP LOGIN testdev
The syntax above able to block developer to create table but cant block developer to use SSMS design and alter the table.
Thanks.
First of all I would use Roles instead of granting access directly to users. You may be already doing this, but I thought I would mention it.
Okay, the problem here is granting ALTER to the Schema means that the grantee has ALTER access to all object types in the schema. Unfortunately, as far as I know, there is no way to grant permissions to specific object types so it is all or nothing. Conversely, you cannot grant ALTER to all objects and then deny ALTER to specific object types.
The only way I have found to do this is to grant ALTER to the schema and then used a DDL Trigger to control what the role can do.
Here is an updated version of your example demonstrating the principle: