SQL queries the Table Name and description table field (column) Information in the MySql database, sqlmysql

Source: Internet
Author: User

SQL queries the Table Name and description table field (column) Information in the MySql database, sqlmysql

The following describes how to use an SQL query statement to obtain the name of a table in a Mysql database, table description, field ID, field name, data type, length, precision, whether it can be null, default value, auto-increment, primary key, column description

I. 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/auto-increment/whether it is a primary key/column description)

Method 1:

Show full columns from Table Name

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 DefaultValfrom information_schema.columns where table_schema = 'database name' and table_name = 'table name' order by ORDINAL_POSITION asc

The preceding methods are used to obtain the column information, such as the table name and field name in the description table, in the MySql database. If you do not need them, read the following articles.

Related Article

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.