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

  • Home
  • SEARCH
  • 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 5841375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:52:57+00:00 2026-05-22T11:52:57+00:00

I have inherited a database that has a table (300gb) full of SQL datatype

  • 0

I have inherited a database that has a table (300gb) full of SQL datatype Image. I understand this datatype is depreciated.

As a routine cleanup I want to delete all duplicate Image‘s from the table where certain conditions are met.

How do I compare binary data using SQL efficiently? Is the = equality operator sufficient?

Here is a scenario:

Table 'Paperwork'
  int ID
  int EmployeeID
  int AnotherID
  int AnotherFKID
  image Attachment

I want to find all rows where the Attachment, EmployeeID, AnotherID and AnotherFKID are the same. It needs to be done with minimal impact on the database as there are over 1,116,313 rows.

Edit

The SQL Server Image data type does not support LIKE or the usual comparison operators.

Edit

Thanks to @Martin who suggested the Image be casted to varbinary. I have added to this to get the MD5 checksum using Hashbytes

HASHBYTES('MD5',CAST(cast([Attachment] as varbinary(max))as varbinary)) AS AttachmentMD5

  • 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-22T11:52:57+00:00Added an answer on May 22, 2026 at 11:52 am

    Jeremy,

    Any all in one script will kill the buffer cache when it reads in the 300g. Break the job down into several tasks.

    Task 1

    • create a table with the ID and a grouping to show duplicates of the three int columns

    Table example

        TableID  PaperWorkID GroupID
           1        14          1
           2        15          1
           3        21          2
           4        55          2
    

    Now we know PaperWorkIDs 14 and 15 share the same the three int columns because they are in the same group.

    Task 2

    • add a column (bigint) to the table and populate the column with the DATALENGTH of the Image column in table Paperwork based on the PaperWorkID in the table
    • remove all non duplicates based on the datalength and GroupID

    Task 3

    • Add a column varbinary(max) to the table.
    • fill the column with the MD5 hash of the image column based on the PaperWorkID in the table
    • Remove all non duplicates from the table based on the MD5 hash and the GroupID

    Task 4

    • make 2 backups of the PaperWork table
    • remove duplicate records in Paperwork based on the items remaining in the table.

    If the data for the image column was scanned from paper there is very little chance two scans will produce the exact same image. If the data was uploaded twice then you are in luck.

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

Sidebar

Related Questions

I inherited a mysql database that has a table with columns like this: object_id,
I inherited MYSQL database that has lots of tables with data like CREATE TABLE
I've inherited a database that has a structure with a table of products, a
I have inherited a very old database that needs some data to be updated.
I have inherited a SQL Server 2008 database to which calling applications have access
I have inherited a terribly written MS Access database that I need to import
So I have this application in ASP MVC 3. My database has two tables:
I have inherited a VB6/Access application that we have developed and sold for many
I have inherited a poorly written web application that seems to have errors when
I have inherited a project that uses LLBLGen Pro for the DB layer. 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.