Search code examples
sqlsql-serversql-server-2017

Select Query doesn't show any results and appears to hang


I have a table, dbo.PE, in SQL Server 2017. Yesterday I had over 40,000 records. today when I do this:

Select Top 1000 * From dbo.PE

Nothing happens. No results (not even a No records message). It just sits there and spins and says Executing Query until it is cancelled. Any Idea to what is going on? I tried inserting new data and once again, nothing happens, just sits there and spins until cancelled.

I can access other tables in the database, just not this one. No permissions have been changed.


Solution

  • So, To answer this question, gsharp was correct in that the table was locked. I ran the following statement to kill the session (https://infrastructureland.wordpress.com/2015/01/24/how-to-release-or-remove-lock-on-a-table-sql-server/):

    SELECT    
        OBJECT_NAME(P.object_id) AS TableName,    
        Resource_type,    
        request_session_id    
    FROM sys.dm_tran_locks L    
    JOIN sys.partitions P ON L.resource_associated_entity_id = p.hobt_id    
    WHERE OBJECT_NAME(P.object_id) = ‘dbo.PE’
    

    Found out that the session ID was 54 so I executed:

    kill 54