Jump to content

[SOLVED] Creating New MySQL Tables With an Auto Incrementing Name


Akenatehm

Recommended Posts

Hey Guys,

 

What I need to do is create a table that has a name auto incrementing. For example:

 

Creates Table "table1"

 

Creates Table "table2"

 

Creates Table "table3"

 

The script is querying the database to see what the next number is

 

OR

 

Another Script Somewhere Else Tries to Create "table2"

 

It finds out that it already exists.

 

and then it keeps going up the numbers. "table4" etc. till it finds one that isn't taken up.

 

Any help will be greatly appreciated.

We are creating an instant messaging client. This would be creating the chat rooms, where all the conversations are stored. Messages and Senders will be listed in here.

Here is how I mean:

 

chatroom1

chatroom2

chatroom3

to

chatroom40 etc etc

Well, you'll have your users table, then you'll have your chatrooms table, then you'll have your messages table:

 

CREATE TABLE msgs (

    user_id INT NOT NULL, --author

    chatroom_id INT NOT NULL,

    message_content text

);

 

 

Edit:  Google "database normalization" and you might develop a better approach of how to store data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.