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 7983571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:59:55+00:00 2026-06-04T10:59:55+00:00

Morning, I have three tables: Table: debtors id – INT(11) type – ENUM(‘c’, ‘p’)

  • 0

Morning,

I have three tables:

Table: debtors

id           -    INT(11)
type         -    ENUM('c', 'p')

Table: companies

id           -    INT(11)
debtor_id    -    INT(11)
and a lot of other fields for companies

Table: private_individuals

id           -    INT(11)
debtor_id    -    INT(11)
and a lot of other fields for private individuals

Foreign KEY SQL for companies(same is used for private individuals):

INDEX `fk_private_individual_debtors1` (`debtor_id` ASC) ,
  CONSTRAINT `fk_private_individual_debtors1`
    FOREIGN KEY (`debtor_id` )
    REFERENCES `application_user`.`debtors` (`id` )
    ON DELETE CASCADE
    ON UPDATE NO ACTION)

When I delete a company or private individual I want the debtor to be deleted as well and it should work the other way around aswell(delete a debtor and the company or private individual is deleted aswell).

I’m thinking to do this with a trigger but I suppose there is a better way to do it..

Can anyone help please?

  • 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-04T10:59:57+00:00Added an answer on June 4, 2026 at 10:59 am

    Delete a debtor and the company or private individual is deleted as
    well:

    This can be done by ON DELETE CASCADE. You specify this when you define the foreign key, and applies to all deletes on the table. You cannot mention this at the indivudual DELETE level. See FOREIGN KEY Constraints in the MySql manual
    Remember this is dangerous in most cases and you are better off having this logic in your application code.

    When I delete a company or private individual I want the debtor to be
    deleted as well

    This is not directly possible. You have built a foreign key relationship between a company and a debtor but there can be more than one company associated to the debtor. There is nothing in the foreign key that prevents this. You may have additional application logic (in a procedure, in your java/C# code, in triggers) but there is nothing in the foreign key level at all.
    So since this is acheived by additional application logic your deletion also will need additional application logic.
    One another point to note is: you should delete a [arent only if all of its child records are deleted.

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

Sidebar

Related Questions

This is probably very easy, but it's Monday morning. I have two tables: Table1:
I have this table: create table demo ( key number(10) not null, type varchar2(3)
Morning folks, I have a temporary table with 135,000 rows and 24 columns, of
I have a folder /Tables that contain all the table objects scripts. Some of
Good morning, folks. I have a question here. I have three select. Brings first
I have a MySQL table with the following fields: id, morning, evening, event, other-fields
I have an interview tomorrow morning and just found out that I will also
I have an application that I restart at 2 am every morning using Application.Restart();
I have made some progress with the DataList and UserControl this morning but I
Morning stackoverflow, I have a repeater, with the following code in my aspx page;

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.