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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:33:41+00:00 2026-06-09T04:33:41+00:00

What I try to accomplish is that I want to update rows in tableA

  • 0

What I try to accomplish is that I want to update rows in tableA when one row from tableB gets deleted.

The layout of tableA is this:

+----------------------------+--------------+------+-----+---------------------+----------------+
| Field                      | Type         | Null | Key | Default             | Extra          |
+----------------------------+--------------+------+-----+---------------------+----------------+
| user_id                    | int(11)      | NO   | PRI | NULL                | auto_increment |
| nickname                   | varchar(32)  | NO   |     | NULL                |                |
| password                   | varchar(129) | NO   |     | NULL                |                |
| mafia_id                   | int(11)      | NO   |     | 0                   |                |
+----------------------------+--------------+------+-----+---------------------+----------------+

and of tableB this:

+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| mafia_id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| mafia_name  | varchar(32) | NO   |     |         |                |
| mafia_tag   | varchar(5)  | NO   |     |         |                |
| mafia_color | int(11)     | NO   |     | 0       |                |
| mafia_car   | int(11)     | NO   |     | 0       |                |
| mafia_base  | int(11)     | NO   |     | 0       |                |
+-------------+-------------+------+-----+---------+----------------+

I want to set all tableA.mafia_id to 0 when the corresponding mafia_id in tableB is deleted.

I read in the documentation that the database will automaticly do it for you, but you have to specify some stuff at table creation (in CREATE TABLE, create_definition: | CHECK (expr)?). The documentation is a bit unclear to me.

I also read this topic:
Create a trigger that updates a column on one table when a column in another table is updated

but this doesn’t apply to me, i think?

So how would I create such a table (create table …) or delete row statement?
Thanks in advance!

  • 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-09T04:33:42+00:00Added an answer on June 9, 2026 at 4:33 am

    Since you are using InnoDB, you can achieve this with a foreign key constraint:

    ALTER TABLE tableA
      MODIFY mafia_id INT(11) NULL,
      ADD FOREIGN KEY (mafia_id) REFERENCES tableB (mafia_id) ON DELETE SET NULL
    

    As explained in the manual:

    • SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.

      If you specify a SET NULL action, make sure that you have not declared the columns in the child table as NOT NULL.

    Note that the constraint has the additional advantage of ensuring that mafia_id values in tableA must always reference an existing record in tableB.

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

Sidebar

Related Questions

What I try to accomplish is that I want to select one row from
Here is the code that shows what I try to accomplish. public partial class
In ASP.NET Web Forms,i would accomplish that easily: [...] try { DateTime date =
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
I am stucked with an idea I want to implement into one of my
I'm building an ASP.NET MVC site where I want one of the Views I
I know that all arrays in .net are limited to 2 GB, under this
I have this: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView debugView = (TextView)findViewById(R.id.debugView);

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.