MySQL第四课
create table biao(
name varchar(20) primary key,
age int(11) not null,
sex char(11)default 1,
love varchar(11)
);
query ok, 0 rows affected
此时name设置了主键约束,age设置了非空约束,sex默认值为一
查看: desc biao;
+-------+-------------+------+-----+---------+-------+
| field | type | null | key | default | extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(20) | no | pri | null | |
| age | int(11) | no | | null | |
| sex | char(11) | yes | | 1 | |
| love | varchar(11) | yes | | null | |
+-------+-------------+------+-----+---------+-------+
4 rows in set
添加数据:
1.
insert into biao (name,age,sex,love) values ('张三',41,'男','e');
query ok, 1 row affected
查看:select*from biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
+------+-----+-----+------+
1 row in set
2.
insert into biao values ('张',40,'男','em');
query ok, 1 row affected
select*from biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
| 张 | 40 | 男 | em |
+------+-----+-----+------+
2 rows in set
3.
insert into biao (sex) values ('男');
query ok, 1 row affected
select*from biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
| 张 | 40 | 男 | em |
| | 0 | 男 | null |
+------+-----+-----+------+
3 rows in set
4.
insert into biao(name,age,sex,love) values('李四',39,'女','ex'),('王五',38,'男','van'),('甲',20,'男','emm');
query ok, 3 rows affected
records: 3 duplicates: 0 warnings: 0
select*from biao;
+------+-----+-----+------+
| name | age | sex | love |
+------+-----+-----+------+
| 张三 | 41 | 男 | e |
| 张 | 40 | 男 | em |
| | 0 | 男 | null |
| 李四 | 39 | 女 | ex |
| 王五 | 38 | 男 | van |
| 甲 | 20 | 男 | emm |
+------+-----+-----+------+
6 rows in set