Results 1 to 6 of 6

Thread: Triggers

  1. #1
    Join Date
    Feb 2003
    Posts
    7

    Unhappy Unanswered: 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

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Triggers

    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?

  3. #3
    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.

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Triggers

    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, ...)

  5. #5
    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 '('.

  6. #6
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Triggers

    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •