達夢資料查詢編碼 達夢常用sql

2021-10-13 02:41:26 字數 2754 閱讀 5343

1、檢視儲存過程建立指令碼

select text from dba_source where owner= '***' and type = 'proc'

注:owner是指使用者名稱,type可以檢視型別、比如檢視、建表等。

2、檢視表的儲存大小

select segment_name, bytes/1024/1024

from user_segments

where segment_type = 'table'

order by 2 desc

3、檢視索引資訊

select

'select indexdef('||a.id||',1) union all'

from

sysobjects a,sysindexes b,dba_indexes c

where

a.id=b.id and b.flag=0

and a.name=c.index_name

and c.owner='***';

4、檢視對應的表的索引資訊

select

a.name ,

c.table_name ,

c.tablespace_name,

d.column_name

from

sysobjects a ,

sysindexes b ,

dba_indexes c,

user_ind_columns d

where

a.id =b.id

and b.flag =0

and a.name =c.index_name

and c.owner ='***'

and a.name =d.index_name

and a.subtype$='index';

5、檢視鎖

查詢表在被使用的sess_id

select

cast(rowid as varbinary) >> 58 ep_n,*

from v$sessions

where

state <>'idle'

and sql_text is not null;

查詢結果中sql_text是sql語句,可以看都在執行什麼,

再用sp_close_session($sess_id); --關掉session號為$sess_id的連線關掉。

注:如果是分布式,第一列代表對應的節點位置。

6、控制台執行匯出文字

這裡採用spool的方式

disql -s ***/***@jjhjk:5236 `d:\e_baseinfo.sql

--spool_ao_opanomaly.sql

spool的檔案

set echo off

set newpage none

set heading off

set pagesize 0

set trimspool on

set linesize 2500

set lineshow off

set timing off

set feed off

set char_code utf8

spool d:\aaa.txt

select

'|'||a||'|,|'||b||'|,|'||c||'|,|'||d||'|,|'||e||'|,|'||f||'|,|'||g||'|,|'||h||'|,|'||i||'|,|'||g||'|,|'||k||'|,|'||l||'|,|'||m||'|'

from "aaa" where rownum<=100;

spool off ;

7、修改列的資料型別

alter table production.product_review modify name varchar(8) default '**' not null;

8、具有dba許可權的使用者需要對employee_address表增加一列,列名為id(序號),

資料型別為int,值小於10000。

alter table resources.employee_address add id int primary key check (id

<10000);

9、具有 dba 許可權的使用者需要刪除 product 表的 product_subcategoryid 一列。

alter table production.product drop product_subcategoryid cascade;

10、 具有dba許可權的使用者需要在product表上增加unique約束, unique欄位為

name。

alter table production.product add constraint cons_productname unique(name);

11、使用 rebuild 將索引置為生效狀態。

alter index index_c1 rebuild ;

12、檢視每個表的資料容量

declare

used_space number;

begin

for rec in

select table_name from user_tables order by 1

loop

execute immediate 'select table_used_pages(''使用者名稱'','''||rec.table_name||''')*(select page()/1024)/1024 use

達夢資料庫常用SQL

達夢資料庫建立表 create table test table scid varchar2 10 primary key,scname varchar2 20 scsm number 6 scprice number 4,2 當前使用者 達夢資料庫 獲取當前使用者擁有的表 select table...

達夢資料常用查詢總結 不定時更新

對於dba來說,有一些常用的檢視還是需要掌握 下面我將常用的檢視羅列一下。select from sys.dba tables 檢視表的資訊 select from sys.dba tablespaces 檢視表空間資訊 select from sys.v dm ini 顯示 ini 引數和 dmi...

達夢資料庫常用sql語句整理(1)

select from v tablespace 2.hmain 表空間檢視語句 select from v huge tablespace 3.檢視使用者占用的空間 使用系統函式 user used space 得到使用者占用空間的大小,函式引數為使用者名稱,返回值為占用的頁的數目。select ...