查詢表資訊
收集表資訊指令碼
大神寫的指令碼分享給大家,用來收集表資訊的
-
-- | PURPOSE : Prompt the user for a schema and and table name then query all |
-
-- | metadata about the table. |
-
-- | NOTE : As with any code, ensure to test this script in a development |
-
-- | environment before attempting to run it in production. |
-
-- +----------------------------------------------------------------------------+
-
-
-
SET PAGESIZE 9999
-
SET VERIFY OFF
-
SET FEEDBACK OFF
-
SET LONG 9000
-
-
-- +----------------------------------------------------------------------------+
-
-- | PROMPT USER FOR SCHEMA AND TABLE |
-
-- +----------------------------------------------------------------------------+
-
-
ACCEPT sch prompt 'Enter Schema (i.e. SCOTT) : '
-
ACCEPT tab prompt 'Enter Table (i.e. EMP) : '
-
-
-
PROMPT
-
PROMPT +----------------------------------------------------------------------------+
-
PROMPT | TABLE INFORMATION |
-
PROMPT +----------------------------------------------------------------------------+
-
-
COLUMN owner FORMAT A15 HEADING "Owner"
-
COLUMN table_name FORMAT A30 HEADING "Table Name"
-
COLUMN tablespace_name FORMAT A28 HEADING "Tablespace"
-
COLUMN last_analyzed FORMAT A20 HEADING "Last Analyzed"
-
COLUMN num_rows FORMAT 999,999,999 HEADING "# of Rows"
-
-
SELECT
-
owner
-
, table_name
-
, tablespace_name
-
, TO_CHAR(last_analyzed, 'DD-MON-YYYY HH24:MI:SS') last_analyzed
-
, num_rows
-
FROM
-
dba_tables
-
WHERE
-
owner = UPPER('&sch')
-
AND table_name = UPPER('&tab')
-
/
-
-
PROMPT
-
PROMPT +----------------------------------------------------------------------------+
-
PROMPT | OBJECT INFORMATION |
-
PROMPT +----------------------------------------------------------------------------+
-
-
COLUMN object_id HEADING "Object ID"
-
COLUMN data_object_id HEADING "Data Object ID"
-
COLUMN created FORMAT A20 HEADING "Created"
-
COLUMN last_ddl_time FORMAT A20 HEADING "Last DDL"
-
COLUMN status HEADING "Status"
-
-
SELECT
-
object_id
-
, data_object_id
-
, TO_CHAR(created, 'DD-MON-YYYY HH24:MI:SS') created
-
, TO_CHAR(last_ddl_time, 'DD-MON-YYYY HH24:MI:SS') last_ddl_time
-
, status
-
FROM
-
dba_objects
-
WHERE
-
owner = UPPER('&sch')
-
AND object_name = UPPER('&tab')
-
AND object_type = 'TABLE'
-
/
-
-
PROMPT
-
PROMPT +----------------------------------------------------------------------------+
-
PROMPT | SEGMENT INFORMATION |
-
PROMPT +----------------------------------------------------------------------------+
-
-
COLUMN segment_type HEADING "Segment Type"
-
COLUMN bytes FORMAT 9,999,999,999,999 HEADING "Bytes"
-
COLUMN extents FORMAT 999,999,999 HEADING "Extents"
-
COLUMN initial_extent FORMAT 999,999,999,999 HEADING "Initial|Extent"
-
COLUMN next_extent FORMAT 999,999,999,999 HEADING "Next|Extent"
-
COLUMN min_extents FORMAT 999 HEADING "Min|Extents"
-
COLUMN max_extents FORMAT 9,999,999,999 HEADING "Max|Extents"
-
COLUMN pct_increase FORMAT 999.00 HEADING "Pct|Increase"
-
COLUMN freelists HEADING "Free|Lists"
-
COLUMN freelist_groups HEADING "Free|List Groups"
-
-
SELECT
-
segment_type segment_type
-
, bytes/1024/1024 Mbytes
-
, extents extents
-
, initial_extent initial_extent
-
, next_extent next_extent
-
, min_extents min_extents
-
, max_extents max_extents
-
, pct_increase pct_increase
-
, freelists freelists
-
, freelist_groups freelist_groups
-
FROM
-
dba_segments
-
WHERE
-
owner = UPPER('&sch')
-
AND segment_name = UPPER('&tab')
-
/
-
-
-
PROMPT
-
PROMPT +----------------------------------------------------------------------------+
-
PROMPT | COLUMNS |
-
PROMPT +----------------------------------------------------------------------------+
-
-
COLUMN column_name FORMAT A20 HEADING "Column Name"
-
COLUMN data_type FORMAT A25 HEADING "Data Type"
-
COLUMN nullable FORMAT A13 HEADing "Null?"
-
-
SELECT
-
column_name
-
, DECODE(nullable, 'Y', ' ', 'NOT NULL') nullable
-
, DECODE(data_type
-
, 'RAW', data_type || '(' || data_length || ')'
-
, 'CHAR', data_type || '(' || data_length || ')'
-
, 'VARCHAR', data_type || '(' || data_length || ')'
-
, 'VARCHAR2', data_type || '(' || data_length || ')'
-
, 'NUMBER', NVL2( data_precision
-
, DECODE( data_scale
-
, 0
-
, data_type || '(' || data_precision || ')'
-
, data_type || '(' || data_precision || ',' || data_scale || ')'
-
)
-
, data_type)
-
, data_type
-
) data_type
-
FROM
-
dba_tab_columns
-
WHERE
-
owner = UPPER('&sch')
-
AND table_name = UPPER('&tab')
-
ORDER BY
-
column_id
-
/
-
-
-
PROMPT
-
PROMPT +----------------------------------------------------------------------------+
-
PROMPT | CONSTRAINTS |
-
PROMPT | UNCOMMENT THIS SECTION FROM THE SCRIPT TO GET THE INFO ABOUT CONST |
-
PROMPT +----------------------------------------------------------------------------+
-
PROMPT
-
-
COLUMN constraint_name FORMAT A18 HEADING "Constraint Name"
-
COLUMN constraint_type FORMAT A11 HEADING "Constraint|Type"
-
COLUMN search_condition FORMAT A15 HEADING "Search Condition"
-
COLUMN r_constraint_name FORMAT A20 HEADING "R / Constraint Name"
-
COLUMN delete_rule FORMAT A11 HEADING "Delete Rule"
-
COLUMN status HEADING "Status"
-
-
BREAK ON constraint_name ON constraint_type
-
-
SELECT
-
a.constraint_name
-
, DECODE(a.constraint_type
-
, 'P', 'Primary Key'
-
, 'C', 'Check'
-
, 'R', 'Referential'
-
, 'V', 'View Check'
-
, 'U', 'Unique'
-
, a.constraint_type
-
) constraint_type
-
, b.column_name
-
, a.search_condition
-
, NVL2(a.r_owner, a.r_owner || '.' || a.r_constraint_name, null) r_constraint_name
-
, a.delete_rule
-
, a.status
-
FROM
-
dba_constraints a
-
, dba_cons_columns b
-
WHERE
-
a.owner = UPPER('&sch')
-
AND a.table_name = UPPER('&tab')
-
AND a.constraint_name = b.constraint_name
-
AND b.owner = UPPER('&sch')
-
AND b.table_name = UPPER('&tab')
-
ORDER BY
-
a.constraint_name
-
, b.position
-
/
-
-
-
SET PAGESIZE 9999
-
SET VERIFY OFF
- SET FEEDBACK ON
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24851054/viewspace-2146407/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 表空間查詢資訊
- Oracle OCP(22):查詢表資訊Oracle
- 根據表查詢索引資訊索引
- mysql查詢表基礎資訊MySql
- 查詢某個表的索引資訊索引
- 鎖表的相關資訊查詢
- 查詢oracle表的資訊(表,欄位,約束,索引)Oracle索引
- GBase 庫中查詢表的列資訊
- 子查詢-表子查詢
- oracle查詢表資訊(索引,外來鍵,列等)Oracle索引
- 查詢表或索引增長的歷史資訊索引
- oracle 鎖資訊查詢
- 海光 DCU資訊查詢
- 單表查詢
- 查詢emp表上的所有約束的詳細資訊
- 域名查詢資訊怎麼操作?可以查詢哪些資訊?(中科三方)
- 查詢(3)--雜湊表(雜湊查詢)
- 閃回查詢之閃回表查詢
- ps -ef | grep 查詢資訊
- 【Linux】CPU資訊查詢Linux
- SQL SERVER 查詢鎖資訊SQLServer
- sqlserver查詢table,columns資訊SQLServer
- 企業資訊查詢工具
- jpa 聯合查詢資料,查詢使用者資訊與部門資訊
- 域名資訊查詢怎麼操作?Godaddy的whois域名資訊查詢在哪裡?Go
- 每秒百萬條資訊查詢 天翼雲助力江蘇核酸檢測資訊查詢
- 查詢 - 符號表符號
- MySQL單表查詢MySql
- JPA 連表查詢
- mysql鎖表查詢MySql
- MySQL 單表查詢MySql
- 查詢表的大小
- 查詢表結構
- SQL SERVER 資料庫查詢表和欄位資訊語句SQLServer資料庫
- 資料庫基礎查詢--單表查詢資料庫
- redo日誌組資訊查詢
- flask查詢whois資訊例項Flask
- 統計資訊的查詢方法