If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-03, 09:41
trilly trilly is offline
Registered User
 
Join Date: Aug 2003
Location: Vicenza(I)
Posts: 21
Red face trigger

This is the trigger:

create trigger T_Noleggio
after insert on Noleggio
for each row
begin
IF((:new.codcliente=prenotazione.codcliente)&&(:ne w.codfilm=prenotazione.codfilm)
&&(:new.codnegozio=prenotazione.codnegozio)
delete prenotazione
end

what's the problem??
Thank, you Elisa

The table Prenotazione is:
CREATE TABLE Prenotazione
(CodFilm NUMBER(10) NOT NULL,
CodNegozio NUMBER(10) NOT NULL,
CodCliente VARCHAR(10) NOT NULL,
Data_Prenotazione date NOT NULL,
Supporto VARCHAR2(3) NOT NULL,
PRIMARY KEY(CodFilm,CodNegozio,CodCliente,Data_Prenotazion e),
FOREIGN KEY(CodNegozio)
REFERENCES Negozio(IdNegozio)
ON DELETE CASCADE,
FOREIGN KEY(CodFilm)
REFERENCES Film(IdFilm)
ON DELETE CASCADE,
FOREIGN KEY(CodCliente)
REFERENCES Cliente(User_id)
ON DELETE CASCADE)

and the table noleggio is:

CREATE TABLE Noleggio
(CodFilm NUMBER(10) NOT NULL,
CodNegozio NUMBER(10) NOT NULL,
CodCliente VARCHAR(10) NOT NULL,
Data_Noleggio date NOT NULL,
Supporto VARCHAR2(3) NOT NULL,
PRIMARY KEY(CodFilm,CodNegozio,CodCliente,Data_Noleggio),
FOREIGN KEY(CodNegozio)
REFERENCES Negozio(IdNegozio)
ON DELETE CASCADE,
FOREIGN KEY(CodFilm)
REFERENCES Film(IdFilm)
ON DELETE CASCADE,
FOREIGN KEY(CodCliente)
REFERENCES Cliente(User_id)
ON DELETE CASCADE)
Reply With Quote
  #2 (permalink)  
Old 08-28-03, 10:08
sjacek sjacek is offline
Registered User
 
Join Date: May 2003
Location: Dublin, Ireland
Posts: 44
Re: trigger

Elisa,

You are trying to compare values passed to the trigger by insert statement with the values from anothe table without retrieving those values from the table.
How this poor trigger should know what is the value of for example prenotazione.codcliente ?

Hope it explains it,

Jacek
Quote:
Originally posted by trilly
This is the trigger:

create trigger T_Noleggio
after insert on Noleggio
for each row
begin
IF((:new.codcliente=prenotazione.codcliente)&&(:ne w.codfilm=prenotazione.codfilm)
&&(:new.codnegozio=prenotazione.codnegozio)
delete prenotazione
end

what's the problem??
Thank, you Elisa

Reply With Quote
  #3 (permalink)  
Old 08-29-03, 08:58
trilly trilly is offline
Registered User
 
Join Date: Aug 2003
Location: Vicenza(I)
Posts: 21
Re: trigger

Quote:
Originally posted by sjacek
Elisa,

You are trying to compare values passed to the trigger by insert statement with the values from anothe table without retrieving those values from the table.
How this poor trigger should know what is the value of for example prenotazione.codcliente ?

Hope it explains it,

Jacek
The value of prenotazione.codcliente is carchar2, while the value of prenotazione.idfilm nd prenotazione.ifnegozio is number.
Thank you Elisa
Reply With Quote
  #4 (permalink)  
Old 08-29-03, 10:32
sjacek sjacek is offline
Registered User
 
Join Date: May 2003
Location: Dublin, Ireland
Posts: 44
Re: trigger

As far as I understand what you are trying to do trigger should look something like that:

create trigger T_Noleggio
after insert on Noleggio
for each row
begin
delete from prenotazione where
codcliente =:new.codcliente and
codfilm=:new.codfilm and
codnegozio=:new.codnegozio;
end;

It will delete from prenotazione row with matching new values.

Hope it helps,

Jacek



Quote:
Originally posted by trilly
The value of prenotazione.codcliente is carchar2, while the value of prenotazione.idfilm nd prenotazione.ifnegozio is number.
Thank you Elisa
Reply With Quote
  #5 (permalink)  
Old 08-30-03, 09:37
trilly trilly is offline
Registered User
 
Join Date: Aug 2003
Location: Vicenza(I)
Posts: 21
Re: trigger

thank you for your help but when I do an insert on noleggio the result is:
Error: ORA-04098: trigger 'T_NOLEGGIO' is invalid and failed re-validation

The problem is this I've two table prenotazione and noleggio with the same field but when I insert a new value on noleggio I check if the value is on the table prenotazione and if there is I want to delete.
What's the trigger that resolv this problem?
Thank you
Elisa
Reply With Quote
  #6 (permalink)  
Old 08-30-03, 09:42
trilly trilly is offline
Registered User
 
Join Date: Aug 2003
Location: Vicenza(I)
Posts: 21
Re: trigger

I've just resolv the problem ... I bad write the trigger.
Elisa
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On