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

How to design a web page? How to create a web page?

When it comes to understanding web design, many p...

How to solve the element movement caused by hover-generated border

Preface Sometimes when hover pseudo-class adds a ...

CocosCreator Getting Started Tutorial: Network Communication

Network Communication Overview When developing an...

JavaScript implements div mouse drag effect

This article shares the specific code for JavaScr...

Example code for implementing verification code login in SMS API in Node

1. Node server setup + database connection The op...

MySQL 8.0.18 installation and configuration method graphic tutorial under MacOS

This article records the installation of MySQL 8....

Install CentOS system based on WindowsX Hyper-V

At present, most people who use Linux either use ...

How to deal with too many Docker logs causing the disk to fill up

I have a server with multiple docker containers d...

Solution to the problem of not finding Tomcat configuration in Intelli Idea

I joined a new company these two days. The compan...

Avoiding Problems Caused by Closures in JavaScript

About let to avoid problems caused by closure Use...

Element table header row height problem solution

Table of contents Preface 1. Cause of the problem...

In-depth explanation of the principle of MySQL Innodb index

introduction Looking back four years ago, when I ...

How to enter and exit the Docker container

1 Start the Docker service First you need to know...

CSS: visited pseudo-class selector secret memories

Yesterday I wanted to use a:visited to change the...