Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Databases»SQL Server»How to Find Currently Running Query in SQL Server

    How to Find Currently Running Query in SQL Server

    RahulBy RahulMay 9, 20171 Min ReadUpdated:May 11, 2017

    This can be an important query for your while debugging slowness of SQL server. This will help you find currently running SQL queries on SQL Server. You can find which queries are running from a long time and utilizing CPU.

    To run this query, start SQL Server Management Studio, Open New Query window and copy below query in it. Now click on Execute button to run this query.

    PgSQL
    1
    2
    3
    4
    5
    6
    7
    8
    9
    SELECT sqltext.TEXT,
    req.session_id,
    req.status,
    req.start_time,
    req.command,
    req.cpu_time,
    req.total_elapsed_time
    FROM sys.dm_exec_requests req
    CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

    Run the above query using SQL server management studio. The result will be different than below screenshot.

    Output Details:

    TEXT: The query is being executed.
    session_id: Session id assigned to query. We can use this id to kill this query
    status: Current status of the query
    Start_time: The time query was started.

    query SQL SErver
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install RabbitMQ Server on Ubuntu 18.04 & 16.04 LTS
    Next Article How to Install Erlang on CentOS/RHEL 7/6

    Related Posts

    How to Backup SQL Server Database

    Updated:June 28, 20212 Mins Read

    How To Restore SQL Server Database

    Updated:July 12, 20213 Mins Read

    How to Rename a SQL Server Database

    Updated:June 21, 20213 Mins Read

    (Fixed) Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724)

    Updated:June 23, 20211 Min Read

    How to Rename a Column in SQL Server

    Updated:June 28, 20212 Mins Read

    FIXED MSSQL Error 3154 – The backup set holds a backup of a database other than the existing database

    Updated:October 15, 20161 Min Read

    6 Comments

    1. Peter on August 23, 2019 9:28 am

      This is a really useful query, is it possible to add the user that has run the query? Be it server log in name or the PC they are running it from?
      Knowing the query is really useful but when you have 50+ users narrowing it down to user would take it to the next level

      Reply
    2. Discolicht on August 20, 2019 5:24 pm

      Τhis paragraph іs really a pleasant one it helps neѡ weeb uѕers, who аre wishing fߋr blogging.

      Reply
    3. Vj on March 22, 2019 3:54 am

      Adding the following condition prevents the SQL from returning the current SQL in the results.

      WHERE req.session_id != @@SPID

      Reply
    4. anu on February 21, 2019 11:15 am

      worked

      Reply
    5. David Dean on July 7, 2017 8:14 pm

      A great technique to Find Currently Running Query in SQL Server. By the way, I have pleased to read the entirety of the post as mentioned above in detail. Thanks!

      Reply
    6. Adam on May 12, 2017 4:28 pm

      Thank you soo much…. It helps me alot to debug SQL Server slowness…. I found multiple SQL queries were running from a long time and causing 100% cpu uses…..

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.