2010-05-04 61 views
18

這很令人尷尬,但我似乎無法找到一種方法來列出DB2數據庫中表的名稱。這裏是我的嘗試:使用LIST命令顯示DB2中的所有表

[email protected]:~# su - db2inst1 
[email protected]:~# . ~db2inst1/sqllib/db2profile 
[email protected]:~# LIST ACTIVE DATABASES

我們收到此錯誤:SQL1092N "ROOT" does not have the authority to perform the requested command or operation.

的DB2版本號如下。

[email protected]:~# db2level 
DB21085I Instance "db2inst1" uses "64" bits and DB2 code release "SQL09071" 
with level identifier "08020107". 
Informational tokens are "DB2 v9.7.0.1", "s091114", "IP23034", and Fix Pack 
"1". 
Product is installed at "/opt/db2V9.7".
+1

不應該是從第二行開始的「db2inst1 @ VO11555」嗎? – 2010-05-05 06:26:32

回答

27

獲取列表DB2中當前數據庫的表格 - >

連接到數據庫:

db2 connect to DATABASENAME user USER using PASSWORD 

運行此查詢:

db2 LIST TABLES 

這是在MySQL SHOW TABLES的等價物。

在運行list tables命令之前,您可能需要執行'set schema myschema'到正確的模式。默認情況下,登錄時,您的架構與您的用戶名相同 - 通常不會包含任何表。您可以使用'values current schema'來檢查您當前設置的模式。

+0

感謝您的命令。 我是使用我在Turnkey LINUX VM上構建的IBM DB2 Express-C環境的新手。 – 2012-09-06 01:35:10

+4

如果某些表處於不同的模式中,您還應該嘗試運行'db2 LIST TABLES FOR ALL'。 – 2013-04-20 03:36:10

15
select * from syscat.tables where type = 'T' 

你可能想查詢限制對tabschema

0

有你安裝在用戶db2inst2,我想,我還記得,那db2inst1是非常行政

2

運行在您的首選shell會話此命令行:

db2 "select tabname from syscat.tables where owner = 'DB2INST1'" 

也許你想修改所有者的名稱,以及需要檢查當前所有者列表?

db2 "select distinct owner from syscat.tables" 
18

連接到數據庫:

db2 connect to <database-name> 

列表中的所有表:

db2 list tables for all 

要列出所選架構中的所有表,請使用:

db2 list tables for schema <schema-name> 

要描述一個表格,輸入:

db2 describe table <table-schema.table-name> 

信貸http://onewebsql.com/blog/list-all-tables

+0

非常有用,謝謝 – Dorgham 2017-07-01 16:09:24

2

我使用DB2 7.1和松鼠。這是唯一對我有用的查詢。

select * from SYSIBM.tables where table_schema = 'my_schema' and table_type = 'BASE TABLE';