Using ID in Databases

When creating a new table in the database, it is important to use an identifier. For our purposes, we use a unique username and email address in each field to match information with this unique username or email. So what is the use of id?

Also, for what field is the length / value? New to this.

thank you a bunch!

+3
source share
5 answers

As others have pointed out, there are two types of keys for records: natural keys and surrogate (artificial) keys. Thus, there are two main questions: is it necessary to use a surrogate key, and if so, what should be this surrogate key?

: , . ON ONDATE CASCADE ', , , , , . , , , , ( ). , , , , , , , , ( ), , .

: , , , . .. : ( ), ( ), , , , , . , ( , , ), . , , UUID ( 128- , ). . (, , 32- . , - , , re !)

+4

id . , , , .

, , , . , . , , , , .

, , , , , CASCADE.

+8

.

username email, string, , , - ID userid.

+3

, , , . , , .

- . , varchar 10 10 . . , , .

0

, . , ( , ) , , firt, . , , , .

And using an identification field will allow you to do things like Comments (id, user_id), and not Comments (id, username, email)...

0
source

Source: https://habr.com/ru/post/1780792/


All Articles