Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
Have you tried to identify all of the entities and their relationships here? –  FrustratedWithFormsDesigner Nov 24 '11 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 Nov 24 '11 at 5:11
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
    
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 Nov 24 '11 at 11:35
add comment

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 : ...
    }
  ...
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.