Results 1 to 3 of 3

Thread: Trigger problem

  1. #1
    Join Date
    Feb 2008
    Posts
    1

    Unanswered: Trigger problem

    I have question about TRIGGERS.
    I have (4 example) VEHICLE_TABLE with VEHICLE_TYPE column and CAR_TABLE and TRUCK_TABLE also.
    I need TRIGGER for INSERT/UPDATE/DELETE who well read value of VEHICLE_TYPE column in VEHICLE_TABLE and if value of VEHICLE_TYPE is CAR he will execute
    INSERT/UPDATE/DELETE on CAR_TABLE and if value of VEHICLE_TYPE column in VEHICLE_TABLE is TRUCK he will execute INSERT/UPDATE/DELETE on TRUCK_TABLE.
    I am using SQL Server 2005.
    Is there any idea how can I solve this problem.
    Thanks in advance
    David

  2. #2
    Join Date
    Aug 2005
    Location
    D/FW, Texas, USA
    Posts
    78
    Look up the "Designing Instead Of Triggers" article in Books Online.

    That will allow you to re-route the transaction to a different table. For inserts you can get the data you need to route from the "inserted" table in the trigger. Delete data will be in the "deleted" table, and an Update will contain a row in both "deleted" and "inserted".
    --wayne
    SELECT * FROM Users WHERE Clue>0
    0 rows returned

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by david_bronsky
    I need TRIGGER for INSERT/UPDATE/DELETE who well read value of VEHICLE_TYPE column in VEHICLE_TABLE and if value of VEHICLE_TYPE is CAR he will execute
    INSERT/UPDATE/DELETE on CAR_TABLE and if value of VEHICLE_TYPE column in VEHICLE_TABLE is TRUCK he will execute INSERT/UPDATE/DELETE on TRUCK_TABLE.
    The trigger will fire regardless of what the value is. Within the trigger you will need to include logic regarding what to do under each circumstance.

    But the bigger question is why you have trucks and cars in separate tables. This is almost certainly a design flaw. If you had them in the same table with a indicator as to type, you could implement cascading relationships and bypass the triggers altogether.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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