Quantcast
Channel: Answers by "Kevin Feasel"
Viewing all articles
Browse latest Browse all 15

Answer by Kevin Feasel

$
0
0
A normal view is just a saved query, nothing more. The data isn't saved on the disk--it isn't materialized. Thus, you cannot have integrity constraints (check constraints, foreign keys, or primary keys) on a view: there's nothing to constrain. Even an index view--which is materialized--does not allow for constraints. It sounds like you are using this for a data warehouse. If you are, there are two options available: either put the foreign key constraint onto the Date table (as @KenJ mentions), or don't have any constraints at all. In a data warehouse, it isn't necessarily a bad thing not to have constraints so long as you only have one way of moving data in and never add, remove, or update data outside of the single process. But if you're doing this in the guise of an OLTP database, I'd say just join to the Date table, and if you need additional constraints (like having an OrderDate less than ShipDate), add check constraints on the fact table itself.

Viewing all articles
Browse latest Browse all 15

Trending Articles