postgresql show tables
时间: 2023-10-02 11:10:16 浏览: 47
To show all tables in a PostgreSQL database, you can use the following SQL command:
```
SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE';
```
This command will retrieve the names of all tables in the "public" schema of your PostgreSQL database. If you have tables in other schemas, you can modify the query to include them as well.
Alternatively, you can use the following command:
```
\dt
```
This is a command used in the psql command-line interface to show all tables in the current database.
相关问题
pg 类似于 show tables的命令
在 PostgreSQL 中,可以使用以下命令来列出当前数据库中的所有表:
```
\dt
```
这个命令会显示当前数据库中所有的表的名称、模式和类型信息。如果您只想显示某个特定模式下的表,可以使用以下命令:
```
\dt <schema_name>.*
```
其中,`<schema_name>` 是您要显示的模式的名称。这个命令会显示指定模式下的所有表的名称、模式和类型信息。
请注意,在 PostgreSQL 中,表也可以被称为关系。因此,在显示表的列表时,有些人也使用 `\d` 命令,它可以列出当前数据库中的所有关系,包括表、视图和序列等。
查系统表名
要查询系统表名,需要先知道使用的数据库类型。不同的数据库类型可能会有不同的系统表名。
以下是几种常见的数据库类型及其对应的系统表名查询语句:
1. MySQL
要查询 MySQL 数据库中的表名,可以使用以下命令:
```
SHOW TABLES;
```
2. Oracle
要查询 Oracle 数据库中的表名,可以使用以下命令:
```
SELECT table_name FROM user_tables;
```
3. SQL Server
要查询 SQL Server 数据库中的表名,可以使用以下命令:
```
SELECT name FROM sys.tables;
```
4. PostgreSQL
要查询 PostgreSQL 数据库中的表名,可以使用以下命令:
```
SELECT table_name FROM information_schema.tables WHERE table_schema='public';
```
以上命令仅供参考,具体查询语句可能会因数据库版本、权限等因素而略有不同。