Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.