- /**View table structure**/
- desc yourtablename
- /**View the create table statement**/
- show createtable yourtablename
- /**View all column information**/
- use information_schema;
- select * from columns where table_name='yourtablename';
- /**View information about all column names**/
- use information_schema;
- select column_name from columns where table_name='yourtablename';
- /** Concatenate column names to predefined sql**/
- select concat('insert into yourtablename values(',r.column_name) from
- (select group_concat(column_name) column_name from columns where table_name='yourtablename') r;
- /**Query all table names and comments in mysql that contain the specified column**/
- useinformation_schema;
- selectdistinctc.table_name,t.TABLE_COMMENTfromcolumnscleftjointablest
- onc.table_name=t.TABLE_NAME
- wherec.TABLE_SCHEMA= 'database' /**Database name*/
- andc.COLUMN_NAME= 'password' /**column name*/
- andc.DATA_TYPE= 'int' /**Data column type*/
View to get the field comments in the table:
> show full columns from tablename;
or
show full fields from tablename;
or, in the metadata table, see
Select COLUMN_NAME column name, DATA_TYPE field type, COLUMN_COMMENT field comment
from INFORMATION_SCHEMA.COLUMNS
Where table_name = 'companies'##Table name
AND table_schema = 'testhuicard'##Database nameAND
column_name LIKE 'c_name'##Field name
2-1 How to view table comments:
> show create table tablename;
2-2 Get the entire database All table information (including table name, table comment, table type, etc.):
> SELECT table_name, table_type, engine
-> FROM information_schema.tables
-> WHERE table_schema = 'db5' //table_schema is the database name
-> ORDER BY table_name DESC ;
//This statement requests to list all tables in database db5 in reverse alphabetical order, but only displays three kinds of information: table name, table type, and table engine.
INFORMATION_SCHEMA is an information database that holds information about all other databases maintained by the MySQL server.
> SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sh_goods' AND TABLE_SCHEMA = 'sh_shop';//Get the comments of the sh_goods table in the sh_shop database .
2-3 Get the table comment or
Or use: show table status;
Comment is the table comment.
Extension:
Modify table comments:
alter table test1 comment 'Modified table comments';
Modify field comments:
alter table test1 modify column field_name int comment 'Modified field comments';