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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:49:57+00:00 2026-06-18T15:49:57+00:00

In SQL Server 2008 R2 I added two duplicate ID and record in my

  • 0

In SQL Server 2008 R2 I added two duplicate ID and record in my table. When I try to delete one of the last two records I receive the following error.

The row values updated or deleted either do not make the row unique or they alter multiple rows.

The data is:

7   ABC         6
7   ABC         6
7   ABC         6
8   XYZ         1
8   XYZ         1
8   XYZ         4
7   ABC         6
7   ABC         6

I need to delete last two records:

7   ABC         6
7   ABC         6

I have been trying to delete last 2 record using the feature “Edit the Top 200 rows” to delete this duplicate id but get the error above.

Any help is appreciated. Thanks in advance:)

  • 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-18T15:49:58+00:00Added an answer on June 18, 2026 at 3:49 pm

    This is an outline of code I use to delete dups in tables that may have many dups.

    /* I always put the rollback and commit up here in comments until I am sure I have 
       done what I wanted. */
    BEGIN tran Jim1 -- rollback tran Jim1 -- Commit tran Jim1; DROP table PnLTest.dbo.What_Jim_Deleted
    
    /* This creates a table to put the deleted rows in just in case I'm really screwed up */
    SELECT top 1 *, NULL dupflag 
      INTO jt1.dbo.What_Jim_Deleted --DROP TABLE jt1.dbo.What_Jim_Deleted
      FROM jt1.dbo.tab1;
    /* This removes the row without removing the table */
    TRUNCATE TABLE jt1.dbo.What_Jim_Deleted;
    
    /* the cte assigns a row number to each unique security for each day, dups will have a
       rownumber > 1.  The fields in the partition by are from the composite key for the 
       table (if one exists.  These are the queries that I ran to show them as dups
    
    SELECT compkey1, compkey2, compkey3, compkey4, COUNT(*) 
      FROM jt1.dbo.tab1
      GROUP BY compkey1, compkey2, compkey3, compkey4
      HAVING COUNT(*) > 1
      ORDER BY 1 DESC
    
    
    */
    with getthedups as
      (SELECT *,
           ROW_NUMBER() OVER 
             (partition by compkey1,compkey2, compkey3, compkey4 
                              ORDER BY Timestamp desc) dupflag /*This can be anything that gives some order to the rows (even if order doesn't matter) */
         FROM jt1.dbo.tab1)
    /* This delete is deleting from the cte which cascades to the underlying table 
       The Where is part of the Delete (even though it comes after the OUTPUT.  The
       OUTPUT takes all of the DELETED row and inserts them into the "oh shit" table,
       just in case.*/
    DELETE 
      FROM getthedups 
      OUTPUT DELETED.* INTO jti.dbo.What_Jim_Deleted
      WHERE dupflag > 1
    
    --Check the resulting tables here to ensure that you did what you think you did
    
    /* If all has gone well then commit the tran and drop the "oh shit" table, or let it 
       hang around for a while. */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table (SQL Server 2008) has 1 million+ records, when I try to order
In SQL Server 2008 I have a user table like the following: Userid Username
I have a SQL Server 2008 database with two tables. The first table is
I have a SQL Server 2008 R2 database table with 12k address records where
I have added an index for a table in sql server 2008. I would
I have the following situation. There is one central SQL Server (2008 R2, Standard
I have an SQL Server 2008 Express Edition and added an Oracle DB as
In SQL Server 2008 Management Studio, when I right click on a database table
I have a table in SQL Server 2008 that stores XML data in an
In a SQL Server 2008 database I have a table with a Date field

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.