What is the best way to store Civil Status data in the database?

Asked

Viewed 96 times

0

Hello, I have a question:

I need to create a <select></select> in HTML for the user to select their marital status. So, I’m using PHP to save the data to an SQL database.

My question is whether I should directly enter the <option></option> in HTML (example: <option>Solteiro(a)</option> and etc).

Or, if I should create a table in the database called estado_civil, and insert data as id = 1, descricao = "Solteiro(a)", capturing this information and creating the <option></option> dynamically through a loop with PHP.

What would be the best way to work in this current state of programming in computational requirements, looking at systems analysis and engineering?

Thank you in advance to all!

  • 2

    What is the chance that you will have to change the list of possible civilian states in your application? At some point you will need to register new or remove existing ones?

  • @Woss 1. The chance of having new civilian states is 0. 2. I will not need to register or remove civilian states at any time. So with these analyses I can get an idea and know whether or not to keep the table in the database?

  • 4

    What enormous confidence that legislation or other factors will never change.

  • 1

    Beware of the Nunca and the Sempre. Better to prepare for all that CAN happen than for all that MUST happen

  • 1

    Suggestion: register the text. This way you do not need to have a table only to know which are the descriptive based on the codes and do not keep doing "de-para". In this specific case it is simple, but in other cases I would suggest associating codes and, if applicable, calling in another table "-to" in order to get the description of the items.

  • 3

    @Maniero de facto, so much so that in Brazil this has already changed, the state "disconnected" no longer exists. It was Article 315 of the Civil Code of 1916, but in the current legislation there is only possibility of divorce. About the post, I think it will only attract material based on opinion, because it depends on factors that are peculiar to each case (and the generic cases seems to me that there is already a post on the site). As the author commented, in this case it may not change in any way, but this is not applicable in other situations. Still, on "systems analysis and engineering", it depends on the head of who is teaching the course.

  • Thank you very much for the personal help, it really is at the discretion of those who are developing and analyzing the system, I believe that in simpler systems it is easier to use only the stored text. Already in more complex systems, as the Government, I believe that it is already necessary a major polishing in this part. I believe that in simpler systems the form of storage through text facilitates even to let the database more streamlined.

  • Create the civil states in Json and done, don’t use database/processing resources and don’t need to modify your VIEW every time you change it, so learn how to use Json in your applications and improve the way of thinking.

Show 3 more comments

1 answer

2


My question is whether I should directly insert the HTML (example: Single(a) and etc).

Or, if I should create a table in the database called state_civil, and insert data as id = 1, description = "Single(a)", capturing this information and creating the dynamically through of a loop with PHP.

The most correct answer seems to be: It depends, but I argue that the best is the second option, ie, create a table in the database.

Motives:

1. Flexibility of the Software: If you need to include a new item, you will not need to change anything in the code, just include the new record in the database, including a record maintenance form where a user with permission to access this record, may include, modify or delete records as necessary.

2. Saves space in the database: Instead of storing a field with 20 characters, you will store only the id record. Considering a table with few records may not make a difference, but in a table with trillions of records, it would make a difference.

3. Prevention of Errors in Information: In case the text is used, without the table, if they had to leave all the text in the upper case and at the moment of changing the page code, the programmer changed to SOLTERO(A) and it would be a long time before they realized the spelling error to make the correction, but they may think, "just fix the web page", but the error was reflected to numerous records, to fix it would be necessary to make a UPDATE to update all wrong records. You would also need to consider that some databases are Casesensitive, that is to say, Solteiro(a) is different from SOLTEIRO(A) in a consultation. This same scenario working with table would not present so many problems, because usually a number is used as primary key and in reports is offered a checkbox that will consider the id as a parameter and not the text shown in the description.

4. The database should be standardised: Avoids repetitions and redundancies. There will be the inconvenience of having to join the queries, but it is recommended when talking about relational databases. Some people talk about denormalizing the bank for performance purposes, but the rule is normalization and denormalization is the exception. It is worth noting that you can use view to simplify the viewing and consultation of information.

Browser other questions tagged

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