Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 840693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:40:03+00:00 2026-05-15T05:40:03+00:00

Here’s a tricky one – how do I programatically create and interrogate a database

  • 0

Here’s a tricky one – how do I programatically create and interrogate a database whose contents I can’t really foresee?

I am implementing a generic input form system. The user can create PHP forms with a WYSIWYG layout and use them for any purpose he wishes. He can also query the input.

So, we have three stages:

  1. a form is designed and generated. This is a one-off procedure, although the form can be edited later. This designs the database.
  2. someone or several people make use of the form – say for daily sales reports, stock keeping, payroll, etc. Their input to the forms is written to the database.
  3. others, maybe management, can query the database and generate reports.

Since these forms are generic, I can’t predict the database structure – other than to say that it will reflect HTML form fields and consist of a the data input from collection of edit boxes, memos, radio buttons and the like.

Questions and remarks:

A) how can I best structure the database, in terms of tables and columns? What about primary keys? My first thought was to use the control name to identify each column, then I realized that the user can edit the form and rename, so that maybe “name” becomes “employee” or “wages” becomes “:salary”. I am leaning towards a unique number for each.

B) how best to key the rows? I was thinking of a timestamp to allow me to query and a column for the row Id from A)

C) I have to handle column rename/insert/delete. Foe deletion, I am unsure whether to delete the data from the database. Even if the user is not inputting it from the form any more he may wish to query what was previously entered. Or there may be some legal requirements to retain the data. Any gotchas in column rename/insert/delete?

D) For the querying, I can have my PHP interrogate the database to get column names and generate a form with a list where each entry has a database column name, a checkbox to say if it should be used in the query and, based on column type, some selection criteria. That ought to be enough to build searches like “position = ‘senior salesman’ and salary > 50k”.

E) I probably have to generate some fancy charts – graphs, histograms, pie charts, etc for query results of numerical data over time. I need to find some good FOSS PHP for this.

F) What else have I forgotten?

This all seems very tricky to me, but I am database n00b – maybe it is simple to you gurus?


Edit: please don’t tell me not to do it. I don’t have any choice 🙁

Edit: in real life I don’t expect column rename/insert/delete to be frequent. However it is possible that after running for a few months a change to the database might be required. I am sure this happens regularly. I fear that I have worded this question badly and that people think that changes will be made willy-nilly every 10 minutes or so.

Realistically, my users will define a database when they lay out the form. They might get it right first time and never change it – especially if they are converting from paper forms. Even if they do decide to change, this might only happen once or twice ever, after months or years – and that can happen in any database.

I don’t think that I have a special case here, nor that we should be concentrating on change. Perhaps better to concentrate on linkage – what’s a good primary key scheme? Say, perhaps, for one text input, one numerical and a memo?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:40:03+00:00Added an answer on May 15, 2026 at 5:40 am

    “This all seems very tricky to me, but
    I am database n00b – maybe it is
    simple to you gurus?”

    Nope, it really is tricky. Fundamentally what you’re describing is not a database application, it is a database application builder. In fact, it sounds as if you want to code something like Google App Engine or a web version of MS Access. Writing such a tool will take a lot of time and expertise.

    Google has implemented flexible schemas by using its BigTable platform. It allows you to flex the schema pretty much at will. The catch is, this flexibility makes it very hard to write queries like “position = ‘senior salesman’ and salary > 50k”.

    So I don’t think the NoSQL approach is what you need. You want to build an application which generates and maintains RDBMS schemas. This means you need to design a metadata repository from which you can generate dynamic SQL to build and change the users’ schemas and also generate the front end.

    Things your metadata schema needs to store

    For schema generation:

    • foreign key relationships (an EMPLOYEE works in a DEPARTMENT)
    • unique business keys (there can be only one DEPARTMENT called “Sales”)
    • reference data (permitted values of EMPLOYEE.POSITION)
    • column data type, size, etc
    • whether column is optional (i.e NULL or NOT NULL)
    • complex business rules (employee bonuses cannot exceed 15% of their salary)
    • default value for columns

    For front-end generation

    • display names or labels (“Wages”, “Salary”)
    • widget (drop down list, pop-up calendar)
    • hidden fields
    • derived fields
    • help text, tips
    • client-side validation (associated JavaScript, etc)

    That last points to the potential complexity in your proposal: a regular form designer like Joe Soap is not going to be able to formulate the JS to (say) validate that an input value is between X and Y, so you’re going to have to derive it using templated rules.

    These are by no means exhaustive lists, it’s just off the top of my head.

    For primary keys I suggest you use a column of GUID datatype. Timestamps aren’t guaranteed to be unique, although if you run your database on an OS which goes to six places (i.e. not Windows) it’s unlikely you’ll get clashes.

    last word

    ‘My first thought was to use the
    control name to identify each column,
    then I realized that the user can edit
    the form and rename, so that maybe
    “name” becomes “employee” or “wages”
    becomes “:salary”. I am leaning
    towards a unique number for each.’

    I have built database schema generators before. They are hard going. One thing which can be tough is debugging the dynamic SQL. So make it easier on yourself: use real names for tables and columns. Just because the app user now wants to see a form titled HEADCOUNT it doesn’t mean you have to rename the EMPLOYEES table. Hence the need to separate the displayed label from the schema object name. Otherwise you’ll find yourself trying to figure out why this generated SQL statement failed:

    update table_11123
    set col_55542 = 'HERRING'
    where col_55569 = 'Bootle'
    /
    

    That way madness lies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is my code sample, let me know if it can be further improved?
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here is my issue from the beginning...I really need someones help.... I needed to
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.