3
I am creating an academic system that consists of a virtual restaurant menu type, for this, I created three tables in the bank:
Table of Menu Items:
CREATE TABLE ITEMS(
ID INT PRIMARY KEY NOT NULL,
NOME VARCHAR(20) NOT NULL,
DESCRICAO VARCHAR(20),
PRECO FLOAT NOT NULL
)
Order Table:
CREATE TABLE PEDIDO(
NUMERO INT PRIMARY KEY NOT NULL,
MESA INT NOT NU NULL,
VALORTOTAL FLOAT
)
Table where I record Order Items, where:
ID_PEDIDO = FK de Pedido, ID_ITEM = FK de Item
CREATE TABLE ITEM_PEDIDO(
ID INT PRIMARY KEY NOT NULL,
ID_PEDIDO INT NOT NULL,
ID_ITEM INT NOT NULL,
QTD_ITEM INT
)
My question is this::
On the system, the user will be able to choose a item or more to your request, as well as the quantity of this item. At the end of the order, you must return the price total of it.
So, should I leave QTD_ITEM in the ITEM_PEDIDO table? As for the PRICE, I must leave in the ITEM table or include also in the ITEM_PEDIDO table?
Thank you very much @Sorack! You helped me a lot! Now I only have one question: In JAVA, I have a class for each section of the menu. For example: One class for drinks, another for salads, another for desserts and so on. I can leave in the database a single table for them, which is the case of the ITEM table, or I should "subdivide" this ITEM into several tables, such as: TABLE DRINKS, TABLE SALADS, etc. ?
– Eduardo R
@Eduardor not necessarily. If the attributes are equal and only the different behavior do not see why create several tables.
– Sorack
That’s what I really thought, @Sorack! Thanks for clearing up my question.
– Eduardo R