I am creating an ERD and one of my subclasses has a different PK than its superclass is it ok to do so?
I have a superclass Accounts which which has Username as its PK and then BannedAccounts which has (Foreign Key) AccountsUsername and BanDate as its PK.
The reason I did so is because the same account can be banned multiple times.
Is it correct?
Here is an image of the diagram: https://prnt.sc/vfb56o
Yes, that is fine, and it is common to do this. The table
BannedAccountscould be called a fact table since it forms a time series of data points for an account. On the other hand, theAccountstable is a dimension table because it is used to categorize fact data.Another way to talk about it is to categorize entities as weak or strong.
Accountwould probably be a strong entity because it does not depend on other entities to exist. In contrast,BannedAccountsis a weak entity because it's existence is dependent onAccounts; it doesn't make sense to talk about which accounts are banned if there is no definition of an account.To define the relationship,
BannedAccountsis a child andAccountsis a parent becauseBannedAccountsreferences the primary key ofAccounts. The relationship can be further classified as a strong (or identifying) relationship because the primary key ofBannedAccountscontains the entire primary key ofAccounts. If the key forAccountswas composite (consisting of more than 1 column), andBannedAccountsdid not include all of those columns in it's primary key, then the relationship would be called weak or non-identifying.