I am trying to creating a system where all new tables will be dynamically created (or objects inside a predefined databases.)
Here is an over view of the design, I would have a predefined table for
- Objects (ie. object 1, 2, 3 ....n)
- Fields (related to Object) field "ABC" is related to object (field 1 is linked to object 2....)
- Data (ie. value for each field) so row 10 in this table is the value for field 1)
For example In the "objects" table I have a rows to look like this:
object_id object_name
1 accounts
2 users
...
...
...
In the fields table I will have the following rows:
field_id field_label object_id
1 Account Name 1
2 Specialty 1
3 DBA 1
4 First Name 2
5 Last Name 2
...
...
...
Finally, the data will be captured in the Data table and it will look something like this:
data_id value field_id object_id
1 Mike 4 2
2 Signs/Graphics 2 1
...
...
...
This design will allow me to dynamically create a new object, create fields inside this object, and finally capture data for each field. Everything will be done without having to create/alter tables at all.
Problem
The problem that I am having is, how would I generate a unique identified for each object? ( I need to be able to identified one row inside a dynamic object)
For instance, if I want to create 100k accounts "unique accounts" inside the accounts object. How can I automatically assign a unique ID for each row?
I should be able to create a new field and call it "account ID" in the field object and relate it to object_id 1. Then automatically populate an auto increment value inside that field. Since the field "account ID" is the primary identifier it should unique for each object.
I believe that I complete understand the design, but not sure how to auto generate unique identifier. The unique identifier will later be used to capture the data before storing it in the data object. The data object will then be something like this
data_id value field_id object_id object_unique_id
1 Mike 4 2 1
2 Signs/Graphics 2 1 1
3 Jack 4 2 2
3 Jay 4 2 3
...
...
...
row 1 of the data object will point to the field_id, object_id, and object_unique_id which represent the exact account that I the "First Name" field reference to.
I am using MySQL as DBMS and PHP as Scripting Language to accomplish this.
Any help will be greatly appreciated