Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.

  1. #21

    Default Re: Trigger Question

    Terry Lee Tucker wrote:
    > 1) INSERT INTO logs (carr_code, ..., ..., ...) VALUES('ABCDEFG', ..., ...);
    > logs is table A in my question
    >
    > 2) logs_insert fires (This is a AFTER INSERT trigger)
    >
    > 3) in this trigger, I need to do the following:
    > update avlds set carr_code = new.carr_code where avlds.recid = ??;
    > avlds is table B in my question
    > The questions marks indicate the first piece of data that I want to
    > dynamically pass to the trigger.
    >
    > 4) in the same trigger:
    > update tract set order_num = avlds.order_num where tract.recid = ??;
    > tract is table C in my question
    > The question marks refer to the second piece of data that I want to pass
    > dynamically into the trigger.
    >
    > In other terms, when the user creates a logs record that assigns a truck to a
    > load, I need to update specific rows in two other tables, avlds, and tract. I
    > was wanting to do this from the trigger level, but I will need the unique
    > serial key of each of the existing records in avlds and tract. These two keys
    > comprise the "dynamic" part of the question. I was just wondering if there is
    > some way of passing dynamic data into a trigger. I don't believe there is,
    > but I thought I would ask.
    I cannot figure out if you are supposed to use the same value as ??, but
    I believe I would just create a function (which takes parameters) and
    then call that from the logs_insert trigger. That way I believe you have
    a much better control of the flow of your updates.

    Hope that helps.

    --
    Thomas Braad Toft

    ---------------------------(end of broadcast)---------------------------
    TIP 1: subscribe and unsubscribe commands go to [email]majordomo@postgresql.org[/email]

    Thomas Braad Toft Guest

  2. Similar Questions and Discussions

    1. SQL Server Trigger question
      Hi All, I have a cf app accessing data from a database that is controlled primarily by our MRP software. My problem isn't really ColdFusion...
    2. An trigger question
      Hi,all: I want to create some trigger on an important database,my database is IDS2000. My question is: If exist a way to limit me only can create...
    3. question about trigger
      Hello, I would like to use trigger to record change in every field (F1, F2, F3..) from table TAB1. CREATE TRIGGER TR1 AFTER UPDATE OF F1, F2,...
    4. Trigger question ...
      We have about 50 customers in hosted environment, each running databases withi identical schema but different names. Part of the application traps...
    5. Simple trigger question
      I'm real rusty with triggers..and I need one fairly quickly, so I would really appreaciate a bit of help. All I need to do: Upon insert or...
  3. #22

    Default Re: Trigger Question

    Maybe what you want is a stored procedure, not a trigger. A trigger
    will only have the data that is available from the insert operation,
    and the rest of the row that was modified (It really can't have
    anything else if you think about it)

    Stored procedures are an exellent way to guarantee atomic access to
    data in an application.

    Alex Turner
    NetEconomist


    On Wed, 5 Jan 2005 16:35:42 -0500, Terry Lee Tucker <terry@esc1.com> wrote:
    > 1) INSERT INTO logs (carr_code, ..., ..., ...) VALUES('ABCDEFG', ..., ...);
    > logs is table A in my question
    >
    > 2) logs_insert fires (This is a AFTER INSERT trigger)
    >
    > 3) in this trigger, I need to do the following:
    > update avlds set carr_code = new.carr_code where avlds.recid = ??;
    > avlds is table B in my question
    > The questions marks indicate the first piece of data that I want to
    > dynamically pass to the trigger.
    >
    > 4) in the same trigger:
    > update tract set order_num = avlds.order_num where tract.recid = ??;
    > tract is table C in my question
    > The question marks refer to the second piece of data that I want to pass
    > dynamically into the trigger.
    >
    > In other terms, when the user creates a logs record that assigns a truck to a
    > load, I need to update specific rows in two other tables, avlds, and tract. I
    > was wanting to do this from the trigger level, but I will need the unique
    > serial key of each of the existing records in avlds and tract. These two keys
    > comprise the "dynamic" part of the question. I was just wondering if there is
    > some way of passing dynamic data into a trigger. I don't believe there is,
    > but I thought I would ask.
    >
    > Thanks for the input.
    > Work: 1-336-372-6812
    > Cell: 1-336-363-4719
    > email: [email]terry@esc1.com[/email]
    >
    > ---------------------------(end of broadcast)---------------------------
    > TIP 8: explain analyze is your friend
    >
    ---------------------------(end of broadcast)---------------------------
    TIP 1: subscribe and unsubscribe commands go to [email]majordomo@postgresql.org[/email]

    Alex Turner Guest

  4. #23

    Default Re: Trigger Question

    Now why didn't I think of that? That's exactly what I need to do. Thanks to
    all who responded ;o)

    On Wednesday 05 January 2005 05:09 pm, Alex Turner saith:
    > Maybe what you want is a stored procedure, not a trigger. A trigger
    > will only have the data that is available from the insert operation,
    > and the rest of the row that was modified (It really can't have
    > anything else if you think about it)
    >
    > Stored procedures are an exellent way to guarantee atomic access to
    > data in an application.
    >
    > Alex Turner
    > NetEconomist
    >
    > On Wed, 5 Jan 2005 16:35:42 -0500, Terry Lee Tucker <terry@esc1.com> wrote:
    > > 1) INSERT INTO logs (carr_code, ..., ..., ...) VALUES('ABCDEFG', ...,
    > > ...); logs is table A in my question
    > >
    > > 2) logs_insert fires (This is a AFTER INSERT trigger)
    > >
    > > 3) in this trigger, I need to do the following:
    > > update avlds set carr_code = new.carr_code where avlds.recid =
    > > ??; avlds is table B in my question
    > > The questions marks indicate the first piece of data that I want
    > > to dynamically pass to the trigger.
    > >
    > > 4) in the same trigger:
    > > update tract set order_num = avlds.order_num where tract.recid =
    > > ??; tract is table C in my question
    > > The question marks refer to the second piece of data that I want
    > > to pass dynamically into the trigger.
    > >
    > > In other terms, when the user creates a logs record that assigns a truck
    > > to a load, I need to update specific rows in two other tables, avlds, and
    > > tract. I was wanting to do this from the trigger level, but I will need
    > > the unique serial key of each of the existing records in avlds and tract.
    > > These two keys comprise the "dynamic" part of the question. I was just
    > > wondering if there is some way of passing dynamic data into a trigger. I
    > > don't believe there is, but I thought I would ask.
    > >
    > > Thanks for the input.
    > > Work: 1-336-372-6812
    > > Cell: 1-336-363-4719
    > > email: [email]terry@esc1.com[/email]
    > >
    > > ---------------------------(end of broadcast)---------------------------
    > > TIP 8: explain analyze is your friend
    >
    > ---------------------------(end of broadcast)---------------------------
    > TIP 1: subscribe and unsubscribe commands go to [email]majordomo@postgresql.org[/email]
    --
    Work: 1-336-372-6812
    Cell: 1-336-363-4719
    email: [email]terry@esc1.com[/email]

    ---------------------------(end of broadcast)---------------------------
    TIP 9: the planner will ignore your desire to choose an index scan if your
    joining column's datatypes do not match

    Terry Lee Tucker Guest

  5. #24

    Default Re: Trigger Question

    On Wed, Jan 05, 2005 at 05:35:18PM -0500, Terry Lee Tucker wrote:
    > On Wednesday 05 January 2005 05:09 pm, Alex Turner saith:
    > >
    > > Maybe what you want is a stored procedure, not a trigger.
    >
    > Now why didn't I think of that? That's exactly what I need to do.
    This is a good example of why it's better to describe the problem
    you're trying to solve instead of asking about a partcular (and
    possibly suboptimal or wrong) way to solve it, and why it's important
    to provide enough information so that others can understand what
    you're trying to do.

    [url]http://www.catb.org/~esr/faqs/smart-questions.html#goal[/url]
    [url]http://www.catb.org/~esr/faqs/smart-questions.html#beprecise[/url]

    --
    Michael Fuhr
    [url]http://www.fuhr.org/~mfuhr/[/url]

    ---------------------------(end of broadcast)---------------------------
    TIP 7: don't forget to increase your free space map settings

    Michael Fuhr Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139