欢迎来到MySQL实战第13篇,修炼500篇成为MySQL高手
1.测试非空
<1>创建表
create table test_not_null(
a varchar(20),
b varchar(20)not null
);
<2>插入数据
(1)insert test_not_null(a,b) values('','');
(2)insert test_not_null(a,b) values(null,null);
(3)insert test_not_null(a,b) values(null,'abc');
(4)insert test_not_null(a) values('Test');
2.测试默认值
<1>创建表
create table test_default(
id int unsigned auto_increment key,
username varchar(20) not null,
age tinyint unsigned default 18,
email varchar(50) not null default '[email protected]'
);
默认值可以用于枚举
create table test_default1(
id int unsigned auto_increment key,
sex enum('a','b','c') not null default 'a'
);
<2>插入数据
(1)insert test_default(username)values('A');
(2)insert test_default(username,age,email)values('B',30,'[email protected]');
(3)insert test_default(username,age,email)values('C',null,'[email protected]');
(4)insert test_default(username,age,email)values('D',null,null);
(5)insert test_default(username,age,email)values('E',null,default);
3.Unique key
<1>创建表
create table test_unique(
id int unsigned auto_increment key,
username varchar(20) not null unique key,
email varchar(50) unique,
card varchar(18)unique
);
<2>插入数值
(1)insert test_unique(username,email,card) values('A','A@@com','1');
(2)insert test_unique(username,email,card) values('A','1A@@com','12');
(3)insert test_unique(username,email,card) values('B',null,null);
(3)insert test_unique(username,email,card) values('C',null,null);
关注财务总监的数据分析,修炼MySQL,做个懂数据的人!