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 tablesProblem 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) 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:
|
<<: Vue uses Canvas to generate random sized and non-overlapping circles
>>: Summary of tips for making web pages
Table of contents 1. Reduce the number of image l...
The picture is used as the background and the lin...
Preface This chapter uses basic Linux functions a...
introduction I discovered a problem before: somet...
1. Remove backslashes through the "stripslas...
Table of contents What is Rract? background React...
Use profile to analyze slow SQL The main purpose ...
•There are many selectors in CSS. What will happe...
Table of contents 1. How are structures stored in...
The difference between relative and absolute in H...
Preface In the case of primary key conflict or un...
Basics 1. Use scaffolding to create a project and...
Table of contents 1. Overview 1.1 What is strict ...
Google's goal with Flutter has always been to...
1. If the user has the create routine permission,...