Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of setting the default value of a field by mysql

2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the method of setting the default value of a certain field in mysql. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Mysql sets the default value of a field: 1, add the field and set the default value; 2, through the way of sql statement, the code is [alter table t_user add type int (11) DEFAULT'1' COMMENT "].

Mysql method to set the default value of a field:

1. First introduce the use of navicat to add fields and set default values to the mysql table, followed by the direct use of SQL statements.

Open the navicat tool and connect to the mysql database service. As shown in the figure, you can view all the tables, select one of the tables that need to add fields, and then right-click to select the design table.

2. On the design table page, you can see all the fields and types of the current table, and the graphical tool can see each field information intuitively, which is much more comfortable than the command line.

3. Then click add field, and a blank line will be added at the end of the table field. If you don't want to put the new field at the end, you can select a field first, and then click insert field to insert a blank line in front of the field you just selected.

4. Next, fill in the blank line with the name, type, length, and whether the field to be added is empty. The two blank input boxes below are the default value and the comment. After filling in the information, click the Save button.

5. In addition to adding fields and setting default values as the image operation above, you can also use the sql statement

Alter table t_user add type int (11) DEFAULT'1' COMMENT 'user type (1: ordinary user, 2: member)'

Add is followed by the added field name and type, DEFAULT is followed by the default value, and COMMENT is the comment content

6. After executing the sql statement, looking at the table structure information, you can see that the fields have been correctly added to the table.

This is the end of the method of setting the default value of a certain field in mysql. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report