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 > Triggers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-26-03, 02:37
fantomen66 fantomen66 is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Unhappy Triggers

I would like to create a trigger on insert, update where I want to
copy each record I insert in one table to another.. from table tblFromCity(FromCityID, FromCityName, GLIndicatorID, CountryID)
to table tblToCity (ToCityID, ToCityName, GLIndicatorID, CountryID)

thanks..
sohail
Reply With Quote
  #2 (permalink)  
Old 04-26-03, 10:05
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Triggers

Quote:
Originally posted by fantomen66
I would like to create a trigger on insert, update where I want to
copy each record I insert in one table to another.. from table tblFromCity(FromCityID, FromCityName, GLIndicatorID, CountryID)
to table tblToCity (ToCityID, ToCityName, GLIndicatorID, CountryID)

thanks..
sohail
1) Have you tried writing this most basic of triggers yourself? There is plenty of guidance and examples here:

http://technet.oracle.com/docs/produ...g13trg.htm#376

2) What is the point of this trigger - i.e. what is the point of having your City data in 2 identical tables?
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 04-26-03, 13:50
fantomen66 fantomen66 is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Triggers

Hi Tony,

I must admite that I am quite new to triggers.
1. This link: http://technet.oracle.com/docs/prod...dg13trg.htm#376
was down when I tried.
2. The reason for this trigger is that I have a fares table where I need to put a travelling from city, and put a travelling to city. They exist as foreign keys in the fares table. Both the city paires have their own table. What i want to do is that when i register a city in the table tblFromCity I want the same values be insterted in the table tblToCity. Thata why I need a trigger for insert, update.
Reply With Quote
  #4 (permalink)  
Old 04-26-03, 14:05
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Triggers

Quote:
Originally posted by fantomen66
Hi Tony,

I must admite that I am quite new to triggers.
1. This link: http://technet.oracle.com/docs/prod...dg13trg.htm#376
was down when I tried.
2. The reason for this trigger is that I have a fares table where I need to put a travelling from city, and put a travelling to city. They exist as foreign keys in the fares table. Both the city paires have their own table. What i want to do is that when i register a city in the table tblFromCity I want the same values be insterted in the table tblToCity. Thata why I need a trigger for insert, update.
1. I'll try that link again:

http://technet.oracle.com/docs/produ...g13trg.htm#376

2. That makes no sense to me. If the Fare table has a from_city and a to_city, then BOTH columns should be foreign keys to the same table City:

CREATE TABLE City( City_ID NUMBER PRIMARY KEY, ...)
CREATE TABLE Fare( From_City_ID REFERENCES City,
To_city_ID REFERENCES City, ...)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 04-27-03, 15:19
fantomen66 fantomen66 is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Question Triggers

You are absolutely right, as I am still a student I was not aware of the REFERNCES keyword.
I did try out the following code in Query Anaylzer:

ALTER TABLE Fare (FromCityID REFERENCES tblCity(CityID), ToCityID REFERENCES tblCity(CityID))

but got the following error message:

Line 1: Incorrect syntax near '('.
Reply With Quote
  #6 (permalink)  
Old 04-28-03, 05:07
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Triggers

Quote:
Originally posted by fantomen66
You are absolutely right, as I am still a student I was not aware of the REFERNCES keyword.
I did try out the following code in Query Anaylzer:

ALTER TABLE Fare (FromCityID REFERENCES tblCity(CityID), ToCityID REFERENCES tblCity(CityID))

but got the following error message:

Line 1: Incorrect syntax near '('.
In Oracle, the correct syntax would be:

alter table fare add constraint fk1 foreign key (FromCityID) references tblCity;
alter table fare add constraint fk2 foreign key (ToCityID) references tblCity;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
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