Re: using a trigger to enforce referential integrity
From: Scott Morris (bogus_at_bogus.com)
Date: 07/28/04
- Next message: Andrew J. Kelly: "Re: Object creation not appearing in consequent log backup"
- Previous message: kurt sune: "Implementing Circular Consistency"
- In reply to: pmcguire: "Re: using a trigger to enforce referential integrity"
- Next in thread: pmcguire: "Re: using a trigger to enforce referential integrity"
- Reply: pmcguire: "Re: using a trigger to enforce referential integrity"
- Reply: Hugo Kornelis: "Re: using a trigger to enforce referential integrity"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Jul 2004 08:51:10 -0400
The first thing to do is COMPLETELY and EXACTLY specify the error message
you are receiving. Lets avoid "something like..." to avoid confusion and
red herrings. As Hugo and I suggested, the problem is probably related to
WHO is doing the insert. Most likely your tests using EM are done using
adminstrator-level privileges. The same for QA. If you login to QA with
the same permissions as a "real" user of your application, you should be
able to insert a row into the table and see a more complete picture of the
errors and messages generated by the trigger.
Once you've done that, you can then move on to rewriting your trigger to
make it much more efficient and avoid the problem altogether. There is
absolutely NO reason to create "temporary" permanent tables and load them
with the contents of the inserted and deleted tables - and then delete these
same tables at the end of the trigger.
Replace statements that use your "temporary" permanent tables with the
appropriate virtual tables
UPDATE tblItemRelationship
SET ChildItemID = I.ItemID
FROM tblItemRelationship AS IR
JOIN mdsystmpDeleted AS D ON IR.ChildItemID = D.ItemID
JOIN mdsystmpInserted AS I ON D.ItemRecordID = I.ItemRecordID
becomes
UPDATE tblItemRelationship
SET ChildItemID = I.ItemID
FROM deleted AS D
JOIN inserted AS I ON D.ItemRecordID = I.ItemRecordID
WHERE tblItemRelationship.ChildItemID = D.ItemID
IMHO, you should also re-evaluate the process that decided the modification
of ID values was appropriate and allowed. IDs are usually pseudo-keys and
have no meaning.
"pmcguire" <pmcguire@discussions.microsoft.com> wrote in message
news:241799EA-4ED0-4807-8748-7EAB04746942@microsoft.com...
> Hi Hugo,
>
> Thanks for the response. I guess I should also say that I'm not
experiencing this problem in, say, EnterpriseManager, but rather in a VB.NET
app that I've written. The specific error I'm getting might be somehow
misleading, but it SEEMS to indicate that mdsystmpDeleted doesn't exist (the
SQLError message is something like "invalid table name 'mdsystmpDeleted'.").
However I CAN succesfully create a table (regardless of WHO I'm logged in
as) by placing a line in the trigger before the SELECT that creates
mdsystmpDeleted that says : SELECT ItemID INTO tmpTest FROM tblItem (ItemID
is a valid column in tblItem, a valid table in the database); so it doesn't
SEEM to be a problem of not having create privileges.
>
> Thanks
>
> --
> Pat
>
>
> "Hugo Kornelis" wrote:
>
> > On Tue, 27 Jul 2004 14:30:02 -0700, pmcguire wrote:
> >
> > > SELECT ItemID,ItemRecordID INTO mdsystmpDeleted FROM deleted
> >
> > Hi Pat,
> >
> > Though you didn't provide the error message, I bet the above line is
where
> > it's raised. And the error is not caused by referencing the deleted
> > pseudotable, but by attempting to create the mdsystmpDeleted table.
System
> > Administrator has create table priviledge by default, mere mortals
don't.
> >
> > Best, Hugo
> > --
> >
> > (Remove _NO_ and _SPAM_ to get my e-mail address)
> >
- Next message: Andrew J. Kelly: "Re: Object creation not appearing in consequent log backup"
- Previous message: kurt sune: "Implementing Circular Consistency"
- In reply to: pmcguire: "Re: using a trigger to enforce referential integrity"
- Next in thread: pmcguire: "Re: using a trigger to enforce referential integrity"
- Reply: pmcguire: "Re: using a trigger to enforce referential integrity"
- Reply: Hugo Kornelis: "Re: using a trigger to enforce referential integrity"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|