سؤال

In a customer database I don't want to use primary key id shown to user. I just want to use the unique key in user end.

Should I make primary key, unique key, and foreign key all refer to unique key in another table?

Is this good practice?

هل كانت مفيدة؟

المحلول

I'd suggest having a unique userID that your customers can see ex: AliceJones45 and a separate unique customerID that you can use as a primary key. You can even automatically generate your customerIDs as new people register for your service.

It's good practice to keep them separate

The foreign key is a reference to the primary key in another table. Say you have a customer table and an orders table. The primary key of the customers table might be customerID and the primary key of the orders table might be OrderNumber. Each order is linked to a customer and so each order might reference an existing customerID.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top