Cannot add a primary key

  • Run the following to see if it returns anything. If it does, you have an index by that name! I'm assuming SQL2K. Let us know what you see.

    select * from sysindexes where name = 'PK_MyTableName'

    -- You can't be late until you show up.

  • PK_MyTableName is probably the primary key for MyTableNameorig. Renaming a table doesn't rename it's indexes and constraints.

    Greg

  • Aha! I didn't realize that indexes and assignment of primary keys would not change along with table names. This is, uh, somewhat counter-intuitive.

    I took the path of least resistance, since I was still experimenting:

    I deleted all the tables I had created that day, and then recreated the table with the final structure that I wanted. The problem went away!

    Thank you! I'll know not to fall into *that* trap again...;)

  • Yes, it would have been nice if SQL Server had dependent objects use dependent Namespaces, but that never happened.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 4 posts - 1 through 5 (of 5 total)

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