Remove orphan PK

  • Hi!

    I'm having problems with MS SQL Server Express 2008. I use ASP.Net Enterprise Manager to manage my database, now I'm trying to add one field to one table (sales) and I get this error:

    Error: There is already an object named 'PK_sales_Temp' in the database. Could not create constraint. See previous errors.

    Source: .Net SqlClient Data Provider

    I think ASP.Net Enterprise Manager uses 'sales_Temp' as a temp table to perform the update. However if I add the fields using SQL commands (alter table...) it works fine.

    Seems there is an orphan PK:

    SELECT * FROM sys.objects WHERE name='PK_SALES_TEMP'

    nameobject_idprincipal_idschema_idparent_object_idtypetype_desccreate_datemodify_dateis_ms_shippedis_publishedis_schema_published

    PK_sales_Temp 165575628 5 149575571 PK PRIMARY_KEY_CONSTRAINT 20/03/2010 0:07:42 20/03/2010 0:07:42 False False False

    How could I fix that?

    Best regards

  • You need to figure out what table this primary key belongs to.

    Run

    SELECT * FROM sys.objects where object_id=149575571

    to check what table that PK belongs to. It does not have to belong to the table you try to alter.

    Also, please post the sql code .NET generates together with the field you'd like to add.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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