SQL Optimization: how many columns on a table?

后端 未结 13 1074
离开以前
离开以前 2021-01-01 13:43

The current project that I\'m working on have table with 126 columns and the least that i saw is at least 50 columns. Should a table hold less columns per table or separate

13条回答
  •  长情又很酷
    2021-01-01 14:18

    If you had an object detailing the data in the database, would you have a single object with 120 fields, or would you be looking through the data to extract data that is logically distinguishable? You can inline Address data with Customer data, but it makes sense to remove it and put it into an Addresses table, even if it keeps a 1:1 mapping with the Person.

    Down the line you might need to have a record of their previous address, and by splitting it out you've removed one major problem refactoring your system.

    Are any of the fields duplicated over multiple rows? I.e., are the customer's details replicated, one per invoice? In which case there should be one customer entry in the Customers table, and n entries in the Invoices table.

    One place where you need to not fix broken normalisation is where you have a facts table (for auditing, etc) where the purpose is to aggregate data to run analyses on. These tables are usually populated from the properly normalised tables however (overnight for example).

提交回复
热议问题