mysql - Creating a table with the name being a variable date? -


i wanted create table name of table being date. when gather stock data day, wanted store this:

$date = date('y-m-d'); $mysqli->query(     "create table if not exists `$date`(id int primary key)" ); 

that way have database like:

2013-5-1: aapl | 400 | 400k           mfst | 30  | 1m           goog | 700 | 2m 2013-5-2: ... 

i think easier store information this, see similar question closed.

how add date mysql table name?

"generating more , more tables opposite of "keeping database clean". clean database 1 sensible, normalized, fixed schema can run queries against."

if not right way it, suggest be? many people commenting on question stated not "clean" solution?

do not split data several tables. become maintenance nightmare, though might seem sensible @ first.

i suggest create date column holds information want put table name. databases pretty clever in storing dates efficiently. make sure use right datatype, not string. adding index column not performance penalty when querying.

what gain full flexibility in querying. there virtually no limits data can extract table this. can join other tables based on date ranges etc. not possible (or @ least more complicated , cumbersome) when split data date tables. example, not easy average of value on week, month or year.

if - , that's depending on real amount of data collect - time in future data grows dramatically, more several million rows estimate - can have @ data partitioning features mysql offers out of box. however, not advise use them immediately, unless have cut growth model data.

in experience there seldom real need technique in cases. have worked tables in 100s of gigabytes range, tables having millions of rows. matter of indexing , crafted queries when data gets huge.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -