2

I have three tables as follows -

enter image description here

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 enter image description here

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 !

Community
  • 1
  • 1

1 Answers1

5

Try closing SSMS and then reopening it again. Seems like the cache used by SSMS for some of functionality is not refreshed even upon closing and re-opening the database connection. check https://stackoverflow.com/a/4316415/364084

umbersar
  • 1,821
  • 3
  • 24
  • 34