Search

Please allow creation of temporary views by lovalvob

Closed
as Won't Fix Help for as Won't Fix

22
0
Sign in
to vote
Type: Suggestion
ID: 640863
Opened: 2/1/2011 8:10:47 PM
Access Restriction: Public
0
Workaround(s)
Temp views would be very convenient.

I often create very complex SPs that perform multiple operations on a table or series of tables. In order to be efficient, a complex predicate is applied to the target table. Because the SPs have multiple steps, that complex predicate must be written and maintained repeatedly.

If I could create temporary views (Create view #ONE_TIME...), I could apply the predicate to the view, and use that view for the rest of the operations.
Details (expand)
Product Language
English

Category

SQL Engine

Proposed Solution

Allow the creation of temporary views using the # syntax

Benefits

Faster Development
Improved Reliability
Improved Performance

Other Benefits

 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Jamie Thomson on 12/19/2011 at 5:38 AM
Why on earth has this been closed? The suggested workaround is a poor one for many reasons (not least that you have to go and DROP it) and lovalvob has provided a very good reason why this is not-satisfactory.
I agree with lovalvob that temporary views would be very useful for porducing concise, readable code and moreover would support the principle of DRY (i.e. Do not repeat yourself).

I have re-raised this here: https://connect.microsoft.com/SQLServer/feedback/details/714617/t-sql-please-provide-temporary-views
Posted by lovalvob on 5/24/2011 at 1:40 PM
I'm afraid that I didn't notice the reply. The workaround won't work for the following reasons:
1) Create View does not allow the specification of a DB, so you must 'use' tempdb first.
2) I don't think that the 'use' clause is allowed in SPs, which is where most of this would happen.
3) If more than a single instance of the code was running, the drop/create cycles would step on each other.

The purpose of temp views is to isolate complex selection logic near the start of a process and to reference it throughout the rest of the script/sp.
Posted by lovalvob on 5/24/2011 at 1:34 PM
I'm afraid that I didn't notice the reply. The workaround won't work for the following reasons:
1)
Posted by Microsoft on 5/24/2011 at 12:40 PM
Hello, as earlier suggested, there is a workaround using the tempDB, therefore we are not going to pursue this any further.

Best regards
Microsoft SQL Server Engine Team
Posted by Microsoft on 2/21/2011 at 9:04 AM
Thanks for contacing SQL Server team. You can create a view in the tempDB as follows
++++++++++++++
use tempdb
go

create view tempview as select * from locktest..basic_locking where c1 > 200
++++++++++++++++
You can then drop this view. Wondering if this will meet your needs?

thanks
Sunil
Sign in to post a workaround.