Home  >  Article  >  Database  >  mysql sets the default value of a field

mysql sets the default value of a field

coldplay.xixi
coldplay.xixiOriginal
2020-10-09 14:55:467032browse

Mysql method of setting the default value of a field: 1. Add fields and set the default value; 2. Through sql statements, the code is [alter table t_user add type int(11) DEFAULT '1' COMMENT" "].

mysql sets the default value of a field

Mysql method to set the default value of a field:

1. First, introduce the use of navicat to add to the mysql table Fields and setting default values ​​will be introduced later using SQL statements directly.

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

mysql sets the default value of a field

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

mysql sets the default value of a field

#3. Then click Add Field, a blank row will be added at the end of the table field. If you don’t want to put the newly added field at the end, you can first select a field and then click Insert Field to insert a blank row before the field you just selected.

mysql sets the default value of a field

4. Next, fill in the name, type, length of the field to be added in the blank line, and whether it is empty. One of the two blank input boxes below is The default value of the setting and the other is the comment. After filling in the information as shown in the figure, click the save button.

mysql sets the default value of a field

5. In addition to adding fields and setting default values ​​through the above image operations, you can also use sql statements

alter table t_user add type int(11) DEFAULT '1' COMMENT '用户类型(1:普通用户,2:会员)';

add is followed by adding The field name and type, DEFAULT is followed by the default value, COMMENT is the comment content

mysql sets the default value of a field

6. After executing the sql statement, check the table structure information, you can see that the field just now has been Correctly added to the table.

mysql sets the default value of a field

Related free learning recommendations: mysql database(Video)

The above is the detailed content of mysql sets the default value of a field. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn