简体   繁体   English

在SSMS 20114中添加新外键引用时,数据库图未显示表关系

[英]Database Diagram not showing table relation when new foreign key reference is added in SSMS 20114

I have three tables as follows - 我有三个表,如下所示:

在此处输入图片说明

But when I add the foreign key reference, the relation is ( a straight line in the Database Diagram) not shown . 但是,当我添加外键引用时,该关系为(数据库图中的一条直线)未显示

Following is the reference I wrote. 以下是我写的参考。

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    
;

In addition, When I add another two tables ( Department and EmployeeDepartment ) I can see the relation in the diagram 另外,当我添加另外两个表( Department and EmployeeDepartment )时,我可以在图中看到关系 在此处输入图片说明

The code for the reference is as follows -- 供参考的代码如下-

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    
;

What might be the reason That the later one showing relation line while the previous one is not showing? 后面的一个未显示关系线而前一个未显示关系线的原因可能是什么? Am I missing something? 我想念什么吗?

Thanks ! 谢谢 !

Try closing SSMS and then reopening it again. 尝试关闭SSMS,然后再次将其重新打开。 Seems like the cache used by SSMS for some of functionality is not refreshed even upon closing and re-opening the database connection. 似乎SSMS用于某些功能的缓存即使在关闭并重新打开数据库连接后也不会刷新。 check https://stackoverflow.com/a/4316415/364084 检查https://stackoverflow.com/a/4316415/364084

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ERD中,表的外键是否可以在没有新关系的情况下引用中间表另一侧的表的主键 - In an ERD, can a foreign key of a table refer to the primary key of the table on other the side of of an intermediate table without a new relation 对新架构的外键引用 - Foreign key reference to a new schema 多态关联和外键引用可以引用相同的表。 如何制作新物品? - Polymorphic association and foreign key reference can reference same table. How do I make a new object? 尝试使用 FOREIGN KEY 创建新表时出现 mysql 错误 1822 - mysql error 1822 when trying to create new table with a FOREIGN KEY 有没有办法在表中没有主键的情况下创建外键关系 - Is there any way to create foreign key relation without primary key in the table 在另一表中添加新记录时如何更新一个表中的外键 - How to update foreign keys in one table when new record is added in another table Vaadin SQLContainer参考-如何实现外键关系? - Vaadin SQLContainer Reference - how to implement foreign key relation? 为什么在将 2 个表的关系输入到关系表中时出现外键约束错误? - Why am I getting a foreign key constraint error when entering a relation of 2 tables with data present into a relationship table? 在 SSMS 2012 中创建数据库图表时出错 - Error Creating Database Diagram in SSMS 2012 是否可以将外键引用到父表? - Is it possible to reference a foreign key to parent table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM