Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: MySQL Table Creation using DBI

by PhiRatE (Monk)
on Sep 06, 2002 at 00:44 UTC ( #195547=note: print w/replies, xml ) Need Help??

in reply to MySQL Table Creation using DBI

You need to read about database normalisation.

Essentially, what you have here is not a large complicated data structure containing many fields, but a very simple data structure containing very few, as so:

table stats ( jobid INT, try INT, item VARCHAR(255), value VARCHAR(255), # or maybe TEXT or equivalent PRIMARY KEY (jobid, try) );

Or similar. You would then be able to retrieve all the contents of the hash by:

select item, value from stats where jobid=273118 and try=1

It also allows you to get nice aggregate stats as so:

select owner, count(*) as n from stats where try=1 group by owner orde +r by n
Which would give you a nicely sorted list of all the different owners in all the jobs, and a count of how many jobs they own.

Even better, its trivial to code for to load and unload from the hash..

foreach (keys %hash) { $dbi->do('insert into stats (jobid,try,item,value) (?,?,?,?)',$job +id, $try, $_, $hash{$_}); }

Read a good book on SQL, or if you alreayd know SQL decently, on database normali|sz|ation and what it means for your data structures.

Create them well, and the database will end up doing all the work for you.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://195547]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-06-09 08:28 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.