I am a newbie to databases. I am using MySQL, and I have a table A using three attributes to form a composite primary key:
A:
[key1, key2, key3], dateCreated, createdBy, …
Now I have another table B, which needs to refer to records from the table above. Now, reusing all the three attributes above again to form a key seems to be a pain. Is it okay to use an additional auto incrementing dummy “id” attribute to table A as a primary key, and use that as a reference in table B? Which is the right thing to do?
It certainly is. It’s called a surrogate key: a surrogate key is not derived from application data.
[There is a debate surrounding the use of surrogate keys. The wiki article linked to lists advantages/disadvantages.]
As @Scharrels points out, a unique constraint should be applied to your 3 fields, if you use a surrogate key.