SQL 使用 LIST 命令显示 DB2 中的所有表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2765412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
show all tables in DB2 using the LIST command
提问by Lightbeard
This is embarrassing, but I can't seem to find a way to list the names of the tables in our DB2 database. Here is what I tried:
这很尴尬,但我似乎无法找到列出 DB2 数据库中表名的方法。这是我尝试过的:
root@VO11555:~# su - db2inst1
root@VO11555:~# . ~db2inst1/sqllib/db2profile
root@VO11555:~# LIST ACTIVE DATABASES
We receive this error: SQL1092N "ROOT" does not have the authority to perform the requested command or operation.
我们收到此错误: SQL1092N "ROOT" does not have the authority to perform the requested command or operation.
The DB2 version number follows.
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".
回答by Dan
To get a list of tables for the current database in DB2 -->
获取 DB2 中当前数据库的表列表 -->
Connect to the database:
连接到数据库:
db2 connect to DATABASENAME user USER using PASSWORD
Run this query:
运行此查询:
db2 LIST TABLES
This is the equivalent of SHOW TABLES in MySQL.
这相当于 MySQL 中的 SHOW TABLES。
You may need to execute 'set schema myschema' to the correct schema before you run the list tables command. By default upon login your schema is the same as your username - which often won't contain any tables. You can use 'values current schema' to check what schema you're currently set to.
在运行 list tables 命令之前,您可能需要对正确的架构执行“set schema myschema”。默认情况下,登录时您的架构与您的用户名相同 - 通常不包含任何表。您可以使用“values current schema”来检查您当前设置的架构。
回答by Guagua
Connect to the database:
连接到数据库:
db2 connect to <database-name>
List all tables:
列出所有表:
db2 list tables for all
To list all tables in selected schema, use:
要列出所选模式中的所有表,请使用:
db2 list tables for schema <schema-name>
To describe a table, type:
要描述表,请键入:
db2 describe table <table-schema.table-name>
回答by Peter Miehle
select * from syscat.tables where type = 'T'
you may want to restrict the query to your tabschema
您可能希望将查询限制在您的 tabschema
回答by PbxMan
I'm using db2 7.1 and SQuirrel. This is the only query that worked for me.
我正在使用 db2 7.1 和 SQuirrel。这是唯一对我有用的查询。
select * from SYSIBM.tables where table_schema = 'my_schema' and table_type = 'BASE TABLE';
回答by user3311636
Run this command line on your preferred shell session:
在您首选的 shell 会话上运行此命令行:
db2 "select tabname from syscat.tables where owner = 'DB2INST1'"
Maybe you'd like to modify the owner name, and need to check the list of current owners?
也许您想修改所有者名称,并需要查看当前所有者的列表?
db2 "select distinct owner from syscat.tables"
回答by Peter Miehle
have you installed a user db2inst2, i think, i remember, that db2inst1 is very administrative
您是否安装了用户 db2inst2,我想,我记得,那个 db2inst1 非常具有管理性