Stefan
Sat Oct 13 03:34:05 PDT 2007
Hi Walter -
"WP" <wpaul@nospam_fibertel.com.ar> wrote in message
news:ePdM69I$HHA.1900@TK2MSFTNGP02.phx.gbl...
> Thanks, Stefan,
>
> I would prefer to show a message if there are children for the parent to
> be deleted.
I'd recommend not to do so in the stored procedure itself because
that way your formerly invisible "backend" gets a user interface and
cannot be used in scenarios like COM or web applications anymore.
Personally I'd prefer separate "tiers" and in this case write a few lines
of code in the UI tier to ask the user before the delete attempt would
take place.
> And then I have another question: normally in my programs I open the
> tables with different aliases. Let's say I have the tables "parent" and
> "child".
>
> In some programs I do:
> USE parent ALIAS parent1 IN 1
> USE child ALIAS child1 IN 2
>
> Does your code work even in that cases ?
Yes.
> Because I remember 2 weeks ago I used an "UPDATE child SET...." command on
> the real table name, and the changes were not buffered, but if I wrote
> "UPDATE child1 SET...." the changes were buffered. So I concluded that you
> have to use in UPDATE and DELETE commands the alias name, and not the real
> table name, in order for the changes being buffered with the possibility
> to undo them should there be an error some lines further down.
Yes, you're right - since you asked for "a very simple piece of code"... :-)
However, the previous sample works fine in a local-views-only scenario,
for instance.
OTOH, when the "child" table is in use with its default alias name *and is
buffered, the code might fail I think - in that case you can probably
improve it by opening the child table with a random alias inside the SP
and use that one for the Delete statement.
FWIW, for an RI alternative see also
http://www.utmag.com/ViewPageArticle.aspx?Session=7A39664C377966557263673D20683236326E43686B41656C49703477616A61314349673D3D
hth
-Stefan
--
|\_/| ------ ProLib - programmers liberty -----------------
(.. ) Our MVPs and MCPs make the Fox run....
- / See us at www.prolib.de or www.AFPages.de
-----------------------------------------------------------