key is not unique

  • Hey

    I just got this error when I was trying to look at one of mine tables.

    The table contains more than 1 000 000 posts, this is not correct and I expect this is becuase I have some duplicate keys in the table.

    Wwhat is the most effective way to find duplicate keys?

    regards

    DJ

  • This will tell you the values of the key that are duplicated, and how many times they occur.  From there you can select * ...where MyKey = 'value here' to see the duplicated rows.

    select MyKey, count(MyKey)

     from MyTable

     group by MyKey

     having count(MyKey) > 1

     

    Steve

  • Please avoid multiple threads on the same topic in different categories. This makes it hard to track who answered already what in which thread.

    Keep this thread alive:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=9&messageid=148045

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply