It's a bit complex.
I have two tables. "Books" and "Book_Authors" (which links between
book_id and author_id).
Book_authors has a foreign key on book_id to the Books table. On key
violation it is set to delete the rows (if a book is deleted, it
should't be linked to any authors).
In Book_Authors I also have a trigger on DELETE. When a book is
unlinked from an author, then the author vote_count should be reduced
(as the author vote_count is the sum of all votes of his books).
The problem is that when a book is deleted and then the trigger tried
to get the number of it votes, it returns NULL, as the book is already
gone and so its data. If it was a simple matter of triggers I could
play with BEFORE/AFTER, but since it is constraints issue, it seems to
be all happening AFTER the deletion.
On Sun, 19 Dec 2004 12:23:09 -0700, Michael Fuhr <mike@fuhr.org> wrote:
> On Sun, Dec 19, 2004 at 03:20:19PM +0200, Vitaly Belman wrote:
>
> > I noticed that when you do a constraint and tell it "cascade on
> > delete", it will do so only AFTER that the source is deleted. Can I
> > tell it somehow to cascade BEFORE the source is gone?
>
> What problem are you trying to solve?
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>
--
ICQ: 1912453
AIM: VitalyB1984
MSN: tmdagent@hotmail.com
Yahoo!: VitalyBe