Sql query MySql database table name and description table field (column) information

Sql query MySql database table name and description table field (column) information

The following is an introduction to using SQL query statements to obtain the table name, table description, field ID, field name, data type, length, precision, whether it can be null, default value, whether it is auto-increment, whether it is a primary key, and column description of the table in the Mysql database.

1. Query table information (table name/table description)

SELECT table_name name,TABLE_COMMENT value FROM INFORMATION_SCHEMA.TABLES WHERE table_type='base table' 
and table_schema = 'database name' order by table_name asc

2. Query field information (field ID/field name/data type/length/precision/whether it can be null/default value/whether it is auto-increment/whether it is primary key/column description)

Method 1:

SHOW FULL COLUMNS FROM 表名

Method 2:

select ORDINAL_POSITION as Colorder, Column_Name as ColumnName, data_type as TypeName, COLUMN_COMMENT as DeText,
(case when data_type = 'float' or data_type = 'double' or data_type = 'decimal' then NUMERIC_PRECISION else CHARACTER_MAXIMUM_LENGTH end ) as length,
NUMERIC_SCALE as Scale,(case when EXTRA='auto_increment' then 1 else 0 end) as IsIdentity,(case when COLUMN_KEY='PRI' then 1 else 0 end) as IsPK,
(case when IS_NULLABLE = 'NO' then 0 else 1 end)as CanNull,COLUMN_DEFAULT as DefaultVal
from information_schema.columns where table_schema = 'Database name' and table_name = 'Table name' order by ORDINAL_POSITION asc

The above are several ways for Sql to obtain table names in the MySql database and column information such as field names and data types in the description table. If this is not what you need, you can also read the following related articles

You may also be interested in:
  • MySQL database SELECT query expression analysis
  • Detailed explanation of MySQL database--multi-table query--inner join, outer join, subquery, correlated subquery
  • MySQL database advanced query and multi-table query
  • Why does the index in the Mysql database table not improve the query speed?
  • MySQL database query advanced multi-table query detailed explanation
  • Why is the query slow even though there is an index in the MySQL database table?

<<:  Detailed steps to delete environment variables in Linux

>>:  Vue project implements graphic verification code

Recommend

An example of how to quickly deploy web applications using Tomcat in Docker

After learning the basic operations of Docker, we...

NULL and Empty String in Mysql

I recently came into contact with MySQL. Yesterda...

SQL GROUP BY detailed explanation and simple example

The GROUP BY statement is used in conjunction wit...

Web interview Vue custom components and calling methods

Import: Due to project requirements, we will enca...

Design Theory: Hierarchy in Design

<br />Original text: http://andymao.com/andy...

JavaScript setTimeout and setTimeinterval use cases explained

Both methods can be used to execute a piece of ja...

Use pure JS to achieve the secondary menu effect

This article example shares the specific code of ...

Docker installation and deployment of Net Core implementation process analysis

1. Docker installation and settings #Install Cent...

Teach you to implement a simple promise step by step

Table of contents Step 1: Build the framework Ste...

Solve the problem of garbled data in MySQL database migration

Under the instructions of my leader, I took over ...

Problems and pitfalls of installing Mysql5.7.23 in Win10 environment

I read many tutorials, but found that I could nev...

UCenter Home site adds statistics code

UCenter Home is an SNS website building system rel...