Errors in database model? [closed]

0

Good morning, I am currently creating a system for a library, I have made the model, but I would like some suggestion or know that I can improve it, because I do not feel satisfied and I am not very expert in the subject.

Thank you in advance, any suggestion is welcome.

    
asked by ebx 19.02.2018 в 05:56
source

1 answer

0

There are some considerations to bear in mind, let's say that they are " good practices ", and reduce some type of problem in the future, such as performance, simplify syntax, make the names meaningful and be intuitive:

  • All tables must be InnoDB and at least with the properties CHARSET = UTF-8 and COLLATE = utf8_unicode_ci.
  • All tables must have a column called "id" which is a Primary Key with the following characteristics: BITINT, UNSIGNED, NOT NULL and AUTO_INCREMENT.
  • All columns that are FOREIGN KEY must have the following characteristics: BITINT, UNSIGNED, and CONSTRAINT.
  • Prevent the CONSTRAINT from cascading, for example: When deleting a parent record, do not automatically delete your children.
  • Have a constant nomenclature for naming columns of type FOREIGN KEY, for example: user_id, profile_id or address_id.
  • Avoid, if possible, using FOREIGN KEY with the possibility of allowing NULL.
  • Do not create an exclusive index of a column that has the CONSTRAINT of the FOREIGN KEY, and the CONSTRAINT defines the index.
  • If possible, add a CONSTRAINT of type UNIQUE to avoid duplicate records, for example: the UNIQUE for an email.
  • Be aware of the differences between data types such as; CHAR, VARCHAR, ENUM, TEXT among its variants. Each one has its advantages and disadvantages, each one influences the optimization of memory, response time and / or search or penalizes disk.
  • Do not use reserved words as column names.
  • To have audit columns, these also imply for the logical elimination of the data, for example: created_at, updated_at, deleted_at, created_by, deleted_by. Those that end in _at are of type TIMESTAMP and those that end in _by can be BIGINT that refers to a user of the system.
  • Names in English, plural tables, and singular fields.
  • The name for an intermediate table that relates two tables is separated with a sub-script, for example: users and products can be called users_products.
  • It is important to note that there are always exceptions depending on the business rules, but it must be documented to avoid misunderstandings.

        
    answered by 19.02.2018 / 16:09
    source