Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Creating new tables is database specific, although DBI allows you to send through any database-specific commands directly to driver.

I am guessing if you want to create many tables, all these tables will be similar, right? Maybe you can create one meta-table, with fields like TBLNAME, KEY, CHARFLD1, CHARFLD2, ... NUMFLD1, NUMFLD2..., TXTFLD1, TXTFLD2... etc. Then, instead of creating table, you need just insert rows into meta-table. This way you will have new table implemented as "SELECT * FROM meta-table WHERE TBLNAME = 'mynewtable'". I know that proposed implementation might be half-empty meta-table (often most of the fields will not be used), but OTOH you can add "table" dynamically.

We used this approach once and it was very successfull. We have database which was very touchy when DB stucture changed - all code required recompilation. Using our approach we avoided a lot of pain. We put more that hundred small simple tables (CODE DESCRIPTION) and were able to add new features into our code which usually reqired changes of structure rather easy.

Here is how to optimize this approach: (1) you need index by TBLNAME and KEY. (2) if you want to avoid many empty fields, you may put all remaining fields (after TABLENAME and KEY) into one long text field as CSV (comma-separated values), packing and unpacking them as needed.

Obviously, meta-table approach is valid if you need to store hundreds small tables (between dozen and couple hundred rows each max), if you want to have hundreds of thousands of rows, it deserves special table.

I hope it makes sense, it's too late and I am sleepy like a dog now...If you need more info, /msg or reply here.

pmas
To make errors is human. But to make million errors per second, you need a computer.


In reply to Re: have a script autmatically create a SQL database by pmas
in thread have a script autmatically create a SQL database by lwilliams

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found