several foreign SQL keys

Asked

Viewed 305 times

1

I have the following table: items (ref) the attribute "ref" as the primary key of the table, may have associated several secondary keys in other tables [ex:Tabela1(ref) and table2(ref) being "ref" the secondary key of the respective tables]?

  • 1

    Yes, you can have..

1 answer

1


A brief summary

Primary and Foreign Keys are two types of constraints that can be used to enforce data integrity in tables.
Generally, a table has a column or combination of columns that contains values that uniquely identify each row in the table (identity). Because PRIMARY KEY constraints ensure unique data, they are often defined as an identity column.

This identity is used in the other tables (foreign key) to classify the records that "belong" to the primary table.

Note the template below and see that it is possible to SIM set as many as necessary:

tbl_usuarios
    PK id_usuarios numero identity---+
       nome texto                    |
                                     |
tbl_materias                         |
    PK id_materias numero identity---͡ -+
       descricao texto               | |
    FK id_usuarios-------------------◄ | 
                                     | |
tbl_faltas                           | |
    PK id_faltas numero identity     | |
       dataRef data                  | |
    FK id_usuarios-------------------◄ |
                                     | |
tbl_notas                            | |
    PK id_notas numero identity      | |
    FK id_materias numero------------͡ -◄
    nota numero                      |
    FK id_usuarios-------------------◄
                                     |
tbl_eventos                          |
    PK id_eventos numero identity    |
       dataRef data                  |
    FK tiposEvento numero            |
    FK id_usuarios-------------------◄

tbl_tiposEvento
    PK id_tiposEvento numero identity
    descricao texto

Primary key and foreign key restrictions

Browser other questions tagged

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