今日内容概要
- 约束条件
- default默认值
- unique唯一
- primary key 主键
- auto_increment自增
- 总结
- 表与表之间建关系
- 外键
- 表关系
- 一对多关系
- 多对多关系
- 一对一关系
- 总结
- 修改表
- 复制表
今日内容详细
约束条件
default默认值
\"\"\"
# 补充知识点,插入数据的时候,可以指定字段顺序
create table t1(
id int,
name char(16)
);
insert into t1(name,id) values(\'jason\',1);
create table t2(
id int,
name char(16) not null,
gender enum(\'male\',\'female\',\'others\') default \'male\'
);
mysql> desc t2;
+--------+-------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------------------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(16) | NO | | NULL | |
| gender | enum(\'male\',\'female\',\'other\') | YES | | male | |
+--------+-------------------------------+------+-----+---------+-------+
3 rows in set (0.05 sec)
insert into t2(id,name) values(1,\'jason\');
insert into t2 values(2,\'egon\',\'female\');
mysql> select * from t2;
+------+------------------+--------+
| id | name | gender |
+------+------------------+--------+
| 1 | jason | male |
| 2 | egon | female |
+------+------------------+--------+
2 rows in set (0.00 sec)
\"\"\"
来源:https://www.cnblogs.com/MRPython/p/15228886.html
图文来源于网络,如有侵权请联系删除。