PDA

View Full Version : dynamic table creaton



baluk
30th November 2010, 12:17
Hi,

I am looking for a way to create dynamic tables in the database. In my app I have to store the user data to a table after every session. And the table should be different for every new session. I am thinking of creating a table name as an Index and increment it for every new session. This is just my thought. So I just wanted to know if it is possible or any other good ways to make this workable. I would be thankful for any suggestions. I want to use Sqlite database.

Thank You,
Baluk

wysota
30th November 2010, 12:26
You can name your tables any way the database engine lets you. There is no "right" or "wrong" approach here, it all depends on what you need those tables for. It might be worth naming them by date or by the name of the user (if you have multiple users).

BalaQT
30th November 2010, 12:51
hi,

I am looking for a way to create dynamic tables in the database. In my app I have to store the user data to a table after every session. And the table should be different for every new session. I am thinking of creating a table name as an Index and increment it for every new session. This is just my thought. So I just wanted to know if it is possible or any other good ways to make this workable. I would be thankful for any suggestions. I want to use Sqlite database.


can u explain it in detailed???


Bala

baluk
30th November 2010, 13:48
OKe. Suppose If i have created a table with name "1" in the first session. The next time when a new session starts a new table should be created let's say "2" in the same database. For the third session it should be "3". All this has to be done dynamically without writing a table name manually in the sql statement. I hope my explanation gives you an idea about my problem.

Since the user is same I can't use name and With the date is also a problem when a user uses more than 1 time in a day. May be I will have to go with the both date and time.

BalaQT
30th November 2010, 13:58
hi balu,

May be I will have to go with the both date and time.
yeah table with Datetime will be a good idea,

or u can create log table which stores all the table creation details and u can take the id from the log table.
ex:
DynamicLog(tabid int,timestamp datetime,userid int);
for the first time , this table will be empty. and when the user logs in, say tabel name 1 is created with the values inserted into the DynamicLog(1,time,userid);
then when the user again logs in , take DynamicLog's max(tabid)+1 and create the table with that id

hope it helps
Bala

wysota
30th November 2010, 15:37
OKe. Suppose If i have created a table with name "1" in the first session. The next time when a new session starts a new table should be created let's say "2" in the same database. For the third session it should be "3". All this has to be done dynamically without writing a table name manually in the sql statement. I hope my explanation gives you an idea about my problem.

Since the user is same I can't use name and With the date is also a problem when a user uses more than 1 time in a day. May be I will have to go with the both date and time.

Ok, but what exactly is the problem? You don't know how to insert the table name into sql statement or what?

baluk
30th November 2010, 16:41
Thank you for the suggestions. I am aware of Sql statements but I thought the Datetime is not very user friendly name to tables. That is why I was looking for some suggestions. Now my problem is solved.

Thank you,
Baluk

Lesiok
30th November 2010, 16:46
Hi,

I am looking for a way to create dynamic tables in the database. In my app I have to store the user data to a table after every session. And the table should be different for every new session....Sorry for my vocabulary but it is stupid:mad: Why are You want to use this crazy idea ???

baluk
30th November 2010, 17:21
Its oke. My app helps to record ratings for videos from the users viewed in my app. And these scores to be saved to a table in a database. So I have to make a new table for every user who takes the test but we don't care of usernames.

And I have another question about restarting my app. Since many users takes the test i have to exit and start the application for each user. Is there any way I can restart the application (starting new session)without closing and open it again.

Thank You,

Baluk

Lesiok
30th November 2010, 17:37
And how You will take some statistics from 10000 tables in example ?
You need ONLY one table with additional column with session_id.

wysota
30th November 2010, 17:48
Its oke. My app helps to record ratings for videos from the users viewed in my app. And these scores to be saved to a table in a database. So I have to make a new table for every user who takes the test but we don't care of usernames.
No, you don't "have to". You can have one table with an additional column storing session id and that's it.


And I have another question about restarting my app. Since many users takes the test i have to exit and start the application for each user. Is there any way I can restart the application (starting new session)without closing and open it again.
If there is such limitation then you have imposed it yourself. You can redesign your application to get rid of such constraint.