Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何创建数据库模式,使一名员工只能是一个部门的一部分?_Mysql_Sql_Database - Fatal编程技术网

Mysql 如何创建数据库模式,使一名员工只能是一个部门的一部分?

Mysql 如何创建数据库模式,使一名员工只能是一个部门的一部分?,mysql,sql,database,Mysql,Sql,Database,如何创建数据库模式,使一名员工只能是一个部门的一部分。 公司“员工表”、“部门表”和“地区表”共有三个表。您可以通过在员工中设置部门id列来实现这一点: create table employees ( . . . , department_id int, . . . constraint fk_employees_department foreign key (department_id) references departments(department_i

如何创建数据库模式,使一名员工只能是一个部门的一部分。
公司“员工表”、“部门表”和“地区表”共有三个表。

您可以通过在
员工
中设置
部门id
列来实现这一点:

create table employees (
    . . . ,
    department_id int,
    . . . 
    constraint fk_employees_department foreign key (department_id) references departments(department_id)
);
如果要要求每个员工始终在一个部门,请使用
notnull

department_id int not null,

您可以通过在
员工
中设置
部门id
列来实现这一点:

create table employees (
    . . . ,
    department_id int,
    . . . 
    constraint fk_employees_department foreign key (department_id) references departments(department_id)
);
如果要要求每个员工始终在一个部门,请使用
notnull

department_id int not null,

将部门ID设置为员工表中的外键将部门ID设置为员工表中的外键