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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:13:55+00:00 2026-06-05T12:13:55+00:00

I have a one to many relationship between two tables in mysql. One called

  • 0

I have a one to many relationship between two tables in mysql.

One called type with a primary of url

url
varchar(255)

And one called order with an index on url.

url          | id_no
varchar(255) | int

The order table can have many values in it and there is already a foreign key set up so that if a url is deleted in the table type it deletes all associated keys with a matching url in order.

Orders can also be deleted manually meaning that a url could exist in type that doesn’t have a relationship to the table order.

Is there a way to set up a foreign key so that if a url in type does not have a relationship to the table order then it will delete itself from type?

Looking at the mysql manual I cannot figure it out, I am confused by CASCADE as it says it will delete all associated keys, but I only want to delete a url from the table type if and only if there is no relationship between the two?

Thanks for your help!

  • 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-05T12:13:56+00:00Added an answer on June 5, 2026 at 12:13 pm

    You can easily do that with a DELETE trigger on the order table: Let it check, if there exist other rows with the same url, and if not delete it from type.

    Another way to do it is creating a maintenance script similar to

    DELETE FROM `type` WHERE url NOT IN (
      SELECT DISTINCT `url` FROM `order`
    )
    

    and run it on a regular or on-demand basis.

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

Sidebar

Related Questions

I have a one to many relationship between two tables. The many table contains
I have a question about One-To-Many relationship between two tables when there is the
Is there a way to map one-to-many relationship between two tables that have the
android noob... I have two tables, with a one to many relationship between country_tbl
I have a one-to-many relationship between two classes for this situation. I have a
If I have a relationship between two tables (both tables have their own primary
I have two tables in a one to many relationship. (products and qty break
I have two tables: invoices & invoice_items. I need a one to many relationship
I have a 1 to many relationship between two tables... say Organisation and Members
I have two tables: messages (messages users posted), likes (many to many relationship between

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.