Foreign key FK, is each ID number in a table?

1

Example:

 - CLIENTE(Num_cliente, Nome_cliente, Cidade)
 - PEDIDO(Num_pedido, Data_pedido, Num_cliente, Preco_total)
 - ITEM_PEDIDO(Num_pedido, Num_item, Quantidade)
 - ITEM(Num_item, Preco_unitario)
 - EXPEDICAO(Num_pedido, Num_deposito, Data_envio)
 - DEPOSITO(Num_deposito, Cidade)

In this case the FK, are the customer number, order number, customer number, item number, order number, deposit number is there any restriction in this example, can anyone see?

    
asked by anonymous 03.09.2018 / 02:56

2 answers

0

The foreign key is when a key in a table (some call it index, or ID) is used inside another table to reference it, so it exists to relate them, that is, not exists alone.

In your example NUM_CLIENTE is a foreign key in the REQUEST table (it refers to the requesting client) while NUM_PEDIDO is a foreign key in the REQUIRED ITEM and also in EXPEDITION . In the case of the ITEM_QUED table, it has two foreign keys as it correlates the ITEM and REQUEST tables. >

The only restriction that I saw in your model is that a request can be sent (parceled) in a piecemeal way or even keep a history of your status (pending, sent, returned, etc.).

    
03.09.2018 / 03:18
0

The ones you mentioned are the PK candidates from the respective tables ... The FK is the key that refers to the other table and, in its tables, are the ones that follow in bold:

CLIENT (Num_client, Clients_Name, City)

ORDER (Order_Number, Order_Date, Customer_Number , Price_total)

Quantity , Num_item , Num_item

ITEM (Num_item, Preco_unitario)

EXPEDITION ( Num_pedid , Num_destination , Ship_Date)

DEPOSIT (Num_deposit, City)

    
03.09.2018 / 05:44