Routine SELECT Queries


The below query to get result for SQL server Installation information


SELECT
    SERVERPROPERTY('productversion') AS 'Product Version',
    SERVERPROPERTY('productlevel') AS 'Product Level',
    SERVERPROPERTY('edition') AS 'Product Edition',
    SERVERPROPERTY('buildclrversion') AS 'CLR Version',
    SERVERPROPERTY('collation') AS 'Default Collation',
    SERVERPROPERTY('instancename') AS 'Instance',
    SERVERPROPERTY('lcid') AS 'LCID',
    SERVERPROPERTY('servername') AS 'Server Name'

The below query is to get total size and actual space used for particular database (SQL server 2005/2008).


SELECT name                 AS [File Name],
       physical_name        AS [Physical Name],
       size / 128           AS [Total Size in MB],
       size / 128.0  CAST(
       FILEPROPERTY(name, 'SpaceUsed' ) AS INT) /
       128.0 AS [Available Space In MB]
FROM   sys.database_files;

Thanks 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: