HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Why SQL Server doesn't support foreign key constraints on views?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
whyconstraintskeysqlforeignviewsdoesnserversupport

Problem

I know that SQL Server doesn't support using a view as the reference for a foreign key constraint, is there a reason (i.e. something to do with the relational model) this is the case? It seems like it would be useful....

Solution

There's no fundamental problem with doing this, since tables and views are both relation variables in the relational model. Foreign key constraints are just a particular subclass of general constraints, which standard SQL implements using CREATE ASSERTION so there's no particular SQL language difficulty either.

According to this Connect item (no longer available, and not archived) it's simply a matter of prioritization. If you would find this feature useful, vote for the item and particularly add details of your use case in the comments.

Context

StackExchange Database Administrators Q#29571, answer score: 15

Revisions (0)

No revisions yet.