Foreign key FK, is each identification number on a table?

Asked

Viewed 275 times

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, is the customer number, order number, customer number, item number, order number, deposit number, there is some restriction in this example, someone can see?

2 answers

0

The foreign key (Foreign Key) is when a key of a table (some call index, or ID) is used within another table to reference it, then it exists to relate them, ie it does not exist alone.

In your example NUM_CLIENTE is foreign key in table REQUEST (refers to the customer who placed the order) while NUM_PEDIDO is foreign key in tables ITEM_PEDIO and also in EXPEDITION. In the case of the table ITEM_PEDIO she has two foreign keys because it correlates the tables ITEM and REQUEST.

The only restriction I saw in your model is related to the fact that an order can be sent (dispatched) in installments or even keep a history about its state (pending, sent, returned etc).

0

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

CLIENT(Num_client, Client Name, City)

REQUEST(Num_request, Requested date, Num_client, Preco_total)

ITEM_PEDIO(On request, Item number, Amount)

ITEM(Num_item, Preco_unitario)

EXPEDITION(On request, Depository, Sending date)

DEPOSIT(Num_deposito, City)

Browser other questions tagged

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