我正在设计一个 SQL 数据库,它有 2 个需要“manager_id”的表。“员工”表和“设施”表。因为经理被认为是员工,所以我不确定是否应该有一个单独的“经理”表,或者只是将其整合到“员工”表中。我是 SQL 新手,不确定这样的情况。这是我到目前为止的代码:
CREATE TABLE Employees (
emp_id NUMBER(5) NOT NULL,
emp_name VARCHAR2(20) NOT NULL,
emp_add1 VARCHAR2(30) NOT NULL,
emp_add2 VARCHAR2(30) NOT NULL,
emp_add3 VARCHAR2(30),
emp_town VARCHAR2(30),
emp_county NUMBER(2) NOT NULL,
emp_telno NUMBER(10),
emp_position NUMBER(3) NOT NULL,
emp_manager NUMBER(4),
CONSTRAINT pk_empid PRIMARY KEY (emp_id),
CONSTRAINT fk_empcounty FOREIGN KEY (emp_county) REFERENCES County(county_id),
CONSTRAINT fk_empposition FOREIGN KEY (emp_position) REFERENCES Positions(position_id),
CONSTRAINT fk_empmanager FOREIGN KEY (emp_manager) REFERENCES Manager(manager_id)
);
CREATE TABLE Facilities (
facility_id NUMBER(2) NOT NULL,
facility_name VARCHAR(15) NOT NULL,
facility_manager NUMBER(4) NOT NULL,
CONSTRAINT pk_facilityid PRIMARY KEY (facility_id);
CONSTRAINT fk_facilitymanager FOREIGN KEY (facility_manager) REFERENCES Manager(manager_id)
);