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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:15:31+00:00 2026-06-17T13:15:31+00:00

I am using SQL Server Management Studio 2012. I have a table with thousands

  • 0

I am using SQL Server Management Studio 2012. I have a table with thousands of rows of data in it. Many of the rows are duplicates, and I need to remove them. Each row has a unique identifier [OwnerID] which is set to Identity Specification with an Identity Increment of 1. For each row, the duplicates lie in these columns: [FirstName], [LastName], and [CompanyName].

So I need to delete rows with duplicate combinations of values in these 3 columns. After the deletion, is there t-sql I can write to reset the Identity Specification in
[OwnerID] to start at 1 for the first row and assign values to the rest of the rows in increments of 1?

Thanks for any assistance.

  • 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-17T13:15:32+00:00Added an answer on June 17, 2026 at 1:15 pm

    Here is my try using the temporary tables SQL Fiddle:

    SELECT 
    firstName, LastName, CompanyName, COUNT(*) thecount, MIN(ID) min_id
    INTO #temp
    FROM tab
    GROUP BY firstName, LastName, CompanyName;
    
    SELECT 
    a.id ID, b.min_id
    INTO #temp1
    FROM tab a, #temp b
    WHERE  a.firstName  = b.FirstName 
    AND a.LastName    = b.LastName
    AND a.CompanyName = b.CompanyName
    AND b.thecount > 1;
    
    -- run this query on all referenced tables:
    UPDATE tab2 SET tab2.ID = t.min_id
    FROM tab2, #temp1 t
    WHERE tab2.ID = t.ID;
    
    DELETE t
    FROM tab t, #temp1 a
    WHERE t.id = a.id and a.id <> a.min_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm using SQL Server Management Studio 2008 and I have a query window
I have a problem when debugging stored procedure using SQL server Management Studio 2008.
I have been using SQL Server Management Studio for years. Yesterday, when I started
I'm trying to delete a couple of rows USING SQL Server management studio, for
Can I convert query syntax to uppercase using SQL Server Management Studio? I have
I need to generate SQL queries with all table records, using SQL Server Management
Using SQL Server Management Studio, I have backed up a database from one server
I am using SQL Server management studio. I have a column named salary. I
Question: when I create a table ( T_TableName ) using SQL Server Management-Studio, it
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; N00b here, I have a GridView, but I want to

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.