Sequence of SQL command execution involving triggers and stored procedures.
am 18.09.2004 06:54:24 von orathThis is a multi-part message in MIME format.
------_=_NextPart_001_01C49D3B.91BA5806
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
I am observing the following:
=20
Say there is a stored procedure i.e FUNCTION sp_foo(...) which has say,
SQL commands (any of SELECT,INSERT,UPDATE,DELETE) in its body, say S1
followed by S2 then S3.... Furthermore, execution of statement S2
results in trigger functions getting invoked (that contain yet other SQL
statements).
=20
By the time, the trigger functions execute (as a result of S2), S3 has
already executed.
=20
Note that sp_foo() was invoked via a SELECT i.e SELECT sp_foo(...).
=20
To work around this "behaviour", I wrapped sp_foo() within another
FUNCTION say sp_foo_wrapper(...) and in the body of sp_foo_wrapper() I
did this -
=20
1. INSERT
2. Invoke sp_foo().
3. DELETE
flag
=20
Even then, by the time the triggers fired as a result of S2 (in the body
of sp_foo), the DELETE (in step 3 above) had executed.
=20
Questions:
1. Did I miss something very basic?
=20
2. Is this behavior random i.e the manifestation pertians to the
particular SQL commands in my code?
=20
3. How does one achieve, the chronolgy that I want i.e I want S3 AND/OR
step 3 to occur AFTER the triggers (as a result of S2) to fire?
=20
Thanx in advance,
=20
=20
=20
Omkar Rath
Software Engr.
VTG
Cisco Systems Inc.
------_=_NextPart_001_01C49D3B.91BA5806
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
rving the=20
following:
is a=20
stored procedure i.e FUNCTION sp_foo(...) which has say, SQL commands =
(any=20
of SELECT,INSERT,UPDATE,DELETE) in its body, say S1 followed by S2 then S3.=
....=20
Furthermore, execution of statement S2 results in trigger functions ge=
tting=20
invoked (that contain yet other SQL statements).
me, the=20
trigger functions execute (as a result of S2), S3 has already=20
executed.
sp_foo()=20
was invoked via a SELECT i.e SELECT sp_foo(...).
round this=20
"behaviour", I wrapped sp_foo() within another FUNCTION say sp_foo_wrapper(=
....)=20
and in the body of sp_foo_wrapper() I did this -
=20
<something> in a scratch table // akin to setting a=20
flag
=20
sp_foo().
=20
<something> from the scratch table // akin to resetting the=20
flag
, by the=20
time the triggers fired as a result of S2 (in the body of sp_foo), the DELE=
TE=20
(in step 3 above) had executed.
miss=20
something very basic?
s behavior=20
random i.e the manifestation pertians to the particular SQL commands in my=
=20
code?
es one=20
achieve, the chronolgy that I want i.e I want S3 AND/OR step 3 to occur AFT=
ER=20
the triggers (as a result of S2) to fire?
=20
advance,
Rath
=20
Engr.
tems=20
Inc.
------_=_NextPart_001_01C49D3B.91BA5806--