开发者

Are computed columns in a view persisted?

开发者 https://www.devze.com 2023-04-12 05:37 出处:网络
CREATE VIEW [dbo].[MyView] ([ID],[VisitDate],[StartDate] ,[EndDate]) WITH SCHEMABINDING AS SELECTid, VisitDate,dateadd(dd,-10,VisitDate)persisted,
CREATE VIEW [dbo].[MyView] ([ID],[VisitDate],[StartDate] ,[EndDate])
WITH SCHEMABINDING  

    AS
    SELECT     id, VisitDate,dateadd(dd,-10,VisitDate)persisted,
       dateadd(dd,10,VisitDate)persisted
    FROM         dbo.Visits

I have a non-clustered index on ID and VisitDate.I wantd to know开发者_StackOverflow if the computed columns StartDate and Enddate is persisted or is it calculated runtime when view is referenced

EDIT:what if i have a unique clustered index on ID and VisitDate.In that case will these columns become persisted?


In your view, the values are calculated at runtime. The word "persisted" there is treated as the column name, not a special keyword.

If you want to create calculated columns that are persisted, you need to do so as part of the table definition, either in the CREATE TABLE statement, or as an UPDATE TABLE statement. You could also consider using an indexed view.

See the documentation for more details:

  • Computed Columns
  • Creating Indexed Views


Yes.

The result set of an indexed view is physically persisted in the database in a manner similar to that of typical table storage.

https://technet.microsoft.com/en-us/library/dd171921(v=sql.100).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号