我们公司有人决定使用3个视图来支持网页,并且它们必须包含相同的子列。因此,我有如下定义:
CREATE VIEW EmailReceivedView
AS
SELECT
dbo.EmailReceived.ID
, ...lots of columns
FROM dbo.EmailReceived
LEFT OUTER JOIN ...more tables
--Emails related to reviews
CREATE VIEW ReviewEmailReceivedView
AS
SELECT RV.ReviewID, V.*
FROM ReviewEmailReceived RV
INNER JOIN EmailReceivedView V ON EmailReceivedID = V.ID
--Emails related to grants
CREATE VIEW GrantEmailReceivedView
AS
SELECT GV.GrantID, V.*
FROM GrantEmailReceived GV
INNER JOIN EmailReceivedView V ON GV.EmailReceivedID = V.ID
我在依赖视图中使用了V.*的原因是,在支持视图发生更改时,我希望依赖视图能够反映这些更改。但在SQL Server中,除非我重新运行ALTER脚本,否则不会发生这种情况。为什么呢?是否有一种方法可以确保对支持视图的更改自动反映在依赖项中?
with schemabinding
吗?它有帮助你自动更新视图吗? - Saeed Neamati