How to create a table in mysql and add field comments

How to create a table in mysql and add field comments

Directly post code and examples

#Write comments when creating a table CREATE TABLE userinfo(
	id INT COMMENT 'Number',
	uname VARCHAR(40) COMMENT 'User name',
	address VARCHAR(120) COMMENT 'Home address',
	hobby VARCHAR(200) COMMENT 'hobby'
 
)COMMENT = 'User information table';
 
#Modify the comment of the table ALTER TABLE userinfo COMMENT 'User information table';
 
#Modify the comment of the field. Note: just write the field name and field type. ALTER TABLE userinfo MODIFY COLUMN uname VARCHAR(40) COMMENT 'name';
 
#To view the table comments, see SHOW CREATE TABLE userinfo in the generated SQL statement;
#Look in the metadata table USE information_schema;
SELECT * FROM TABLES WHERE TABLE_SCHEMA='shoppingcart' AND TABLE_NAME='userinfo';
 
#Method to view field comments SHOW FULL COLUMNS FROM userinfo;
#Look in the metadata table SELECT * FROM COLUMNS WHERE TABLE_SCHEMA='shoppingcart' AND TABLE_NAME='userinfo'; 

Supplement: MySQL adds fields and comments to existing data tables

Problem Description: In the process of developing a system, it is often necessary to appropriately modify the original table structure as the system service functions expand or the relationship between services is expanded, for example, adding some necessary fields.

Example: Add three fields: device IP, device name, and device type to the existing device table device.

Problem Solving

Method 1 (Command line method)
Use the MySQL command. In the MySQL client tool or command line, execute the following command:

ALTER TABLE device ADD COLUMN `device_ip` VARCHAR(32) DEFAULT NULL COMMENT 'Device IP';
ALTER TABLE device ADD COLUMN `device_name` VARCHAR(128) DEFAULT NULL COMMENT 'Device name';
ALTER TABLE device ADD COLUMN `device_type` VARCHAR(32) DEFAULT NULL COMMENT 'Device type';

or

ALTER TABLE device ADD COLUMN 
(`device_ip` VARCHAR(32) DEFAULT NULL COMMENT 'Device IP',
`device_name` VARCHAR(128) DEFAULT NULL COMMENT 'Device name',
`device_type` VARCHAR(32) DEFAULT NULL COMMENT 'Device type');

Method 2 (Client Tool Method)

Use MySQL visualization tools, such as SQLyog, Navicat.

Right-click the table name-->Select Design Table-->Add fields, fill in the corresponding properties, and save.

This is the end of this article about how to add field comments to MySQL table creation. For more relevant content about adding field comments to MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL creates three relationship tables in practice
  • How to quickly create a test data table with 8 million entries in MySQL
  • MySQL and PHP basics and application topics: creating database tables
  • Python saves dict dictionary type data to Mysql and automatically creates tables and columns
  • MySQL learning to create and operate databases and table DDL for beginners
  • The first step in getting started with MySQL database is to create a table
  • Mysql table creation foreign key error solution
  • MySQL create table operation command sharing

<<:  Vue uses Canvas to generate random sized and non-overlapping circles

>>:  Summary of tips for making web pages

Recommend

Native JS to implement sharing sidebar

This article shares a sharing sidebar implemented...

HTML n ways to achieve alternate color code sample code

This article mainly introduces the sample code of...

Use standard dl, dt, dd tags to discard table lists

Now, more and more front-end developers are starti...

A detailed introduction to JavaScript primitive values ​​and wrapper objects

Table of contents Preface text Primitive types Pr...

Detailed tutorial on building Gitlab server on CentOS8.1

There is no need to say much about the difference...

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...

Detailed explanation of Linux commands and file search

1. Perform file name search which (search for ...

The docker-maven-plugin plugin cannot pull the corresponding jar package

When using the docker-maven-plugin plug-in, Maven...

Navicat connection MySQL error description analysis

Table of contents environment Virtual Machine Ver...

About CSS floating and canceling floating

Definition of Float Sets the element out of the n...

Use vue to implement handwritten signature function

Personal implementation screenshots: Install: npm...

MySQL learning database backup detailed explanation

Table of contents 1.DB,DBMS,SQL 2. Characteristic...

How to set up scheduled tasks in Linux and Windows

Table of contents Linux 1. Basic use of crontab 2...