Permissions to create schemas and grant access to specific DB User?

techresearch7777777 1,766 Reputation points
2021-03-28T14:59:53.033+00:00

Hello, what are the permissions-role and syntax necessary to create schemas and grant access to a specific DB user?

Thanks in advance.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,653 questions
0 comments No comments
{count} votes

Accepted answer
  1. CathyJi-MSFT 21,081 Reputation points Microsoft Vendor
    2021-03-29T02:32:42.557+00:00

    Hi @techresearch7777777 ,

    >Permissions for creating schemas;

    Requires CREATE SCHEMA permission on the database.

    To create an object specified within the CREATE SCHEMA statement, the user must have the corresponding CREATE permission.

    To specify another user as the owner of the schema being created, the caller must have IMPERSONATE permission on that user. If a database role is specified as the owner, the caller must have one of the following: membership in the role or ALTER permission on the role.

    >Syntax necessary to create schemas and grant access to a specific DB user;

    The following example creates schema Sprockets owned by Annik that contains table NineProngs. The statement grants SELECT to Mandar and denies SELECT to Prasanna.

    USE AdventureWorks2012;    
    GO    
    CREATE SCHEMA Sprockets AUTHORIZATION Annik    
        CREATE TABLE NineProngs (source int, cost int, partnumber int)    
        GRANT SELECT ON SCHEMA::Sprockets TO Mandar    
        DENY SELECT ON SCHEMA::Sprockets TO Prasanna;    
    GO  
    

    Please refer to MS document CREATE SCHEMA (Transact-SQL).

    Syntax for creating DB user, refer to MS document Create a Database User.


    If the response is helpful, please click "Accept Answer" and upvote it, thank you.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 100.8K Reputation points MVP
    2021-03-28T16:10:12.523+00:00

    So I did this. I went to http://www.google.com. There I entered CREATE SCHEMA in the search box. Luckily, the first was from the T-SQL Reference, https://learn.microsoft.com/en-us/sql/t-sql/statements/create-schema-transact-sql?view=sql-server-ver15. I opened this page. Since I know that the required permissions are listed just before the examples, I went to the end of the page and scrolled upwards. But that is just by habit. There is also a table of contents on top.

    So there you find the answer to that question.

    I leave it as an exercise for you to find the answer for the second part. (I mean, since I don't know the answer by heart, it's either you or I who have look it up.)

    0 comments No comments

  2. techresearch7777777 1,766 Reputation points
    2021-03-30T22:29:43.553+00:00

    Sorry I kind of was more curious what permissions like which DB role is needed if at that level.

    Thanks for the replies.

    0 comments No comments

  3. Erland Sommarskog 100.8K Reputation points MVP
    2021-03-31T21:29:31.727+00:00

    Sorry I kind of was more curious what permissions like which DB role is needed if at that level.

    Most topics have roles listed in the Permissions section, but there isn't one for CREATE SCHEMA. I did a quick test, and it seems that db_ddladmin is sufficient. Obviously, db_owner will also work.

    For creating user, I guess you are looking for db_securityadmin, but I did not test, nor check the documentation.

    0 comments No comments