What you describe is often called "Entity-Attribute-Value" and is sometimes described as "mixing data and metadata." That is, the names of the attributes (fields) are stored as strings (data).
This leads to many complex problems, such as checking that each instance of the form contains the same set of fields or filling out the required fields (NOT NOT NULL equivalent in a regular table).
You asked how best to do this with a relational database. In a relational database, you must use metadata for metadata. In this case, this means creating a new table (s) for each form and using columns for the form fields. So your form definition is just the metadata of the table, and one instance of the form is one row in that table. If you support forms with multiple answers (e.g. checkboxes), you also need dependent tables.
This may seem expensive or difficult to scale. Probably true. Thus, a relational database may not be the best tool for this work. You mentioned the possibility of XML or YAML; basically some sort of structured file format that you can define ad hoc. You must define a DTD for each client form so that each assembled form can be validated.
edit: If you really need EAV flexibility in your application, this is normal, usually there are circumstances that justify breaking the rules. Just keep in mind the extra work that it does, and plan it in your development schedule and scale the server to handle the load. Also see Another answer to my question about EAV in StackOverflow.
Bill karwin
source share