SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to use temp tables or other less resources in store proc


how to use temp tables or other less resources in store proc

Author
Message
asita
asita
Say Hey Kid
Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)

Group: General Forum Members
Points: 664 Visits: 337
Hello All,

Could you please help me out, i am in a wierd situation,


i have a sql store procedure (about 1350 lines in it), which quries data different tables and loads data to tables (about 11 tables)

the reason, the above procedure is generating 11 tables, i am using only 4 tables in these 11, but these 11 tables were derived internally data connected,


so the requirement is, after execute the procedure we want to generate only 4 tables(which i need, presently using) , i need to consolidate the proc to generate only 4 tables.



the reason why it is generating 11 tables is,

step1 load data to table, scrub and then apply some additionl logic then prepare table 2, then some update and union and insert to table 3 (using table 2 and table 1 and some other tables... etc it will go till 11 tables)


can i use temp tables ? here in proc to replace these 11 tables, so that i will have only required 3 tables in db remain all for temporary calculation, but temp tables shoun't visible after proc exec completes in db, or any other ideas please, does temp tables stay till proc execution completes or only valid for single sql statement ......


help me here, please assist me, guide me with all open ideas


thanks in advance
asitti
laurie-789651
laurie-789651
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1484 Visits: 1272
You can select data into temp tables like this:



select *
into #TempTable
from dbo.table




Temp tables starting with one # exist for the session, or until you drop them. If you create them in a stored procedure, the temp tables will be dropped when it finishes.

You can drop them yourself like this:



drop table #TempTable




A simple solution might be to just drop the unwanted tables at the end of the stored procedure.
asita
asita
Say Hey Kid
Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)Say Hey Kid (664 reputation)

Group: General Forum Members
Points: 664 Visits: 337
hi laurie,

thanks alot for your response,

great idea i will try to learn the #temptables

but others please post any other ideas as well... please

i will follow this

best regards
asita
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search