Results 1 to 5 of 5

Thread: Triggers

  1. #1
    Join Date
    Feb 2003
    Posts
    7

    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
    Apr 2003
    Posts
    18

    Re: Triggers

    CREATE TRIGGER trig1
    on tblFromCity
    FOR INSERT
    AS
    BEGIN

    Insert into tblToCity (ToCityID, ToCityName, GLIndicatorID, CountryID)
    Select FromCityID, FromCityName, GLIndicatorID, CountryID
    From INSERTED
    END

    Try this.....
    Cheers,
    Gola
    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

  3. #3
    Join Date
    Feb 2003
    Posts
    7

    Triggers

    As Tony mentioned it there is no need to create two tables, instead i should use the REFERNCES keyword to refernce the colum toCityFare and FromCityFare in my Fare table to a singel colum in for example a city table called CityID.

    But when I tried this in Query Anaylyzer I get the following error:

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

    but got the following error message:

    Line 1: Incorrect syntax near '('.

  4. #4
    Join Date
    Oct 2001
    Location
    England
    Posts
    426
    ???
    What are you trying to do with that statement.
    Looks like sort of a foreign key. If so look at the syntax and examples in bol (it wants an "add constraint" or "add foreign key").
    This will only stop data being added which violates the foreign key though - it won't add data to a table.

    alter table Fare add foreign key (FromCityID) references tblCity(CityID)

    or something like that.

  5. #5
    Join Date
    Jan 2003
    Location
    London, England
    Posts
    106
    I would assume that the syntax would be more like this:

    ALTER TABLE Fare (FromCityID REFERENCES tblCity.CityID, ToCityID REFERENCES tblCity.CityID)
    Frettmaestro
    "Real programmers don't document, if it was hard to write it should be hard to understand!"

Posting Permissions

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