Mysql get table comment field operation

Mysql get table comment field operation

I won't say much nonsense, let's just look at the code~

-- View and obtain the field comments in the table:
show full columns from tablename;
-- Or show full fields from tablename;
-- Or, look in the metadata table 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 name AND column_name LIKE 'c_name'##field name -- 2-1 How to view table comments:
show create table tablename;
-- 2-2 Get all table information of the entire database (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 a reverse alphabetical listing of all tables in database db5, but only displays three types of information: table name, table type, and table engine.
-- INFORMATION_SCHEMA is the 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 table comments or -- or use:
show table status;
-- Comment is a table comment.
-- Extensions:
-- Modify the table's comments:
alter table test1 comment 'Comments of the modified table';
-- Modify the field's comment:
alter table test1 modify column field_name int comment 'modified field comment';

Supplement: mysql query all field names, field types and comments of a table in a database

When doing background development, we must generate corresponding entity classes, that is, JavaBeans, from the tables in the data. During development, in order to quickly generate entity classes, we can query all field names, field types and comments of a table in the database, and quickly create JavaBeans, which can also prevent spelling errors.

Corresponds one to one with the fields in the database. In Navicat (database visualization tool), you can execute SQL statements

select COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT from information_schema.COLUMNS where table_name = 'table name' and table_schema = 'database name';

The result is similar to:

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • MySQL table and column comments summary
  • Basic operations of MySQL data tables: table structure operations, field operation example analysis
  • MySql creates a table with explanation and annotates the table and fields

<<:  How to use VUE to call Ali Iconfont library online

>>:  HTML table tag tutorial (20): row background color attribute BGCOLOR

Recommend

js array entries() Get iteration method

Table of contents 1. Detailed syntax of entires()...

Detailed installation and configuration of MySql on Mac

1. Download and install Download the community ed...

HTML imitates Baidu Encyclopedia navigation drop-down menu function

HTML imitates the Baidu Encyclopedia navigation d...

Add and delete table information using javascript

Getting Started with JavaScript JavaScript is a l...

JavaScript to achieve fixed sidebar

Use javascript to implement a fixed sidebar, for ...

JavaScript to implement image preloading and lazy loading

This article shares the specific code for impleme...

Tips on making web pages for mobile phones

Considering that many people now use smartphones, ...

Example of how to set WordPress pseudo-static in Nginx

Quoting Baidu's explanation of pseudo-static:...

Tomcat class loader implementation method and example code

Tomcat defines multiple ClassLoaders internally s...

vue.js downloads pictures according to picture url

Recently, when I was working on a front-end vue.j...

Detailed examples of ajax usage in js and jQuery

Table of contents Native JS How to send a get req...

Implementation of 2D and 3D transformation in CSS3

CSS3 implements 2D plane transformation and visua...