tags:

views:

51

answers:

4

Hi All,

In our web app, we are creating session table in database to store temporary data. So the temp table will be created and destroyed for every user. I have some 300 users for this web app. So for every user these table will be created and destroyed.

i heard that this way of design is not good due to performance issues. I am using MS Sql server 2005. Is there any way to store a result set temporarily without creating any table.

Please suggest me some solution. Thanks.

A: 

I think, a solution at GenerateData is what you are looking for. You can create test/sample databases their and delete them when needed.

Sarfraz
A: 

Depending on what you're actually doing (and whether you can refactor it) it may be more appropriate to use table variables which are highly performant in general.

There is a question of whther the DB is really an appropriate place to even be trying to persist data sets if it's for your applications benefit - if the question isn't just academic perhaps it would be better to keep the object representation of the data in your app memory?

annakata
Temp tables are actually often better performers than table variables if the data set is large.
HLGEM
how would that persist across multiple page calls?
KM
@KM - It wouldn't, but I didn't see a requirement up there that it needed to. Frankly if you're persisting data sets for business reasons I'm usually doing that in the business logic, not in the repository.
annakata
I'm not sure exactly what the OP is doing, they say: `In our web app, we are creating session table in database`, with that I thought they meant to persist across page calls, if not that then just use variables in the web application language, no need to store then in the DB if they will be flushed when the current page processing is done.
KM
+2  A: 

Either:

use a single permanent database table for all users, with a UserID column to filter on

or

just use the session handling ability of your web platform to store the info

KM
SOunds like with further information that the second possibly is what he really wants. Send a dataset to the web platform and maintain the data through the sesion.
HLGEM
But i am using the result set inside the trigger. Inside the trigger i am using the temporary result set for further processing.
Manoj
@Manoj said `But i am using the result set inside the trigger`, why oh why did you not one time mention `trigger` in the question? you only further obscured the real question by including `web app` and `session` in the question. I have no idea what your question is asking, please edit your question to make it more clear what is going on here!
KM
+1  A: 

It sounds as if you are creating and dropping permanent tables. Have you tried using real temp tables (those with table names beginning with #). OR table variables if you havea small data set. Either of these can work quite well. If you use real temp tables, you need to make sure your tempdb is sized large enough to accomodate the usual amount of users, growing tempdb can cause delays.

HLGEM
You'll also need to make sure the connection to the DB is maintained, or the temp table will go ka-puts. To make it a little more lenient, might want to check out global temp tables.
Mike M.