Why use an auto-incrementing primary key when other unique fields exist?

前端 未结 12 2386
悲&欢浪女
悲&欢浪女 2021-01-30 10:36

I\'m taking a course called \"database systems\" and for our class project I have to design a website.

Here\'s an example of a table I created:

CREATE TA         


        
12条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 11:08

    I'll need someone with more database knowledge to back me up on this one, but i believe you get a faster response in foreign key lookup time.

    Additionally, you may decide later that you want usernames to change, or that the requirements for usernames may change (maybe a longer string?). Using an ID prevents having to change all foreign keys.

    Lets face it, most projects aren't going to expand that much, but do you really want to risk the headache 12 months down the road, when you could conform to good programming standards now?

提交回复
热议问题