Results 1 to 3 of 3

Thread: Is there any T-SQL to search for duplicates ? (*** SOLVED ***)

  1. #1

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Unhappy Is there any T-SQL to search for duplicates ? (*** SOLVED ***)

    Hi...

    Let's say like this... I have an old database in .DBF format. I transfer the database to SQL Server using DTS. Result of DTS is the table(s) from .DBF with no Primary Key.

    When I need to set up the PK (primary key), SQL returns error, and said something likes "Duplicate key found for record .... and ..."

    My question is :
    before I setup the PK, can I find which record has its duplicate(s) by using T-SQL at Query Analyzer ???

    FYI : I'm using SQL Server 2K
    Last edited by Wen Lie; Jun 13th, 2004 at 10:42 PM.
    Regards,
    [-w-]

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Lets say the table your are checking is called THETABLE and the column you are interested in seeing if it has dups is called THECOLUMN

    Code:
    SELECT THECOLUMN,SUM(1) FROM THETABLE GROUP BY THECOLUMN HAVING SUM(1)>1

  3. #3

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    hmm...
    huh....

    that simple ? =p~
    wew... i try to create my own T-SQL, so complicated, nd not workin' at all ;p

    hahaha.... lolz
    thanks a lot szlamany for the T-SQL... it works.
    Regards,
    [-w-]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width