Corruption? Wrong primary keys scripted

  • Hi people,

    I'm getting a problem scripting using SQL Management Studio for SQL 2005. I'm trying to copy table and using the generate scripts feature. However, the script generated includes a primary key that does not exist! Example:

    CREATE

    TABLE [dbo].[Targeting](

    [TargetingId] [int] IDENTITY(1,1) NOT NULL,

    [Name] [nvarchar](100) NULL,

    [Type] [tinyint] NULL,

    CONSTRAINT [PK_CampaignExp] PRIMARY KEY CLUSTERED

    (

    [TargetingId] ASC

    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    ) ON [PRIMARY]

    In the above, I get PK_CampaignExp which doesn't exist in any of my tables, or is not a table. It used to be a table that I deleted ages ago. Do I have some corruption somewhere?

    Thanks

    Gerard

  • have you been renaming objects ?

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]
    www.grumpyolddba.co.uk
    http://sqlblogcasts.com/blogs/grumpyolddba/

  • I have renamed /and/or deleted objects in the past. I'm developing the database as I go and as things develop, things are either renamed/added or deleted. Currently there are around 60 tables and 300 odd stored procedures. I am just adding a bunch of new tables where this problem has occured.

  • renaming objects can create all sorts of problems, like you're seeing, I'd really suggest that to be safe you drop and recreate  ( with a copy for data ) rather than rename.

     

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]
    www.grumpyolddba.co.uk
    http://sqlblogcasts.com/blogs/grumpyolddba/

  • Thanks Colin. If I want to create a copy of the datase for a different application, can you tell me the best way to create a new duplicate without carrying over any corruption found in the old database - and of course how best to copy generic data across?

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

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