Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

temp table in view Expand / Collapse
Author
Message
Posted Thursday, October 28, 2010 12:52 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, March 25, 2011 11:46 AM
Points: 15, Visits: 49
Hello All,

Is it a good practice to use a temp tables in a view?
How do we handle temp tables in views?

Please explain in detail.

Thank you,
Sra1
Post #1012589
Posted Thursday, October 28, 2010 1:23 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 2:05 PM
Points: 1,072, Visits: 6,329
sravanb (10/28/2010)
Hello All,

Is it a good practice to use a temp tables in a view?
How do we handle temp tables in views?

Please explain in detail.

Thank you,
Sra1


Others will provide a far more sophisticated answer, here's the simple one: if a view is a persisted or "permanentised" query, then what's something transient and undefined gotta do with it?



Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




Understanding and using APPLY, (I) and (II) Paul White

Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Post #1012604
Posted Thursday, October 28, 2010 1:33 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:23 PM
Points: 6,131, Visits: 7,170
Is it good practice to use temp tables in a view...

Quick Answer: You can't. Views are single statement activities.

You can use cte's to help keep code readable. You can subselect to the end of the earth. But you can't do multi-part statements.

If the question is regarding a global temp table (##tmp)... don't do it. More headaches then it'll ever be worth to you.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1012612
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse