I created table in SQL Server 2012 and when I execute
select * from tableName
it is taking a long time and some time returns no result.
Currently it has only 1 row. After searching I know it is being locked so please help how to unlock it or drop it?
Use the UNLOCK TABLE statement in a database that does not support transaction logging to unlock a table that you previously locked with the LOCK TABLE statement. The UNLOCK TABLE statement is an extension to the ANSI/ISO standard for SQL.
Answer: The only way to release a lock on an Oracle table is to kill the session that is holding the lock, or wait for the transaction to complete.
Thank you Guys.. It is resolved.
I fired below query
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) = 'P1Chronolog_IncidentActivityUpdates'
and killed that respective session by
Kill session_ID
Get the SPID of what is locking the table and kill it, see below
SELECT r.start_time [Start Time],session_ID [SPID],
DB_NAME(database_id) [Database],
SUBSTRING(t.text,(r.statement_start_offset/2)+1,
CASE WHEN statement_end_offset=-1 OR statement_end_offset=0
THEN (DATALENGTH(t.Text)-r.statement_start_offset/2)+1
ELSE (r.statement_end_offset-r.statement_start_offset)/2+1
END) [Executing SQL],
Status,command,wait_type,wait_time,wait_resource,
last_wait_type
FROM sys.dm_exec_requests r
OUTER APPLY sys.dm_exec_sql_text(sql_handle) t
WHERE session_id != @@SPID -- don't show this query
AND session_id > 50 -- don't show system queries
ORDER BY r.start_time
DBCC opentran()
exec sp_who2 68
exec sp_lock 68
kill 68
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With