Why are my newly created FK relationships not showing up in the object explorer?

I just added the PackageItems table to the existing SQL Server 2008 R2 database. I work in SQL Server Management Studio. After creating a new table, I created a relationship between this table and another Package table. The FK_PackageItems_Package relationship makes the primary key of the Package table (PackageID) the foreign key in my new PackageItems table. Both tables have a common column named PackageID (int, not null).

My question is the following. The primary and foreign keys for each other table in the database are clearly indicated in the "Object Explorer" panel in SSMS. I see gold or gray keys next to the columns, and I also see PK or FK in parentheses next. But my newly created relationship (FK_PackageItems_Package) is not represented in this way. Did I do something wrong?

Note. To create FK relationships, I went into the design view for PackageItems, clicked the Relationships icon, clicked Add, clicked the ... button next to Table and Column Specification. Then in the window that appeared, I selected Package as my main key table and PackageID. And I chose PackageItems and PackageID for my table and foreign key column.

Hope this is not a too stupid question. Thanks in advance for watching.

+3
source share
2 answers

When you open the Create Foreign Key dialog box, you will notice that the graphical interface adds a table design window. After setting the keys and closing the window, you must also save the table design.

+7
source

There may be a problem creating a foreign key design. If I try to create a foreign key with a GUI view, it will not be created. If I create it using a script, it does this.

To verify that the foreign key was created or not, you can use sp_help [TableName].

0
source

Source: https://habr.com/ru/post/1793403/


All Articles