Good day, I have a question, I am working with 2 databases at the same time, to make a table, it works well, I did some joins and it brings me the data, but, there is a data that does not bring it to me, and I was verifying and the only thing different that I found is:
That in my table A the data has ´ varchar(4)
´ and in my table C it has varchar(6)
the keys have the same namea.id_org = c.id_org
Is it necessary that they be identical in value, so that it brings me the data?
When relating 2 tables by means of
PRIMARY KEY
and oneFOREIGN KEY
you must take into account that:VARCHAR, DECIMAL o INT, etc
)INT(10) o VARCHAR(15)
EXAMPLE 1
main table
dependent table
The creation of the tables is done successfully, since both
id
thetablaUno
andtablaUno_id
the tabletablaDos
are of the same type:VARCHAR
and the same length10
EXAMPLE 2
I'm going to try to repeat the creation of the tables above, but this time look at the length of
tablaUno_id
as although it is of typeVARCHAR
this time it has a length of120
main table
dependent table
IT WILL GIVE ME THE FOLLOWING ERROR
Which is very descriptive by telling you the length between the primary key and the foreign key is not the same
EXAMPLE 3
If I now try to create a table with a primary key of type
VARCHAR(10)
like soBut I try to bind it to a foreign key of type
INT(10)
Even though both have the same length, the type is different
IT WILL GIVE ME THE FOLLOWING ERROR