Home  >  Article  >  Database  >  How to set default value in mysql

How to set default value in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-10-28 16:40:5415608browse

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)
)

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!

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