Вопрос

Iam creating an application which is being used to send reminders. Here is the requirements.

  1. We have set of Students.
  2. Every student has a Student Pass, this need to be renewed in every month. Student Pass has Pass ID, monetary value, date of expiry, etc.
  3. Before 7 days of Student Pass expiry, we have to send notifications to the system admin.
  4. We have to monitor the Student Pass History of every student as well. Which means how many notifications were given to the admin, what is the date the pass got expired and so on.

Now we need to create tables for this. We thought of creating a table called StudentPass and maintaining the student pass history and current student pass in the same table. It is like below

enter image description here

However maintaining the current student pass data and student pass history seems to be mixed up work because we have to send notification for the expiration of current student pass. So we decided to divide this into 2 tables. It is like below, the current student pass data will be maintained in StudentPass table and the history data will be maintained in StudentPassHistory.

enter image description here

With your experience in database, please let me know which method is better. In case you need more information about why we divided the data into 2 tables, that is because our notification system can simply identify that it should send notification only for the items in StudentPass table, We do not have to do DB comparison to find out which data is the latest and current, we have history and current data separated and it will be easy to generate reports. Your advice is highly appreciated.

Это было полезно?

Решение

One thing missing from the sample tables above is BeginDate and EndDate (or whatever you want to call them). Since you are tracking history, the dates are obviously valuable and can be used when querying older entries.

Having a StudentPass and a StudentPassHistory table does split out the information, but that is a mixed blessing, since the student's full StudentPass information is split across two different tables.

You might consider implementing StudentPass like this:

CREATE TABLE dbo.StudentPass
(idStudentPass INT,
 Student_idStudent INT,
 BeginDate Date,
 EndDate Date
 PassActive INT);

This way, the BeginDate and EndDate clearly identify not only whether the StudentPass is active, but could also preview for you the approaching EndDate. Likewise, a future BeginDate could also support setting up a StudentPass that will not be activated for a few more weeks.

The PassActive is not strictly needed, but can be a useful shortcut for querying active StudentPass data without using dates. You just need a process to update the PassActive column setting as defined to be in the inclusive range of the BeginDate and EndDate.

Using a design like this keeps all the information in one table, which I assume will not overwhelm your query processing, so that you can simply filter the data according to your needs.

Of course, if you feel that the StudentPassHistory would server you better for some other needs, then make the choice to also create that table.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с dba.stackexchange
scroll top