Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

based on database design is it possible to predict the queries to be used in the application?

lets say i have this mysql db, and all the tables in the db are related to one another, primary keys, foreign keys, etc all are set. Now is it possible to predict, just from the database design, what the queries will be used for the application? Since the database does dictate the application capabilities, then therefore from the design, we can predict what queries that will be used in the application, right?

If it is possible, is there a strategy or automated way to generate the possible queries?

like image 786
user1549397 Avatar asked Nov 17 '25 20:11

user1549397


2 Answers

I have written a book on the subject of analyzing data using SQL and Excel, and have spent many years working with databases.

Yes, from a database structure, you can figure out how tables are going to be joined together. You are not going to figure out the harder -- and generally more business relevant -- things that users need. Here are some examples:

You can have a database where the primary table is telephone calls, with the associated information. From this database, you may need to know the maximum number of active calls at one time. Or you may need to know how many different people someone calls in a month.

You can have a database of subscriber records. You may need to figure out the probability that someone will stop after a given amount of time.

You can have a database of products and purchases. You may need to figure out the most common combinations of three products that occur together.

You can have a database of credit card purchases. You may need to figure out who spends more than $200 in a restaurant more than 50 miles from their billing address.

The point is. A database does not represent "application capabilities". A database represents entities and relationships between them, presumably in the real world. There is hubris to think that you can look at a database and know what the business questions are.

Instead, the purpose of a database is to support data, which in turn, supports applications. The needs of applications will change over time. The beauty of databases, as opposed to many other data storage technologies, is that the technology scales as the data increases, supports changes to the structure, and allows new entities and relationships to be added into the system, without completely rewriting it.

Over time, and with experience, you might develop intuition on what's important. Even if you do, you will be constantly surprised at the varied needs of your users.

like image 86
Gordon Linoff Avatar answered Nov 20 '25 10:11

Gordon Linoff


I am sincerely not trying to be smart here but answer is - yes and no.

Yes, because 3NF design usually outlines business rules behind it pretty well, so you can to a degree tell what is the business logic behind it, you can create an object or graph model from it and get a good idea what kinds of questions can be asked from based on connections/relations and accessible properties.

No, because combinatorially you might have a untractable number of combinations of questions from a graph. Hence, you can't really tell what question one might ask in reasonable, non-exponential amount of time.

In general, if design is good and tables are meaningfully named you can get a pretty good idea what is going on.

like image 38
Edmon Avatar answered Nov 20 '25 11:11

Edmon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!