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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:07:34+00:00 2026-05-12T19:07:34+00:00

I just found a bug in my Rails app which would lead to certain

  • 0

I just found a bug in my Rails app which would lead to certain records not getting deleted with their associated objects. The bug has been fixed, but I now have several thousand records in my database with foreign key values pointing to records that don’t exist.

Is it possible to delete all records in a table where an integer foreign key references a record in another table that doesn’t exist in SQL? How?

  • 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-05-12T19:07:35+00:00Added an answer on May 12, 2026 at 7:07 pm
    delete from child_table where not exists 
       (select 1 from parent_table where parent_table.id=child_table.related_id)
    

    the next step is of course to create a FOREIGN KEY constraint immediately (unless you’re on MySQL MyISAM in which case you’re out of luck on that).

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

Sidebar

Related Questions

I just found a bug in some number manipulations in my program and I'm
I think I've found a bug in IE's (IE8) handling for the for-in javascript
Greetings StackOverflowians, As discovered here , Windows 7 features a bug in which the
I'm using Castle ActiveRecord which uses NHibernate underneath and I've added a property with
I'm using jQuery to parse XML which is retrieved via ajax, however I have
Update : I've found a workaround. If I submit a dummy form field along
I face a very annoying bug in D2007 IDE : It's the second time
I am using the Nov version of the AjaxControlToolkit, and I found a logic
This is the calendar script I got from an online tutorial. It works fine
I'm using GD to generate images on the fly for title images on the

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.