Home > Database > Mysql Tutorial > How to set default value in mysql

How to set default value in mysql

coldplay.xixi
Release: 2020-10-29 16:23:04
Original
15762 people have browsed it

Mysql method of setting the default value: Use mysql to create a data table and set the default value. The code is [stuSex varchar(2) default 'male' check(stuSex in('male', 'female'))].

How to set default value in mysql

Mysql method to set the default value:

create table stu(
stuId varchar(30) primary key,
stuName varchar(50) not null,
stuSex varchar(2) default '男' check(stuSex in('男', '女')),
stuJg varchar(30),
stuDept varchar(40)
)
Copy after login

Use mysql to create a data table and set the default value:

int type: default 1; (add the value directly)

varchar type: default 'aaa' (use single quotes)

Another: After testing, in mysql, default should be written in before checking, otherwise an error will be reported

More related free learning recommendations:mysql tutorial(Video)

The above is the detailed content of How to set default value in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template