Hi there. I was wondering if I could get veteran database designers' opinions on a design choice I have to make. See, I'm writing a piece of software using PHP and a SQL database (MySQL for now, hopefully Firebird in the future) that allows museums, archivists, collectors, etc catalogue their data. The user will be able to create their own tables any way they like, with whatever fields. I guess it's similar to FileMaker or some other visual database creation tool.
Anyway, the big question is, what would be the best way to design this program, out of the two options below?
Option 1
when the user creates a new 'collection' (it'll be all pretty and wizard-based), the program creates a new table in the SQL database, and adds records into the following tables:
Collection, which holds the name of the collection, along with its description, datestamp, and a reference to a few special fields: the name of the 'catalogue number' field, the name of the 'title' field (all collections are required to have at least those two fields, although their names and data types can be anything), and the name of the 'image' field, for those collections that involve image thumbnails.
Field, which has one record for each of the fields created in the new database. Each record has the collection ID, the field name, its location on the form, and its data type (the data types I've created are text, longText, number, image, enum, set, link, boolean, and date). This way I can pull the collection's table structure directly from this field, instead of guessing at it by dumping the table structure. You can see I have some specialised data types that don't exist in MySQL as well, like 'image'.
This is the way the program is written now, and it seems to work okay.
Option 2
Have the following tables:
Collection, with name, id, etc, as above
Field, again with the same as above
Record, just has its own id and collection ID
DataItem, which holds the actual data. It'd have the record ID, the field ID, and the actual data for the field.
I hope all this makes sense!
The first option strikes me as being the fastest and most efficient, and has the added option of making the tables readable by humans. The second option has a mess of relations and foreign keys, but seems the most database-design-pure option.
anyway, if anyone can understand this, and has some comments, I'd love to hear them.
Thanks!
Paul d'Aoust