当前位置:首页 » 编程语言 » 锁表的sql语句

锁表的sql语句

发布时间: 2023-12-13 01:38:32

⑴ Oracle 锁表情况查询sql

select LOCK_INFO.OWNER || '.' || LOCK_INFO.OBJ_NAME as "已锁物件名称", --物件名称(已经被锁住)

LOCK_INFO.SUBOBJ_NAME as "已锁子物件名称", -- 子物件名称(已经被锁住)

SESS_INFO.MACHINE as "机器名称", -- 机器名称

LOCK_INFO.SESSION_ID as "会话ID", -- 会话SESSION_ID

SESS_INFO.SERIAL# as "会话SERIAL#", -- 会话SERIAL#

SESS_INFO.SPID as "OS系统的SPID", -- OS系统的SPID

(SELECT INSTANCE_NAME FROM V$INSTANCE) "实例名SID", --实例名SID

LOCK_INFO.ORA_USERNAME as "ORACLE用户", -- ORACLE系统用户名称

LOCK_INFO.OS_USERNAME as "OS用户", -- 作业系统用户名称

LOCK_INFO.PROCESS as "进程编号", -- 进程编号

LOCK_INFO.OBJ_ID as "对象ID", -- 对象ID

LOCK_INFO.OBJ_TYPE as "对象类型", -- 对象类型

SESS_INFO.LOGON_TIME as "登录时间", -- 登录时间

SESS_INFO.PROGRAM as "程式名称", -- 程式名称

SESS_INFO.STATUS as "会话状态", -- 会话状态

SESS_INFO.LOCKWAIT as "等待锁", -- 等待锁

SESS_INFO.ACTION as "动作", -- 动作

SESS_INFO.CLIENT_INFO as "客户资讯" -- 客户资讯

from (select obj.OWNER as OWNER,

obj.OBJECT_NAME as OBJ_NAME,

obj.SUBOBJECT_NAME as SUBOBJ_NAME,

obj.OBJECT_ID as OBJ_ID,

obj.OBJECT_TYPE as OBJ_TYPE,

lock_obj.SESSION_ID as SESSION_ID,

lock_obj.ORACLE_USERNAME as ORA_USERNAME,

lock_obj.OS_USER_NAME as OS_USERNAME,

lock_obj.PROCESS as PROCESS

from (select *

from all_objects

where object_id in (select object_id from v$locked_object)) obj,

v$locked_object lock_obj

where obj.object_id = lock_obj.object_id) LOCK_INFO,

(select SID,

SERIAL#,

LOCKWAIT,

STATUS,

(select spid from v$process where addr = a.paddr) spid,

PROGRAM,

ACTION,

CLIENT_INFO,

LOGON_TIME,

MACHINE

from v$session a) SESS_INFO

where LOCK_INFO.SESSION_ID = SESS_INFO.SID

order by LOCK_INFO.SESSION_ID;

⑵ MySQL数据库如何锁定和解锁数据库表

第一步,创建数据库表writer和查看表结构,利用SQL语句:
create table writer(
wid int(10),
wno int(10),
wname varchar(20),
wsex varchar(2),
wage int(2)
第二步,向数据库表writer插入五条数据,插入后查看表里数据
第三步,利用锁定语句锁定数据库表writer,利用SQL语句:
lock table writer read;
让数据库表只读不能进行写
第四步,为了验证锁定效果,可以查看数据库表数据,利用SQL语句:
select * from writer;
第五步,利用update语句对id=5进行更新,SQL语句为:
update writer set wname = '胡思思' where id = 5;
第六步,利用unlock进行解锁,SQL语句为:
unlock tables;

⑶ 两个SQL的锁表问题

不是很明白的你的意思,查看是否锁表的sql:
select s.SID,s.SERIAL#,s.username,
decode(l.type,'TM','TABLE LOCK',
'TX','ROW LOCK',
NULL) LOCK_LEVEL,
o.owner,o.object_name,o.object_type,s.terminal,s.machine,s.program,s.osuser
from v$session s,v$lock l,dba_objects o
where s.sid=l.sid
and o.object_id=l.id1
and s.username is not null ;
如果1 .2是同时操作一张表,最好是执行完一条sql先commit一下在执行第二条这样肯定不会锁表,我不知道我理解对了没有?
ps:不能,数据库的事务机制不允许同一时刻同一记录update 如果先update操作会先lock table等执行完释放资源才有其他的操作。
以下是我做过的测试:
eg:select * from table for update;
1.不允许做for update查询。
2.允许普通search查询。
3.不允许对表中任何记录做update操作;
4.允许insert操作;
5.不允许delete操作。
另:一楼说的是对的。

⑷ oracle 锁表时,怎么查出是哪些SQL语句导致了锁表

SELECT S.SID SESSION_ID, S.USERNAME, DECODE(LMODE, 0, 'None', 1, 'Null', 2, 'Row-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6, 'Exclusive', TO_CHAR(LMODE)) MODE_HELD, DECODE(REQUEST, 0, 'None', 1, 'Null', 2, 'Row-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6, 'Exclusive', TO_CHAR(REQUEST)) MODE_REQUESTED, O.OWNER||'.'||O.OBJECT_NAME||' ('||O.OBJECT_TYPE||')', S.TYPE LOCK_TYPE, L.ID1 LOCK_ID1, L.ID2 LOCK_ID2
FROM V$LOCK L, SYS.DBA_OBJECTS O, V$SESSION S
WHERE L.SID = S.SID AND L.ID1 = O.OBJECT_ID;
执行上记SQL语句,可以查寻到数据库中的锁的情报.
SESSION_ID, USERNAME, MODE_HELD, MODE_REQUESTED, OBJECT_NAME, LOCK_TYPE, LOCK_ID
分别是 拥有锁的SESSION_ID,拥有锁的USERNAME,锁的执行模式MODE_HELD,锁的请求MODE_REQUESTED,锁所在的数据库对象名
,锁的类型,锁的ID
还有你问的应该是数据库中表出现死锁情况吧,是哪些sql过程导致了表死锁:
解决方案如下:
1.查哪个过程被锁:
查V$DB_OBJECT_CACHE视图:
SELECT * FROM V$DB_OBJECT_CACHE WHERE OWNER='过程的所属用户' AND CLOCKS!='0';
2. 查是哪一个SID,通过SID可知道是哪个SESSION:
查V$ACCESS视图:
SELECT * FROM V$ACCESS WHERE OWNER='过程的所属用户' AND NAME='刚才查到的过程名';
3. 查出SID和SERIAL#:
查V$SESSION视图:
SELECT SID,SERIAL#,PADDR FROM V$SESSION WHERE SID='刚才查到的SID';
查V$PROCESS视图:
SELECT SPID FROM V$PROCESS WHERE ADDR='刚才查到的PADDR';
4. 杀进程:
(1)先杀ORACLE进程:
ALTER SYSTEM KILL SESSION '查出的SID,查出的SERIAL#';
(2)再杀操作系统进程: (linux)
KILL -9 刚才查出的SPID或ORAKILL 刚才查出的SID 刚才查出的SPID。

⑸ 怎样用SQL给SQL2880特定表加锁解锁

加锁的语句如下:

SELECT*FROM表名WITH(TABLOCK);

这里没有解锁的概念,只有不加锁的概念,语句如下:

SELECT*FROM表名WITH(NOLOCK);

加锁的解释:

TABLOCK(表锁)

此选项被选中时,SQLServer将在整个表上置共享锁直至该命令结束。这个选项保证其他进程只能读取而不能修改数据。

不加锁的解释:

NOLOCK(不加锁)

此选项被选中时,SQLServer在读取或修改数据时不加任何锁。在这种情况下,用户有可能读取到

⑹ 如何查询锁表的SQL

用下边的语句查询,如果想结束直接kill
SELECT SPID=p.spid,
DBName = convert(CHAR(20),d.name),
ProgramName = program_name,
LoginName = convert(CHAR(20),l.name),
HostName = convert(CHAR(20),hostname),
Status = p.status,
BlockedBy = p.blocked,
LoginTime = login_time,
QUERY = CAST(t.TEXT AS VARCHAR(MAX))
FROM MASTER.dbo.sysprocesses p
INNER JOIN MASTER.dbo.sysdatabases d
ON p.dbid = d.dbid
INNER JOIN MASTER.dbo.syslogins l
ON p.sid = l.sid
CROSS APPLY sys.dm_exec_sql_text(sql_handle) t
WHERE p.blocked = 0
AND EXISTS (SELECT 1
FROM MASTER.dbo.sysprocesses p1
WHERE p1.blocked = p.spid)

⑺ 怎样查询出SQLSERVER被锁的表,以锁表的SQL语句

查看被锁表:
select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type='OBJECT'
spid 锁表进程
tableName 被锁表名

热点内容
ios6G与安卓12G哪个更快 发布:2025-01-24 11:26:22 浏览:827
下线源码 发布:2025-01-24 11:26:22 浏览:523
windows8解压软件 发布:2025-01-24 11:04:41 浏览:559
蓝牙聊天源码 发布:2025-01-24 11:03:13 浏览:124
安卓是什么意思是vivo吗 发布:2025-01-24 11:01:32 浏览:486
悬赏网源码 发布:2025-01-24 10:53:14 浏览:733
c语言时间变量 发布:2025-01-24 10:40:24 浏览:870
ppiandroid 发布:2025-01-24 10:25:50 浏览:1001
儿童压缩机 发布:2025-01-24 10:25:09 浏览:75
苹果的允许访问在哪里 发布:2025-01-24 10:24:32 浏览:32