|
-
Jan 25th, 2009, 04:41 AM
#1
Thread Starter
Addicted Member
SQL Views with Computed Columns
Hi Guys,
Is it possible for me to create views with persisted column?
Code:
CREATE VIEW dbo.viewTable AS
SELECT
Item1,
Item2,
Total AS (Item1+Item2) PERSISTED
FROM
Table1 t1
JOIN
Table2 t2
ON
t1.ID = t2.ID
Also what is the proper syntax for this?
Last edited by jsc0624; Jan 25th, 2009 at 04:45 AM.
-
Jan 25th, 2009, 11:47 AM
#2
Re: SQL Views with Computed Columns
What version of MS SQL SERVER are you using?
Or is this even MS SQL?
VIEW's can have "computed" columns - that's kind of one of the major features of a VIEW.
Give us more info on what your actual goal is here.
-
Jan 25th, 2009, 01:53 PM
#3
Re: SQL Views with Computed Columns
Persisted is a new feature in SQL Server 2005 that if used will store the result of the computed column. Primarily used to allow indexing on computed columns.
-
Jan 25th, 2009, 02:01 PM
#4
Re: SQL Views with Computed Columns
So PERSISTED takes the place of manually putting an INDEX on a computed column - which would have persisted it in the past.
Is that kind of the point?
I've used computed columns in a table once. Then eventually dropped the concept as it only made inserting rows into that table painful.
-
Jan 25th, 2009, 02:49 PM
#5
Re: SQL Views with Computed Columns
Sorry, misread the docs. Persisted is required if the computed column is based on a CLR expression and you want it to be indexed.
-
Jan 26th, 2009, 03:55 AM
#6
Re: SQL Views with Computed Columns
Why are you designing indexes on computed columns rather than on keys? There are other tuning methods such as checking query explain plan, disk I/O, etc, creating an index is not a one size fits all solution.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|