Get schema All tables && get all fields of a table

Source: Internet
Author: User
Tags modifiers

Note: The following is PostgreSQL, the other database skips \d[+] table_name View "detailed" Table structure

To get all the tables under a schame, or to get all the fields for a table, you need to rely on both tables:
Information_schema.tables and information_schema.columns The first table holds information for all tables under all schemas

\d information_schema.tables View "Information_schema.tables" Column | Type | Modifiers------------------------------+-----------------------------------+-----------Table_catalog | 
 Information_schema.sql_identifier | Table_schema | 
 Information_schema.sql_identifier | table_name | 
 Information_schema.sql_identifier | Table_type | 
 Information_schema.character_data | Self_referencing_column_name | 
 Information_schema.sql_identifier | reference_generation | 
 Information_schema.character_data | User_defined_type_catalog | 
 Information_schema.sql_identifier | User_defined_type_schema | 
 Information_schema.sql_identifier | User_defined_type_name | 
 Information_schema.sql_identifier | Is_insertable_into | 
 Information_schema.yes_or_no | is_typed |      Information_schema.yes_or_no| commit_action |  Information_schema.character_data |
The second table is the name of the field that holds all the tables under all schemas
\d information_schema.columns View "Information_schema.columns" Column | Type | Modifiers--------------------------+------------------------------------+-----------Table_catalog | 
 Information_schema.sql_identifier | Table_schema | 
 Information_schema.sql_identifier | table_name | 
 Information_schema.sql_identifier | column_name | 
 Information_schema.sql_identifier | ordinal_position | 
 Information_schema.cardinal_number | Column_default | 
 Information_schema.character_data | is_nullable | 
 Information_schema.yes_or_no | Data_type | 
 Information_schema.character_data | Character_maximum_length | 
 Information_schema.cardinal_number | Character_octet_length | 
 Information_schema.cardinal_number | numeric_precision | 
 Information_schema.cardinal_number | Numeric_precision_radix | InformatiOn_schema.cardinal_number | Numeric_scale | 
 Information_schema.cardinal_number | datetime_precision | 
 Information_schema.cardinal_number | Interval_type | 
 Information_schema.character_data | interval_precision | 
 Information_schema.cardinal_number | Character_set_catalog | 
 Information_schema.sql_identifier | Character_set_schema | 
 Information_schema.sql_identifier | Character_set_name | 
 Information_schema.sql_identifier | Collation_catalog | 
 Information_schema.sql_identifier | Collation_schema | 
 Information_schema.sql_identifier | Collation_name | 
 Information_schema.sql_identifier | Domain_catalog | 
 Information_schema.sql_identifier | Domain_schema | 
 Information_schema.sql_identifier | domain_name | 
 Information_schema.sql_identifier | Udt_catalog | 
 Information_schema.sql_identifier | Udt_schema | Information_schema.Sql_identifier | Udt_name | 
 Information_schema.sql_identifier | Scope_catalog | 
 Information_schema.sql_identifier | Scope_schema | 
 Information_schema.sql_identifier | Scope_name | 
 Information_schema.sql_identifier | maximum_cardinality | 
 Information_schema.cardinal_number | Dtd_identifier | 
 Information_schema.sql_identifier | is_self_referencing | 
 Information_schema.yes_or_no | is_identity | 
 Information_schema.yes_or_no | identity_generation | 
 Information_schema.character_data | Identity_start | 
 Information_schema.character_data | identity_increment | 
 Information_schema.character_data | Identity_maximum | 
 Information_schema.character_data | Identity_minimum | 
 Information_schema.character_data | identity_cycle | 
 Information_schema.yes_or_no | is_generated | Information_schema.character_Data | generation_expression | 
 Information_schema.character_data | is_updatable | 
 Information_schema.yes_or_no |

According to the fields of these two tables, it becomes easy to get all the tables of a schema and get all the fields of a table. get all the tables under a schame:

Select table_name from information_schema.tables where table_schema= ' schema_name ' and table_type= ' table_name ';
get all fields of a table
Select column_name from Information_schema.columns where table_schema= ' schema_name ' and table_name= ' table_name '
get a field that holds text for a table
Select Column_name,data_type from Information_schema.columns where table_schema= ' Table_schema ' and Table_name= ' Table_ Name ' and data_type in (' character varying ', ' text ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.