使用LIST命令显示DB2中的所有表

gev0vcfq  于 2023-04-30  发布在  DB2
关注(0)|答案(7)|浏览(263)

这很尴尬,但我似乎找不到一种方法来列出DB2数据库中表的名称。以下是我尝试的:

root@VO11555:~# su - db2inst1
root@VO11555:~# . ~db2inst1/sqllib/db2profile
root@VO11555:~# LIST ACTIVE DATABASES

我们收到这个错误:SQL1092N "ROOT" does not have the authority to perform the requested command or operation.
DB2版本号如下。

root@VO11555:~# 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".
mrfwxfqh

mrfwxfqh1#

获取DB2中当前数据库的表列表--〉
连接到数据库:

db2 connect to DATABASENAME user USER using PASSWORD

运行此查询:

db2 LIST TABLES

这相当于MySQL中的SHOW TABLES。
在运行list tables命令之前,您可能需要执行“set schema myschema”以获得正确的架构。默认情况下,登录时,您的模式与用户名相同-用户名通常不包含任何表。您可以使用“values current schema”来检查您当前设置的模式。

qni6mghb

qni6mghb2#

连接到数据库:

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

ktecyv1j

ktecyv1j3#

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

您可能希望将查询限制为tabschema

okxuctiv

okxuctiv4#

我用的是DB2 7。1和Squirrel。这是唯一一个对我有用的查询。

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

rmbxnbpk5#

在首选shell会话上运行以下命令行:

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

也许你想修改所有者的名字,并需要检查当前所有者的列表?

db2 "select distinct owner from syscat.tables"
lvjbypge

lvjbypge6#

你有没有安装一个用户db2inst2,我想,我记得,db2inst1是非常管理的

atmip9wb

atmip9wb7#

在首选shell会话上运行以下命令行:$db2连接到$db2列表表

相关问题