Creating a foreign key for system tables

I want to create a table with columns:

IdRole IdProcedure 

the idea is that IdProcedure is FK before sys.objects .

When I create this query:

 SELECT * FROM sys.objects WHERE type='p' 

It works fine, but this one:

 ALTER TABLE dbo.CORE_ProcedureXRole ADD CONSTRAINT FK_SysProcedure FOREIGN KEY (IdProcedure) REFERENCES sys.objects(object_id) 

tells me:

The foreign key 'FK_SysProcedure' refers to the invalid table 'Sys.objects'.

+6
source share
1 answer

sys.objects not a table. This is a system view supported by data stored in the proprietary SQL Server format. If you want to make sure that the saved name is correct, add TRIGGER to update and paste to process validation.

+1
source

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


All Articles