1

我有三个表如下 -

在此处输入图像描述

但是当我添加外键引用时,关系是(数据库图中的一条直线)没有显示

以下是我写的参考。

ALTER TABLE [dbo].EmployeeDesignation   
ADD CONSTRAINT FK_EmployeeDesignation_Employee FOREIGN KEY (EmployeeId)     
    REFERENCES Employee (EmployeeId)     
    ON DELETE CASCADE    
    ON UPDATE CASCADE    
;

ALTER TABLE [dbo].[EmployeeDesignation]     
ADD CONSTRAINT FK_EmployeeDesignation_Designation FOREIGN KEY (DesignationId)     
    REFERENCES Designation (DesignationId)     
    ON DELETE CASCADE    
    ON UPDATE CASCADE    
;

此外,当我添加另外两个表 ( Department and EmployeeDepartment) 时,我可以在图中看到关系 在此处输入图像描述

参考代码如下——

ALTER TABLE [dbo].EmployeeDepartment     
ADD CONSTRAINT FK_EmployeeDepartment_Department FOREIGN KEY (DepartmentId)     
    REFERENCES Department (DepartmentId)     
    ON DELETE CASCADE    
    ON UPDATE CASCADE    
;

ALTER TABLE [dbo].EmployeeDepartment     
ADD CONSTRAINT FK_EmployeeDepartment_Employee FOREIGN KEY (EmployeeId)     
    REFERENCES Employee (EmployeeId)     
    ON DELETE CASCADE    
    ON UPDATE CASCADE    
;

后一个显示关系线而前一个没有显示的原因可能是什么?我错过了什么吗?

谢谢 !

4

1 回答 1

4

尝试关闭 SSMS,然后再次重新打开它。似乎 SSMS 用于某些功能的缓存即使在关闭和重新打开数据库连接时也不会刷新。检查https://stackoverflow.com/a/4316415/364084

于 2017-05-25T00:40:12.460 回答