Is it better to have a single primary key, or use composite primary keys (usually, they are combination of one primary key and foriegn keys). I have examples below:
Composite Primary Key example:
AMeta
— AMetaId – Primary Key
— AMetaText
BMeta
— BMetaId – Primary Key
— AMetaID – Foreign Key to Table AMeta
— BMetaText
A
— AId – Primary Key
— AMetaId – Primary Key and Foreign Key to Table AMeta
— AText
B
— BId – Primary Key
— BMetaId – Primary Key Foreign Key to Table BMeta
— AId – Primary Key and Foreign Key to Table A
— BText
Single Primary Key example:
AMeta
— AMetaId – Primary Key
— AMetaText
BMeta
— BMetaId – Primary Key
— AMetaId – Foreign Key to Table AMeta
— BMetaText
A
— AId – Primary Key
— AMetaId – Foreign Key to Table AMeta
— AText
B
— BId – Primary Key
— BMetaId – Foreign Key to Table BMeta
— AId – Foreign Key to Table A
— BText
Which is the better Database Design?
I genereally tend to use single-column primary keys almost exclusively – either there is a good natural key available (pretty rarely), or then I add a surrogate INT IDENTITY key to the table.
My main reasons are: