Doubt SQL tables

Asked

Viewed 58 times

0

In the 1:1 relations I have done in another way that only today I noticed, in which I turn this 1:1 to 1:N, and in the table that has the N, the primary key is the same as the 1, so it’s like 1:1, but I don’t know if this method can generate errors?

Example:

tabela 1
--------------
id_ficha - PrimaryKey
etc..

tabela 2
-------------
id_ficha -PrimaryKey e ForeignKey(tabela1)
etc...
  • I did not understand what exactly is your doubt. Is it about the cardinality? Could it be more specific?

  • If you want to relate table 1 to 2, you need to have the "id" of one on the other to "tie" the die, if you say the id is the same. 1°- will these id always be the same? 2°- If they are always equal and you do not want to put the id of one table in the other, this "mooring" will be in charge of the code, which will always have to take the "id’s" equal, and not by the bank. From the bank’s point of view, it would only be two fields, which by chance would have equal values

  • @2016, I don’t know any other way to make a 1:1 relationship

  • Usually what they give in college is, create two different primary keys one for each table, and when it is 1:1 the primary key of the two passes to the foreign key of the other. That way I presented up, I was always told I might be sick, and I’m trying to clear that up

1 answer

2


It won’t make any mistakes. The method that will be assumed is 1:1 if you do not create FK_ID in table 2 by relating it to table 1.

However, if you are creating table 2 for normalization, you should at least adopt the good practices of data modeling - creating in table 2, the respective PK_ID and FK_ID.

  • 1

    Thank you for the answer! That’s right. I like to use different ways that lead to the same result, but they always advise me to follow the rules so there are no mistakes, and when I try a new way I am afraid of future mistakes in the database. Vlw :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.