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.

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, 03: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, 11:05
andrewst andrewst is offline
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?
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #3 (permalink)  
Old 04-26-03, 14: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, 15:05
andrewst andrewst is offline
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, ...)
__________________
Tony Andrews
http://tonyandrews.blogspot.com
Reply With Quote
  #5 (permalink)  
Old 04-27-03, 16: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, 06:07
andrewst andrewst is offline
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;
__________________
Tony Andrews
http://tonyandrews.blogspot.com
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

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