I'm on the way developing an application which requires a kind of dynamic database,
So this is what I want,
enter image description here
This is the for reading the details of a class, the number of variables and methods will only be known at run-time, and I have to create a number of classes like this.
In the above scenario,how can I design a database (MySql) to store all these datas and retrieve them later?
-
1Have you tried to identify all of the entities and their relationships here?FrustratedWithFormsDesigner– FrustratedWithFormsDesigner2011年11月24日 05:07:11 +00:00Commented Nov 24, 2011 at 5:07
-
@FrustratedWithFormsDesigner the relationship between the classes?? I do it separately, and for that I need the datas, and thats the reason I need to store all these in a db.COD3BOY– COD3BOY2011年11月24日 05:11:15 +00:00Commented Nov 24, 2011 at 5:11
2 Answers 2
It would be very lengthy to give you a fully normalized db here. Hopefully this would get you started.
tblClasses
pk Name
AnyOtherDataYouwanttostore
tblAttributes
fk ClassName <-> tblClasses.Name
Name
Visibility
Type ...
tblFunctions
fk ClassName <-> tblClasses.Name
Name
Visibility
ReturnType ...
Depending on your design, it may be better to use an Identity column for your primary key for tblClasses and then use that for your Foreign Key in the other tables. It all depends on your datatypes and the rest of the data you need to store.
-
This works nicely, But use an ID field, not name, as the PK in the class table (and of course the FK in the other tables).Morons– Morons2011年11月24日 11:35:34 +00:00Commented Nov 24, 2011 at 11:35
You may want to look into MongoDB. Its significantly different than MySQL as it is in the NoSQL group but seems like it might be a good fit for what you need. You can store the dynamic aspects in one table in an array which is something you can't do in a MySQL setup. If however you need/want to stick with the MySQL database then the appropriate method is to split the data between tables as suggested by Jonathan Henson.
FYI the MongoDB Structure would be something like the following:
Classes:
{
Name : NameValue,
Attributes : {
0 : {
AttName : AttNameValue0,
AttVisibility : AttVisibilityValue0,
AttType : AttTypeValue0
},
1 : {
AttName : AttNameValue1,
AttVisibility : AttVisibilityValue1,
AttType : AttTypeValue1
},
2 : ...
},
Functions: {
0 : {
FuncName : FuncNameValue0,
FuncVisibility : FuncVisibilityValue0,
FuncReturnType : FuncReturnTypeValue0
},
1 : {
FuncName : FuncNameValue1,
FuncVisibility : FuncVisibilityValue1,
FuncReturnType : FuncReturnTypeValue1
},
2 : ...
}
...
}
Explore related questions
See similar questions with these tags.