简体   繁体   English

SQL-有关存储数据列表的数据库设计问题

[英]SQL - Database design issue on storing list of data

I have a list of records to be stored in database table, but I'm facing some difficulty in designing the database. 我有一个要存储在数据库表中的记录列表,但是在设计数据库时遇到了一些困难。 The following would be the data to be stored: 以下是要存储的数据:

在此处输入图片说明

The Class (Rows) and The Day (Column) will be continue to grow in future. 将来,类(行)和日期(列)将继续增长。 My initial idea have 2 designs. 我的最初想法有2种设计。

  1. The table design for the database design will be exactly same with the current table. 数据库设计的表设计将与当前表完全相同。 But the problem would be how if want to add Day13? 但是问题是如果要添加Day13怎么办? It would be suffer in future in the column keep continue to grow. 将来在列中继续增长会受到影响。

  2. Add 1 column as result: 结果添加1列:

在此处输入图片说明

It look better to solve the problem of Day column to be growing in future, but the problem is it will keep large amount of data records in database which make query become slower when more and more data insert. 解决“日”列在将来增长的问题看起来更好,但是问题是它将在数据库中保留大量数据记录,这会在越来越多的数据插入时使查询变慢。

Any idea or technique on how to optimize the database design? 关于如何优化数据库设计的任何想法或技术? Thank you. 谢谢。

Maybe something simple like this. 也许像这样简单的事情。

One table for Classes (ClassID, ClassName) 一个表的类(ClassID,ClassName)

One table for Day/Period/whatever you call it (DayID, DayName, DayInMonth etc..) Day / Period /无论您叫什么的一个表(DayID,DayName,DayInMonth等。)

One table for Results(ResultId,DayId,ClassId, Result) 一个结果表(ResultId,DayId,ClassId,Result)

So a Class can have a result and a date. 因此,一个班级可以有一个结果和一个日期。 Just make sure to have a unique primary key on your Class table and make the correct data types for your fields. 只需确保在类表上具有唯一的主键,并为您的字段输入正确的数据类型即可。 What I think you need is a ClassId for primary key and then make a ClassName field (varchar) to store the class name. 我认为您需要的是主键的ClassId,然后创建一个ClassName字段(varchar)来存储类名。 Don't write Day1 it should be a date format. 不要写Day1,它应该是日期格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM