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

How to write a picture as a background and a link (background picture plus link)

The picture is used as the background and the lin...

Linux IO multiplexing epoll network programming

Preface This chapter uses basic Linux functions a...

JS implements simple example code to control video playback speed

introduction I discovered a problem before: somet...

Example of removing json backslash in php

1. Remove backslashes through the "stripslas...

How to create your first React page

Table of contents What is Rract? background React...

Detailed explanation of CSS weight value (cascading) examples

•There are many selectors in CSS. What will happe...

Detailed explanation of Linux kernel macro Container_Of

Table of contents 1. How are structures stored in...

Three ways to avoid duplicate insertion of data in MySql

Preface In the case of primary key conflict or un...

Implementation steps for setting up the React+Ant Design development environment

Basics 1. Use scaffolding to create a project and...

Introduction to JavaScript strict mode use strict

Table of contents 1. Overview 1.1 What is strict ...

Canonical enables Linux desktop apps with Flutter (recommended)

Google's goal with Flutter has always been to...

Some notes on mysql create routine permissions

1. If the user has the create routine permission,...