I have a question about Database design.
I have two tables, usertable and historytable, which are one-to-many relationship, which usertable contains
- username primary key
- passwordname
and historytable has
- username foreign key
- date
- visted url
I am not sure if there are any negative effects in terms of performance if historytable has no primary key defined , if there are , what would be the best option in the historytable to be the primary key?
Thanks.
You would need to define a new column: UserHistoryId
Make it identity column
The reason for this is no combination of the other columns could be unique in all cases.
e.g. If a history record is created twice in one day for a user from the same url.
Performance:
Depends on how the history table is used – If you only ever SELECT data from it by means of a query on userId, or date, or Url, then the ID column would serve no purpose.
However, if you ever perform any Update/Delete operations on the table then, the Id would be useful.
Regardless of current requirements, it costs you almost nothing to include the extra column now, and it’s something I would always recommend.