开发者

Physical access logging - SQL database design

A daemon returns every minute a list of users that are currently checked into a facility. To enter or leaver one has to use a smart card.

The final solution should allow to see which user had been checked in for how long and when.

My question is: Is it better to a) log the raw output of the daemon into one table of a sql database, and do all the logic if needed based on the raw data, or b) Programm some logic into the daemon, so that sql entries are only generated when something changes?

In the second case (which I am tendi开发者_如何学Cng toward at the moment) how should I build the sql tables?

a) One table for every unique user (it should be possible to add user in case they appear) that lists Check in Time || Check out Time || Duration

b) Only one table User || Check in Time || Check out Time || Duration

c) A user table and linked time logging table User || Boolean(checkedin)

User ID || Check in Time || Check out Time || Duration

Does anyone have experience how to design such a scenario to avoid future caveats


Based on the information available, option b) gets my vote.

If your RDBMS allows, consider making Duration a computed column. For Microsoft SQL Server, that would look like:

create table SecurityLogging (
    UserId int,
    CheckInTime datetime,
    CheckOutTime datetime,
    Duration as datediff(minute, CheckInTime, CheckOutTime)
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜