SQL Trigger Updates Stock

Asked

Viewed 92 times

0

LISTA_DE_PRODUTOS

create table LISTA_DE_PRODUTOS (
   IDPRODUTO            numeric              identity,
   PRECO                money                null,
   DESIGNACAO           varchar(50)          null,
   ALCOOLICO            bit                  null,
   constraint PK_LISTA_DE_PRODUTOS primary key nonclustered (IDPRODUTO)

ITEMS

create table ITENS (
   IDTRANSACAO          numeric              not null,
   IDITEN               numeric              identity,
   IDPRODUTO            numeric              not null,
   QUANTIDADE           decimal(10,2)        null,
   constraint PK_ITENS primary key nonclustered (IDTRANSACAO, IDITEN)

TRANSACTIONS

create table TRANSACOES (
   IDTRANSACAO          numeric              identity,
   IDPULSEIRA           numeric              not null,
   IDPOS                numeric              not null,
   IDLOJA               numeric              not null,
   VALOR_TOTAL          money                null,
   DATA_DA_TRANSACCAO   datetime             null,
   constraint PK_TRANSACOES primary key nonclustered (IDTRANSACAO)

LOJAS_PRODUTOS

create table LOJAS_PRODUTOS (
   IDLOJA               numeric              not null,
   IDPRODUTO            numeric              not null,
   STOCK_DISPONIVEL     float                null,
   constraint PK_LOJAS_PRODUTOS primary key (IDLOJA, IDPRODUTO)

How do I create a Trigger to update stock with these tables?

With the following details:

Each of the transaction items can only be purchased if there is sufficient stock in the store in which the transaction is being made. If there is not enough stock of at least one of the products, the transaction and the respective items should not be loaded.

  • And how should the stock update be? Add in the topic description the details of what has to be done and mainly how.

  • 1

    "stock"!? Wouldn’t that be "stock"!?

  • Thank you very much José. I have already added the details.

No answers

Browser other questions tagged

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