logo       

Need help creating a BEFORE DELETE trigger: msg#00353

Subject: Need help creating a BEFORE DELETE trigger
Hello everyone,

I'm creating two database tables that will be used to cache the results of a 
search.  Basically, when a search is initiated, an entry will be created in 
the "Search" table that represents the search, and a single entry will be 
created in a child table "SearchResults" for every result returned.  A 
foreign key relationship will be associated between the two.

CREATE TABLE Search
( id         SERIAL
, accountid  INTEGER REFERENCES account(id) ON DELETE CASCADE NOT NULL
, sessionnum CHAR(32) UNIQUE NOT NULL
, created    TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
, sqlcode    TEXT
);

CREATE TABLE SearchResults_Customer
( id            SERIAL
, searchid      INTEGER REFERENCES search(id) ON DELETE CASCADE NOT NULL
, customerid    INTEGER REFERENCES customer(id) ON DELETE CASCADE
-- All the results go in fields here
);

Now, when any record is deleted in the SearchResults table (via an ON DELETE 
CASCADE, or other trigger), I'd like the entire search set to be deleted 
since the search is now invalid.  Therefore, if a single record in the 
SearchResults table is deleted, I want it to instead delete the associated 
record in the Search table; this'll cause a CASCADE into the SearchResults 
table, toasting my entire result set.

The problem I'm looking at is: could this cause a recursion problem, where the 
cascading deletion will try to cause the whole thing to cascade again?  How 
can I set this up so I can kill an entire tree of data if any one of it's 
members dies?

Thanks in advance.

-- 
/* Michael A. Nachbaur <mike@xxxxxxxxxxxx>
 * http://nachbaur.com/pgpkey.asc
 */

"I don't know, " said the voice on the PA, "apathetic 
bloody planet, I've no sympathy at all. "


---------------------------(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



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe