Select permissions

Hram Admin 80 Reputation points
2025-02-28T13:47:07.2233333+00:00

Hello!

While creating reports using bcp utility -

*bcp "select Name, physical_name, state_desc, (size)8/1024, ... from msdb.sys.database_files ORDER BY Name" queryout C:\REPORTS\SQ\LUSERDB.txt -c -T

...

*bcp "select Name, physical_name, state_desc, (size)8/1024, ... from USERDB.sys.database_files ORDER BY Name" queryout C:\REPORTS\SQ\LUSERDB.txt -c -T

I noticed that if the account under which the command is run is te member of only the default public role, the command would not produce any output, although it seems the publc role membership should be enough to select from [].sys.database_files:

sql1

For selecting from system databases (master, msdb) I had to add the account to severadmin role, for selecting from any user databases - to sysadmin role.

**Q: Doesn't the picture above means the membership of the Public role alone should be sufficient for selecting from [].**sys.database_files ?

Regards,

Michael

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
147 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 119K Reputation points MVP
    2025-02-28T22:25:51.6566667+00:00

    When it comes to the catalog views there are several layers of security. Public membership is sufficient to query the view as such, but you need further permissions to see any actual data. Exactly what permissions depend on the view.

    As one example run this in a database that has a couple of tables:

    CREATE USER tillfällig WITHOUT LOGIN
    CREATE TABLE tillfällig (a int NOT NULL)
    GRANT SELECT ON tillfällig TO tillfällig
    go
    EXECUTE AS USER = 'tillfällig'
    go
    SELECT * FROM sys.tables
    go
    REVERT
    go
    DROP USER tillfällig
    DROP TABLE tillfällig
    

    The temporary user (tillfällig is Swedish for temporary) can only see the table tillfällig, not the other tables as it lacks permission to them.


1 additional answer

Sort by: Most helpful
  1. LiHongMSFT-4306 31,001 Reputation points
    2025-03-03T03:15:46.46+00:00

    Hi @Hram Admin

    Regarding the Public Role, when a server principal isn't granted or denied specific permissions on a securable object, the user inherits the permissions granted to public on that object.

    I noticed that if the account under which the command is run is te member of only the default public role, the command would not produce any output

    The reason might be the public role does not include the necessary permissions for exporting data via the bcp utility.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.