Linking of SQL tables by means of string instead of id

1

User accounts data

id  nome    sobrenome   pais    estado  cidade  telefone    url_perfil

User login data

id  email   senha   prioridade

My questions are:

  • How can I bind them to foreign key using string ?
  • Is it best to do this with ID ? Because? (Can there be problems when a user registers his data in a table, and his account has 2 id 's different being one per each table, making it difficult to use the foreign key?)
  • For the use of the foreign key, does%% of the bank have to be ENGINE ?
  • What would be the INNODB for these tables?

PS: I searched for Join and other places if there was a "question" that answered my doubts, or at least gave me a light but I did not find it, and because of that I'm opening this

    
asked by anonymous 24.02.2017 / 13:50

1 answer

4
  

For the use of the foreign key, does the bank's ENGINE need to be INNODB?

When using this engine, the database automatically guarantees referential integrity, it can be guaranteed via the application, but you can plan the rules and take all the necessary care.

  

How can I link them to the foreign key using string?

Yes you can. It works the same way just inform the names of the columns in the foreign key.

  

How would Join for these tables?

It's the same thing.

  

Is it more recommended to do this with ID? Because? (Can there be problems when a user registers his data in a table, and his account has 2 different ids being one for each table, making it difficult to use the foreign key?)

In terms of performace numerical comparisons are faster than comparisons with strings (varchar). The length of the string field influences the index or the worse the performace.

When working with keys not numerical, the rigor of validation of values should be greater if for example remove spaces, take care not to have problems with encodings.

An example of a primary key as a string can be seen between the city (FK) and state (acronym + PK) tables

    
24.02.2017 / 14:15