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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:50:23+00:00 2026-06-17T15:50:23+00:00

I have designed my database structure, like below to support the creation of multiple

  • 0

I have designed my database structure, like below to support the creation of multiple shops and users assigned to those shops. My tables use InnoDB storage engine.

[user]  
user_id 

[user_profile]  
user_profile_id  
user_id

[user_to_shop] PIVOT 
user_id  
shop_id

[shop]  
shop_id

[shop_profile]  
shop_profile_id  
shop_id  

[category_to_shop] PIVOT  
category_id  
shop_id

[category]  
category_id

[category_description]  
category_description_id  
category_id 

[product_to_category] PIVOT  
product_id
category_id

[product_to_shop] PIVOT
product_id
shop_id

[product]
product_id

...  
...

What I want to achieve is to delete all related records(category records, shop records, …, …) when a user(user_id) is deleted.

I have created constraints per entity. So when I remove a user_id(1), engine takes care of removing user_profile(user_id(1)) also.

ALTER TABLE `user_profile`
ADD CONSTRAINT `user_profile_cs1`
FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`)
ON DELETE CASCADE

But what should I do with pivot tables? How should I declare constraints or foreign keys on those tables to get the job done and be safe?

  • 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-17T15:50:24+00:00Added an answer on June 17, 2026 at 3:50 pm

    Create a chain of deletion: Add FK constraints to the pivot tables ([C]) or [D] that depends on C, below)

    [A]
    idA
    dataA
    
    [B]
    idB
    dataB
    
    [C]
    idC
    idA
    FOREIGN KEY (idA) REFERENCES A(idA)
    ON DELETE CASCADE
    idB
    FOREIGN KEY (idB) REFERENCES B(idB)
    ON DELETE CASCADE
    
    [D]
    idD
    idC
    FOREIGN KEY (idC) REFERENCES C(idC)
    ON DELETE CASCADE
    

    Order of operations

    Delete(A) -> Delete(C) -> Delete(D)
    Delete(B) -> Delete(C) -> Delete(D)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed database tables (normalised, on an MS SQL server) and created a
I have an app which uses core data, the database structure was designed through
Due to previously poorly designed structure, the current database that I have to work
I have designed a database whose MDF file will be copied to remote offices,
I am creating a database based on a ERD i have designed according to
I am planning to build a database for a school application. I have designed
I have a SQLite DB designed using SQLite Database Browser 2.0 b1 I have
I have rewritten an old program and designed a new database for it. I
My problem is that the database fields have been badly designed by previous people
I've designed a database structure where data is collected about cars over a period

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.