Relationship in database table

Asked

Viewed 126 times

0

I have a registration form where contains personal information, professionals, additional, financial and production, my doubt, as it gives many columns, I believe that more than 50 fields.

Is it advisable to leave everything in a table? Or separate them and relate 1:1?

  • 2

    The information is unclear as to what you mean by professionals, additional, production, financial... Domain knowledge is very important during modeling.

  • there are several areas in the registration form, areas such as: Personal, professional, financial, additional and production information, where joining all fields will give more than 50 columns

  • I would say that you should separate the fields into tables as they make sense and, mainly, if there is potential for reuse. For example, what is "professional" information? Is it the kind of job a customer has? Because if it is, different clients can have the same job, so it makes perfect sense to separate the tables. Provide more details and if possible focus on some of the fields you have more doubt about.

1 answer

1


Is there a reason to separate? That’s the question. You almost always don’t. Usually there is a small loss of performance (in some cases there may be improvement, but would have to analyze the problem, it is not common) since it would have to read more of a different log, have to do separate searches and would have an extra complication in the queries. Why do it then? What’s in it for me?

You may even want to set up a logical model where it’s separate, but the physical model (which is what counts most for the database, and many developers think it exists only) doesn’t usually benefit from this.

Anything you decide to do has to ask yourself why you do it. If you do it for free, you shouldn’t do it. If you can’t explain a reason or if you read it somewhere telling it to do and you didn’t see a plausible explanation of why you did it, you shouldn’t. Unfortunately we sometimes find recommendations, usually called "good practices", even with plausible explanations, but either they are wrong or they do not apply to the context that the inexperienced programmer is facing.

If the database manager allows hundreds of columns, you can use them. To tell the truth it is very common that the tables usually have more 10 columns, so it seems to me that this is not much, on the contrary. Even if it was, it would still have to technically justify the decision to separate, which is usually difficult because it is almost always "wrong".

If you still have doubt and have a more concrete example you can ask a new question to analyze. But it is very likely that the answer is still to keep a single table.

  • The registration form has more than 100 fields, the question of divide,I believe, It is more to facilitate maintenance

  • In question put 10, but still does not change the answer. If you want to split try to show why it would facilitate maintenance. Having to move two places makes it hard for me.

  • uhm, I understand, but n would be better even to keep the query at the time of the update ?

  • As I said in the answer, it depends, but in my opinion it is exactly the opposite. If you think better, you can try to demonstrate this. Query that involves more than one table is always more complex to write, even if not much, and much more complex of database processing.

  • I understand, thank you !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.