我正在创建公司目录,需要一些SQL Server数据库的帮助。
我所拥有的表格为Employees
,Departments
,Equipment
,Phonenumber
表Employees
,Department
,Equipment
可以有电话号码(许多电话号码)
就像这样,Employees
可以有电话录音和设备
Departments
可以拥有多个电话号码和许多设备
Equipment
可以有多个电话号码
希望得到一些帮助
答案 0 :(得分:1)
我认为您没有指出实际想到的所需相关性。我并不质疑它背后的意义。但是为了强调我从你的解释中得到的结论,我给出了一个简短的总结:
在这里,您将使用相应的表定义(摘录):
CREATE TABLE Employee (
id INT PRIMARY KEY,
equipment_id INT NOT NULL,
phone_number_id INT NOT NULL,
...
FOREIGN KEY (employee_equipment_id) REFERENCES Equipment (id)
FOREIGN KEY (employee_phone_number_id) REFERENCES PhoneNumber (id)
)
CREATE TABLE Department (
id INT PRIMARY KEY,
...
)
CREATE TABLE Equipment (
id INT PRIMARY KEY,
...
)
CREATE TABLE PhoneNumber (
id INT PRIMARY KEY,
...
)
CREATE TABLE DepartmentEquipment (
department_id INT NOT NULL,
equipment_id INT NOT NULL,
FOREIGN KEY (department_equipment_department_id) REFERENCES Department (id)
FOREIGN KEY (department_equipment_equipment_id) REFERENCES Equipment (id)
)
CREATE TABLE DepartmentPhoneNumber (
department_id INT NOT NULL,
phone_number_id INT NOT NULL,
FOREIGN KEY (department_phone_number_department_id) REFERENCES Department (id)
FOREIGN KEY (department_phone_number_phone_number_id) REFERENCES PhoneNumber (id)
)
CREATE TABLE EquipmentPhoneNumber (
equipment_id INT NOT NULL,
phone_number_id INT NOT NULL,
FOREIGN KEY (equipment_phone_number_equipment_id) REFERENCES Equipment (id)
FOREIGN KEY (equipment_phone_number_phone_number_id) REFERENCES PhoneNumber (id)
)