Skip to content

Commit

Permalink
新增 建表 代码样例
Browse files Browse the repository at this point in the history
  • Loading branch information
Leetfs committed Sep 27, 2024
1 parent 1348e8c commit 4be3da2
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion docs/zh/sql/06/biao.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,54 @@ priority: 2
### 外键
- 不是当前表的主键
- 参照了其他表的主键列/与其他表的主键列相对应
- 他就是当前表的外键
- 他就是当前表的外键

### 建表

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',
```

0 comments on commit 4be3da2

Please sign in to comment.