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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:10:31+00:00 2026-05-16T08:10:31+00:00

I have several tables in a database. One table (tbl_transactions) has thousands of orphaned

  • 0

I have several tables in a database. One table (tbl_transactions) has thousands of orphaned records that are not linked to any of the remaining tables. I need to run a script that will delete these records in order to regain some lost space in my database. I tried to run a script that deleted all the records, but the log file consumed 20 GB of space, thus filling the HDD and the script did not complete. My script looks like this:

delete tbl_Transactions
where not exists (select * 
                    From tbl_SocketConnections
                   where tbl_Transactions.TransactionID = tbl_SocketConnections.TransactionID)
  And Not Exists(Select * 
                   From tbl_ProtocolCommands
                  where tbl_Transactions.TransactionID = tbl_ProtocolCommands.TransactionID)
  And Not Exists(Select * 
                   From tbl_EventRules
                  where tbl_Transactions.TransactionID = tbl_EventRules.TransactionID)

There are several other tables, but the pattern repeats. Can someone advise on how I can limit the scope of this script to say 1000 records at a time?

  • 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-16T08:10:32+00:00Added an answer on May 16, 2026 at 8:10 am

    SQL Server 2005+

    Change TOP to LIMIT covers mySQL too

    SELECT 'starting' --gives one row
    WHILE @@ROWCOUNT <> 0
        delete TOP (10000) tbl_Transactions
        where not exists (select * 
                            From tbl_SocketConnections
                           where tbl_Transactions.TransactionID = tbl_SocketConnections.TransactionID)
          And Not Exists(Select * 
                           From tbl_ProtocolCommands
                          where tbl_Transactions.TransactionID = tbl_ProtocolCommands.TransactionID)
          And Not Exists(Select * 
                           From tbl_EventRules
                          where tbl_Transactions.TransactionID = tbl_EventRules.TransactionID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database with several tables, each one containing columns that may not
I have a project that necessarily spans several databases. One database has tables: CREATE
I have a database where one table "Common" is referenced by several other tables.
I have a SQL Server Database with several tables. One of them has ID
I have several database tables that just contain a single column and very few
I have several tables: CREATE TABLE [dbo].[Tracks]( [Id] [uniqueidentifier] NOT NULL, [Artist_Id] [uniqueidentifier] NOT
Greetings, stack overflow In my database, I already have one table, 'contacts' that contains
I have a very large database with about 120 Million records in one table.I
I have a SQLite database, and several tables within that datbase. I am developing
I have a mysql database which have set of tables One table have a

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.