資料庫系統相關SQL

2022-06-17 23:45:12 字數 1935 閱讀 8394

查出所有被鎖住的表

select b.owner tableowner, b.object_name tablename, c.osuser lockby,

c.username loginid, c.sid sid, c.serial# serial

from v$locked_object a,dba_objects b, v$session c

where b.object_id = a.object_id and a.session_id =c.sid;

通過sid, serial解鎖

--alter system kill session 'sid, serial';
select owner from dba_tables where table_name=upper('表名');
不過這個要求你當前登入的使用者許可權為dba才行,或有查詢這個檢視的許可權才行。

select * from v$nls_parameters where parameter like '%characterset'
找出外來鍵約束名稱,比如fk_ref27_agency,然後使用如下語句

select              

a.table_name as owner,

b.table_name as refer

from

dba_constraints a,

dba_constraints b

where

a.constraint_name='fk_ref27_agency' and

a.constraint_type = 'r' and

a.r_constraint_name = b.constraint_name

order by

a.table_name,

b.table_name;

owner是外來鍵所在的表,refer是所依賴的表(父項關鍵字)

有兩張系統表:dba_constraintsuser_constraints分別儲存了系統和使用者級約束

鎖在使用者修改之前就發揮作用:

select ..for update(nowait)

select * from tab1 for update

注意: for update操作對表是加行獨佔鎖,只影響select選中的行。

select owner from dba_tables where table_name='表名';
使用者發出這條命令之後,oracle將會對返回集中的資料建立行級封鎖,以防止其他使用者的修改。

如果此時其他使用者對上面返回結果集的資料進行dml或ddl操作都會返回乙個錯誤資訊或發生阻塞。

1:對返回結果集進行update或delete操作會發生阻塞。

2:對該錶進行ddl操作將會報:ora-00054:resource busy and acquire with nowait specified.

原因分析

此時oracle已經對返回的結果集上加了排它的行級鎖,所有其他對這些資料進行的修改或刪除操作都必須等待這個鎖的釋放,產生的外在現象就是其他的操作將發生阻塞,這個這個操作commit或rollback.

同樣這個查詢的事務將會對該錶加(dml操作的)表級鎖,不允許對該錶的任何ddl操作,否則將會報出ora-00054錯誤::resource busy and acquire with nowait specified.

附加:表級鎖是用於防止表的結構的修改。

sql資料庫系統表

sysaltfiles 主資料庫 儲存資料庫的檔案 syscharsets 主資料庫 字符集與排序順序 sysconfigures 主資料庫 配置選項 syscurconfigs 主資料庫 當前配置選項 sysdatabases 主資料庫 伺服器中的資料庫 syslanguages 主資料庫 語言 ...

SQL資料庫系統概論

如下 if exists select from sys.databases where name eshop begin use master drop database eshop endcreate database eshop use eshop create table members m...

資料庫系統mysql MySQL資料庫系統

1 mysql的特點 1 多執行緒 多使用者 2 基於c s 客戶端 伺服器 架構 3 簡單易用 查詢速度快 4 安全可靠 2 mysql編譯安裝 代表鍵盤上tab鍵 1 準備工作 解除安裝使用rpm方式安裝的mysql rpm e mysql nodeps 安裝cmake包 cd media ta...