-1
The Trigger I have to do:
A user can only classify an offer if he has purchased it (reservation with
estado = pago
). On the other hand one of the two attributes classification and comment has to beNOT NULL
.
What I’ve been doing:
create trigger T10 on CLASSIFICACOES instead of insertas begin
--inserir apenas se tiver adquirido um produto/serviço (reserva de estado = pago)
insert into CLASSIFICACOES
select
i.ID_UTILIZADOR,
i.ID_OFERTA,
i.ID_CLASSIFICACAO,
i.DATA_DA_CLASSIFICACAO,
i.CLASSIFICACAO,
i.COMENTARIO
from inserted i
where exists (
select
[ESTADO_DA_RESERVA]
from RESERVAS r,
where
r.[ESTADO_DA_RESERVA] = 'Pago'
)
-- verificar se tem ou comentário ou classificação `NULL`
-- (aqui agora quero verificar se algum dos campos é `NULL` para não poder inserir caso o sejam)
Is the right way to think to create this Rigger? If so, how do I check if the fields are NULL
?
Tables that matter:
CLASSIFICACOES (
id_utilizador (pk),
id_oferta (pk),
id_classificacao (pk),
data_da_classificacao,
classificacao,
comentario
)
RESERVAS (
id_reserva (pk),
id_meio_pagamento (fk),
data_de_reserva,
data_de_pagamento,
estado_da_reserva,
total
)
UTILIZADORES(
id_utilizador (pk),
id_empresa (fk),
login,
email,
primeironome,
ultimonome,
nif,
bloqueado
)
You cannot enter this clause of
NOT NULL
in thewhere
where you already check whether you are paid?– Giovane
@Giovane not because they are different tables, your suggestion would be right in Where to try to create solution where to verify if there is null in this field?
– Ricarte
Yeah, just run a search with
JOIN
. These tables relate, right?– Giovane
Not the reserve table connects to a table of offers and that of offers is what links to one of ratings... Hence I don’t quite know how to make the querys to make this Trigger @Giovane
– Ricarte
Put the structures there, just the parts that relate, I’ll help you.
– Giovane
@Giovane I edited in the reply, I hope it’s what you asked
– Ricarte
Which database??
– Giovane
@Giovane thanks for the formatting of the question (still not quite sure how to put the questions well arranged
– Ricarte
What do you mean? @Giovane
– Ricarte
Which database is using? Mysql, Postgres, Oracle, SQL Server?
– Giovane
SQL Sever @Giovane
– Ricarte
Right... how will you know if the user made the payment if the reservation does not have his ID?
– Giovane
Understanding "one of the two attributes classification and comment has to be NOT NULL" as the two can be simultaneously NOT NULL is only use OR (A IS NOT NULL OR B IS NOT NULL). If they cannot be simultaneously NOT NULL then you will need to use the XOR operator, which does not exist directly but can be rewritten with a combination of OR, AND and NOT.
– anonimo