patternsqlMinor
SQL Server database level roles for creating tables
Viewed 0 times
tablessqllevelrolescreatingdatabaseforserver
Problem
Is there a way to create or change a special role for creating tables? Our software developer team has
I read this article related to database level roles. I don't want to grant
So my question is how can i give creating and deleting tables permissions for a database? Views, procedures and functions are okay too. All I need is I don't want to grant permissions related to security, login or backup operations.
db_datareader and db_datawriter roles but they can not create new tables.I read this article related to database level roles. I don't want to grant
db_ddladmin role because there is too much permissions in this role.So my question is how can i give creating and deleting tables permissions for a database? Views, procedures and functions are okay too. All I need is I don't want to grant permissions related to security, login or backup operations.
Solution
If you want to create a role with specific rights, you could do this:
Create the test user:
Add the user to the role:
Test the user's permissions:
Result
Or like Tom stated, add the user to the db_ddladmin role.
CREATE ROLE CreateObjects
GRANT CREATE TABLE TO CreateObjects
GRANT CREATE VIEW TO CreateObjects
GRANT CREATE FUNCTION TO CreateObjects
GRANT CREATE PROCEDURE TO CreateObjects
GRANT ALTER ANY SCHEMA TO CreateObjectsCreate the test user:
CREATE LOGIN testlogin with password = 'StrongP@SSWORD123'
CREATE USER Testlogin FOR LOGIN TestloginAdd the user to the role:
ALTER ROLE CreateObjects ADD MEMBER TestloginTest the user's permissions:
EXECUTE AS LOGIN = 'testlogin'
SELECT SUSER_NAME(),USER_NAME()
(No column name) (No column name)
testlogin Testlogin
CREATE TABLE dbo.test(id int)
DROP TABLE dbo.test
REVERTResult
Commands completed successfully.Or like Tom stated, add the user to the db_ddladmin role.
ALTER ROLE db_ddladmin ADD MEMBER testloginCode Snippets
CREATE ROLE CreateObjects
GRANT CREATE TABLE TO CreateObjects
GRANT CREATE VIEW TO CreateObjects
GRANT CREATE FUNCTION TO CreateObjects
GRANT CREATE PROCEDURE TO CreateObjects
GRANT ALTER ANY SCHEMA TO CreateObjectsCREATE LOGIN testlogin with password = 'StrongP@SSWORD123'
CREATE USER Testlogin FOR LOGIN TestloginALTER ROLE CreateObjects ADD MEMBER TestloginEXECUTE AS LOGIN = 'testlogin'
SELECT SUSER_NAME(),USER_NAME()
(No column name) (No column name)
testlogin Testlogin
CREATE TABLE dbo.test(id int)
DROP TABLE dbo.test
REVERTCommands completed successfully.Context
StackExchange Database Administrators Q#225359, answer score: 9
Revisions (0)
No revisions yet.