| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |

04-26-03, 03:37
|
|
Registered User
|
|
Join Date: Feb 2003
Posts: 7
|
|
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
|
|

04-26-03, 11:05
|
|
Moderator.
|
|
Join Date: Sep 2002
Location: UK
Posts: 4,874
|
|
|
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?
|
|

04-26-03, 14:50
|
|
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.
|
|

04-26-03, 15:05
|
|
Moderator.
|
|
Join Date: Sep 2002
Location: UK
Posts: 4,874
|
|
|
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, ...)
|
|

04-27-03, 16:19
|
|
Registered User
|
|
Join Date: Feb 2003
Posts: 7
|
|
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 '('.
|
|

04-28-03, 06:07
|
|
Moderator.
|
|
Join Date: Sep 2002
Location: UK
Posts: 4,874
|
|
|
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;
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|