"SQL Server" lock table and unlock operations for various databases

Source: Internet
Author: User

SQL Server queries locked tables and locks table

--1. View Locked TableSELECTrequest_session_id asspidobject_name(resource_associated_entity_id) asTableName fromSys.dm_tran_locksWHEREResource_type='OBJECT' --SPID lock table process; tableName Locked table name--2. UnlockingDeclare @spid  int  Set @spid  =The process number of the locked tableDeclare @sql varchar( +)Set @sql='Kill'+cast(@spid   as varchar)exec(@sql)

Oracle queries locked tables and locks table
--1. The code for the Lock table query is in the following form:SELECT Count(*) fromV$locked_object;SELECT *  fromV$locked_object;--2. See which table is lockedSELECTB.owner,b.object_name, A.session_id,a.locked_mode fromV$locked_object A,dba_objects bWHEREB.object_id =A.object_id; --3. See which session is causing theSELECTB.username,b.sid,b.serial#,logon_time fromV$locked_object A,v$session bWHEREa.session_id=B.sidOrder  byB.logon_time; --4. Kill the corresponding processAlterSystemKillSession'1025,41'; --1025 of them are sid,41 for serial#.

"SQL Server" lock table and unlock operations for various databases

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.