Sql-server – One table to save all records vs create one table each day

optimizationperformancequery-performancesql server

One vendor need to store in a database multiple records. There are 5 tables (a table per element – elements are: pressure, flow, volume, temperature and distance). Each table have the following columns: ID, Timestamp, Value;
Each day, a table will have approximately 50.000 records.

Database used is SQL Server 2017, on a Windows Server 2016 machine.
There will be a lot of analytics to make (charts, reports, etc.) (daily, weekly, monthly, yearly)

So, the vendor wants to create these 5 tables every day for each day of one year (example: "Table_yyyyMMdd_Pressure") and store into it values from that day only; this approach will get the database to have something like 1825 tables per year.

Our request was to create only 5 tables and store all records there – which will get to have approximately 18 000 000 records in one year per table.

From my point of view, our approach is better taking into account:

  1. queries will be run only on those 5 tables once (per table) instead of running queries multiple times per each table per each day;
  2. easier to create reports on a single table than on multiple tables
  3. easier to change the structure of the tables if will be necessary
  4. less complex to write code/procedure

Can you please give me more pro's and con's regarding these 2 approaches?

Thank you!

Best Answer

Avoiding separate tables by date would be best. Besides the benefits you mentioned, performance will likely be better too.

If each table has a row for the same ID and Timestamp (e.g. a device that reports all 5 readings at the same time), you could have a single table with ID, Timestamp, pressure, flow, volume, temperature, and distance.

You might also consider using columnstore and partitioning by date for maximum performance and manageability (respectively).