diff --git a/docs/zh/sql/06/biao.md b/docs/zh/sql/06/biao.md index a0befb2..7cdeb92 100644 --- a/docs/zh/sql/06/biao.md +++ b/docs/zh/sql/06/biao.md @@ -17,4 +17,54 @@ priority: 2 ### 外键 - 不是当前表的主键 - 参照了其他表的主键列/与其他表的主键列相对应 -- 他就是当前表的外键 \ No newline at end of file +- 他就是当前表的外键 + +### 建表 + +create table Department +( + 表名+类名+数据类型 +) + +```sql +create table Department +( + DepartmentID char(4) primary key, + DepartmentName char(4) foreign key references Title(TitleID) +) +``` + +- 主键:primary key +- 外键:foreign key +- 唯一键:unique +- 默认值:default + +```sql +DepartmentName char(4) foreign key references Title(TitleID) +外键,参照了Title表的TitleID +简略写法: +DepartmentName char(4) foreign key(TitleID) +``` + +### 创建班级class表 + +```sql +create table class +( + ClassID char(8) primary key, + ClassDep char(4) foreign key, + ClassTeacherID char(10) foreign key, + ClassName nvarchar(20) , + Amount int +) +``` + +### 唯一键 样例 +```sql +ClassName nvarchar(20) unique, +``` + +### 默认值 4 +```sql +ClassName nvarchar(20) default '4', +``` \ No newline at end of file