Category: Database

  • sys.sql_logins

    sys.sql_logins: Returns one row for each SQL Server authentication login. It will return all the below columns.

    • name
    • principal_id
    • sid
    • type
    • type_desc
    • is_disabled
    • create_date
    • modify_date
    • default_database_name
    • default_language_name
    • credential_id
    • is_policy_checked
    • is_expiration_checked
    • password_hash

    You can query sys.sql_logins to get all the below information.

    SQL Logins which are disabled:

    SELECT name  
    FROM [sys].[sql_logins] 
    WHERE [is_disabled] = 1; 
    

    SQL Server Logins which adhere the password policy:

    SELECT name  
    FROM [sys].[sql_logins] 
    WHERE [is_policy_checked] = 1;
    

    SQL Server Logins which do not adhere to the password policy

    SELECT name  
    FROM [sys].[sql_logins] 
    WHERE [is_policy_checked] = 0;
    

    SQL Logins which do not adhere to password expiration

    SELECT name  
    FROM [sys].[sql_logins] 
    WHERE [is_policy_checked] = 0 
       OR  ([is_policy_checked] = 1 AND [is_expiration_checked] = 0);
    
  • Update Statistics Useful Scripts

    Script to find out the statistics update date for all the indexes in the current database

    sp_MSforeachtable 'sp_autostats "?"'
    

    Script to update the statistics of all the indexes

    EXEC sp_MSforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN'
    
  • How to check Lock Pages In Memory is enabled?

    You can use below simple technique to check whether lock pages in memory is enabled or not. If lock pages in memory is enabled you can see the “Using locked pages for buffer pool” message in the SQL Server error log.

    exec xp_readerrorlog 0, 1, 'locked pages' 
    

    To check if it is disabled. You have to check for the “Address Windowing Extensions (AWE) requires the ‘lock pages in memory’ privilege which is not currently present in the access token of the process.” message.

    exec xp_readerrorlog 0, 1, 'lock pages in memory' 
    
  • T-SQL script to Identify the SQL Server version and edition

    Execute below T-SQL Script to get the SQL Server version details.

    SELECT SERVERPROPERTY ('productversion') as ProductVersion,
    SERVERPROPERTY ('productlevel') as Productlevel,
    SERVERPROPERTY ('edition') as Edition
    

    Output:
    -Product version (for example, 10.0.1600.22)
    -Product level (for example, SP3)
    -Edition (for example, Development)

    SQL Server 2012 version number examples
    11.0.2316 SQL Server 2012 CU1
    11.0.2100.6 SQL Server 2012 RTM

  • Different ways to make a table read only in a SQL Server database

    Problem

    In some cases there may be a need to make a SQL Server table read only. There are several different options for doing this and in this tip we cover various ways that you can make a table read only in a SQL Server database.

    Solution

    http://www.mssqltips.com/sqlservertip/2711/different-ways-to-make-a-table-read-only-in-a-sql-server-database/#comments