[英]How to create database schema in such a way that one employee can be part of one department only?
How to create database schema in such a way that one employee can be part of one department only.如何以一种员工只能属于一个部门的方式创建数据库模式。 There are three tables of a company "Employee table" "Department table" and "Region table".
公司有“员工表”、“部门表”和“地区表”三个表。
You do this by having a department_id
column in employees
:您可以通过在
employees
中设置department_id
ID 列来实现此目的:
create table employees (
. . . ,
department_id int,
. . .
constraint fk_employees_department foreign key (department_id) references departments(department_id)
);
If you want to require that each employee is always in a department, then use not null
:如果你想要求每个员工总是在一个部门,那么使用
not null
:
department_id int not null,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.