Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:08:12+00:00 2026-06-13T23:08:12+00:00

I have a table which we can call decks. Decks has an id used

  • 0

I have a table which we can call decks. Decks has an id used as its primary key along with some other attributes. The cards table contains a foreign key reference to the deck id and has a primary key of cardid as well. Another table exists called answers where its foreign key is the cardid.

So in order to delete from decks, the database requires I delete from answers first, then cards, and then finally from decks.

I would like to create a trigger which takes care of the first and second delete so that I only have to specify a delete statement from the decks table to completely destroy a deck.

Below is an example PostgreSQL trigger I’ve found, but I am not sure if its even possible to do what I am asking as I can find no examples online of anyone creating a trigger this way.

CREATE OR REPLACE FUNCTION autoCalculate() RETURNS TRIGGER AS $$
        BEGIN

        IF NEW.wins < 0 THEN
                RAISE EXCEPTION 'Wins cannot be negative';
        END IF;

        IF(OLD.wins <> NEW.wins_ OR (OLD.losses <> NEW.losses) THEN
                NEW.Winning_Percentage := calc_winning_percentage(NEW.Wins, NEW.Losses);
        END IF

        RETURN NEW;
        END;
$$ LANGUAGE plpgsql;

DROP TRIGGER update_winning_percentage ON standings;
CREATE TRIGGER update_winning_percentage BEFORE INSERT OR UPDATE ON standings
FOR EACH ROW EXECUTE PROCEDURE autoCalculate();

If anyone has knowledge to do this, if they could nudge me in the right direction or provide an example of how to do this I’d be grateful!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:08:13+00:00Added an answer on June 13, 2026 at 11:08 pm

    On your foreign key definitions use ON DELETE CASCADE and it will take care of this for you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a table which has an id (primary key with auto increment),
I have problem with creating constructor, which Jenkins can call for some JSON data
I have the Demo Table which I can click on the cell(td tag) and
I have a table which defines what things another table can have, for example:
I have a table which contains my ads that can be searched in sql-server-2008.
I have a table which holds a list of criminal charges.These charges can be
I have this table, which can be seen as a basic custom gantt chart:
I need a query which can do the following operation. I have a table
In Oracle, I have a table with a column (X) which can have strings
I have a payment_types table in which you can enter different payment types such

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.