1. 程式人生 > >資料庫導表和鎖表問題

資料庫導表和鎖表問題

一些基本的資料庫操作,好長時間不用了,好像有點忘了。在這裡還是要記一下啊

清空資料表:   truncate table +表名

建立索引: create index +索引名(idx_) on 表名(列名);

建立唯一索引:create unique clustered +索引名(idx_) on 表名(列名);

刪除索引: drop   index 表名.索引名;

資料庫在伺服器的匯入匯出

匯出

首先要進入oracle使用者下

還要建立使用者名稱

將使用者user使用者表匯入到/tmp下

exp user/[email protected] file=/tmp/20180115.dmp owner=user

將使用者user使用者的表table1,table2匯入到

/tmp

exp user/[email protected] file=/tmp/20180115.dmp tables=(table1,table2) 

將使用者user使用者的表table1中的欄位filed1以"a"開頭的資料匯出

exp user/[email protected] filed=/tmp/20180115.dmp tables=(table1) query=/"   where filed1 like 'a%'/"

匯入

將/temp/20180115.dmp檔案匯入到user下

imp user/[email protected]

filed=/tmp/20180115.dmp ignore=y full=y

先將資料庫檔案匯出到tmp下,然後再匯入到另一個使用者下。

-exp npstest/npstest owner=npstest file=/tmp/ nps.dmp

Imp qxnxy/[email protected] fromuser=qxnxy  touser=qxnxy ignore=y file=/tmp/nps.dmp

鎖表問題怎樣解決

首先你要知道表鎖住了是不是正常鎖?因為任何DML語句都會對錶加鎖。你要先查一下是那個會話那個sql鎖住了表,有可能這是正常業務需求,不建議隨便KILL session,如果這個鎖表是正常業務你把session kill掉了會影響業務的。

建議先查原因再做決定。(1)鎖表查詢的程式碼有以下的形式:select count(*) from v$locked_object;select * from v$locked_object;(2)檢視哪個表被鎖select b.owner,b.object_name,a.session_id,a.locked_mode from v$locked_object a,dba_objects b where b.object_id = a.object_id;(3)檢視是哪個session引起的select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = b.sid order by b.logon_time; (4)檢視是哪個sql引起的select b.username,b.sid,b.serial#,c.* from v$locked_object a,v$session b,v$sql c where a.session_id = b.sidand b.SQL_ID = c.sql_id and c.sql_id = ''order by b.logon_time; (5)殺掉對應程序執行命令:alter system kill session'1025,41';其中1025為sid,41為serial#.