Whereas its tables already created contain the following structure:
Tabela Usuarios
PK idUsuarios int
Nome varchar(30)
NomeCompleto varchar(255)
Table Products
PK idProdutos int
Descricao varchar(255)
ValorUnit decimal(10,4)
The new tables you want
Order table
PK idPedidos int
FK idUsuarios int
DataPedido datetime
ValorTotal decimal(10,4)
SQL code
create table Pedidos
(idPedidos int identity,
idUsuarios int,
DataPedido datetime,
ValorTotalPedido decimal(10,4))
Order Tableproduct -> Link to the various products of the application
PK idPedidos int
PK idProdutos int
Qtde decimal(7,4) -> Decimal para produtos fracionados por exemplo
SQL code
create table PedidosProdutos
(idPedidos int,
idProdutos int,
Qtde decimal(7,4))
Please note that you can register multiple products using the same order ID. Ex:
+---------------------------+
| PEDIDO | PRODUTO | QTDE |
+---------------------------+
| 1 | 1029 | 1.0000 |
| 2 | 1023 | 3.0000 |
| 3 | 1993 | 8.3100 |
+---------------------------+
If I understand correctly, and a relationship 1 to n, then you should create the requested table and put in it a foreign key to the primary key of products, if it’s not that or you want the code in sql let me know
– user53006
Search Google < order system diagram > you’ll get some ideas.
– Motta
@Sergioguerik: What is the database manager: SQL Server? Oracle database? Mariadb?
– José Diz
Arcashaid, if you can show me through a code number how to do this would be great. thanks
– Sergio Guerjik
Jose says, the Bank is SQL
– Sergio Guerjik