Minimum Rights for DBCC SHOWFILESTATS

  • Hi,

    i am writing a Java program in which i use DBCC SHOWFILESTATS.

    What a are the necessary minimum rights? Because i don't want to grant the Server Role "System Administrator" - may be there already exsists an work around that an user who has only the role public can use DBCC SHOWFILESTATS.

    Thanks in Advance

    Jürgen

  • I found this: http://www.derkeiler.com/Newsgroups/microsoft.public.sqlserver.security/2003-11/0296.html

    A good way around this is to run it as a job, like every few minutes or whenever, and then store the results in a a table, then grant the user the rights to select from the table.

  • Hi Steve,

    thank you for your suggestion.

    regards

    Jürgen

  • Another workaround to do this with just public level access (and without using an undocumented command) is to use this code:

    SELECT

    File_id FileID, type_desc as FileType,

    size/8*64/1024 as TotalSpaceMB,

    fileproperty(name,'SpaceUsed')/8*64/1024 as UsedSpaceMB,

    size/8*64/1024 - fileproperty(name,'SpaceUsed')/8*64/1024 as FreeSpaceMB,

    name LogicalFilename, physical_name PhysicalFilename

    FROM sys.database_files

    WHERE type in (0,1)

    ORDER BY type

    You can change the system catalog in the query from sys.database_files to sys.master_files to get data for all the databases on the server in one go.

    Amar

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply