MySQL Auto Table Creation

Discussion in 'Databases' started by Wizeman29, Oct 6, 2009.

  1. #1
    Hello, i have a database in SQL and a Table, how can i auto create a table according the value of a record on the first table. For a exable let say that a user is sign up, then a text filed called referal (For exable) shows a row in the first table that have an initial value if the user does not put anything in that text filed, but if the user ender data in that field then a table is created with name equals with the ender data. (the endered data is usual represends a record on the first table. How can i do that?? should a variable work? (Sorry for my english).
     
    Wizeman29, Oct 6, 2009 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    First and foremost--you shouldn't do this. It reeks of an unnormalized database and will most definetly give you fits on down the line.

    With that out of the way, here's how you would generally accomplish this: You would do this programmatically.

    First you would retrieve the value(s) from that initial table with a SELECT query, putting them into a variable, then you would use a programming language to create and execute a CREATE TABLE query in SQL using the necessary information you retrieved from the SELECT query.

    And remember--don't do this.
     
    plog, Oct 6, 2009 IP
  3. Wizeman29

    Wizeman29 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So you say that the database will Crash??? What you suggesting for Programming language?? You think that PHP should Work? Thanks.
     
    Wizeman29, Oct 9, 2009 IP
  4. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #4
    The database won't crash, its just not the right way to set up a database. Google: 'database normalization'.

    I'm not suggesting a programming language, whichever one you are most comfortable with should work as long as it can interact with your database. PHP would work.
     
    plog, Oct 9, 2009 IP
  5. Wizeman29

    Wizeman29 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks. it was rong afterall thinking to complicated, i find it after a while. Thanks anyway.
     
    Wizeman29, Oct 11, 2009 IP