问题描述
是否有可能在Microsoft SQL Server Management Studio中的数据库视图定义主键和外键?怎么样?
我试图创建一个ADO.NET实体数据模型从四老,我不能修改不当形成的数据库表来读取。我创建的意见只是我需要的数据。
这四个观点应该映射到一个简单的三个实体EDMX一个多对一对多的关系。
我创造我的数据模型时出现此错误:
据推断正确的两种观点的主键。但未能与其他两个这样做。
我的一个问题的看法使用聚合函数:
SELECT MAX(...)... GROUP BY ...
另外应该有两个外键复合主键。
您需要定义您的视图,以便它:
- 包括所有的
PRIMARY KEY
列 - 在不使用任何
加入
的 - 在不使用任何聚合函数或
UNION
的
这是你的看法任意行应该映射到从表中的一行。
这不能更新。为只读实体,由溶液here:
对于第二个问题:
从 文件 :
Is it possible to define primary and foreign keys for database Views in Microsoft SQL Server Management Studio? How?
I'm trying to create an ADO.NET Entity Data Model to read from four old, poorly-formed database tables that I cannot modify. I've created views of just the data I need.
The four views should map to a simple three-entity EDMX with one many-to-many relationship.
I get this error when creating my Data Model:
It correctly inferred the primary keys of two views. But failed to do so with the other two.
One of my problem views uses aggregate functions:
SELECT MAX(...) ... GROUP BY ...
The other ought to have a compound primary key of two foreign keys.
You need to define your view so that it:
- Includes all the
PRIMARY KEY
columns - Does not use any
JOIN
's - Does not use any aggregate functions or
UNION
's
Any row from your view should map to exactly one row from the table.
It cannot be updateable. For a readonly entity, a solution from here:
For the second question:
From documentation:
这篇关于SQL Server视图可以通过主键和外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!