Category: SQL Server

  • ORIGINAL_LOGIN() and SUSER_SNAME() functions

    ORIGINAL_LOGIN() function returns the name of the original login that connected to the instance of SQL Server and is used to identify original login in all sessions. Even though you will do the security context switch it will return the original login name.

    SUSER_SNAME returns the name of user in the current security context.

    --connect SQL Using LoginDEMO account
    SELECT ORIGINAL_LOGIN() Original_Login_func, SUSER_SNAME() Suser_Name_Login_Func
    
    --Executing query using LoginTest account
    execute as login = 'LoginTest'
    SELECT ORIGINAL_LOGIN() Original_Login_func, SUSER_SNAME() Suser_Name_Login_Func
    revert
    
    --Again executing query be reverting the change
    SELECT ORIGINAL_LOGIN() Original_Login_func, SUSER_SNAME() Suser_Name_Login_Func
    

    Check below output image for more information. I connected SQL Server using LoginDemo account.
    New

  • How to monitor SQL Server Services of multiple instances?

    Problem:
    I have a need to monitor the SQL Server Services in my environment. Are there any programmatic options to do so? Check out this tip to learn more.

    Solution:
    http://www.mssqltips.com/sqlservertip/2867/steps-to-monitor-the-sql-server-services/

  • Get the List Of DBCC Commands & Syntax

    If you don’t remember all the DBCC commands “NO Issue” execute the DBCC HELP command to get the list of all the DBCC.

    DBCC HELP('?')
    

    checkalloc
    checkcatalog
    checkconstraints
    checkdb
    checkfilegroup
    checkident
    checktable
    cleantable
    dbreindex
    dropcleanbuffers
    free
    freeproccache
    freesessioncache
    freesystemcache
    help
    indexdefrag
    inputbuffer
    opentran
    outputbuffer
    pintable
    proccache
    show_statistics
    showcontig
    shrinkdatabase
    shrinkfile
    sqlperf
    traceoff
    traceon
    tracestatus
    unpintable
    updateusage
    useroptions

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    Don’t remember syntax, execute below command to get the syntax.

    DBCC HELP('checktable')
    

    DBCC

  • Script to get the SQL Agent Properties

    You can use the sp_get_sqlagent_properties undocumented stored procedure to retrieve the SQL Agent properties of a SQL Instance. It is available in SQL Server MSDB database. This procedure only works if the SQL Agetn Service is started.

    SQLAgent