Link to home
Start Free TrialLog in
Avatar of frosty1
frosty1

asked on

Cannot insert duplicate key row

I'm getting the following error when you batch import on SubSonic. Though this seems like an SQL error. The odd thing is, i don't believe i had an index called "IX_Guid"

{"Cannot insert duplicate key row in object 'dbo.Clips' with unique index 'IX_Guid'.\r\nThe statement has been terminated."}

Here is my table, not column "Guid" is actually of type "varchar"


/****** Object:  Table [dbo].[Clips]    Script Date: 03/31/2010 12:06:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Clips](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Author] [varchar](100) NULL,
      [Title] [varchar](100) NULL,
      [Thumbnail] [varchar](150) NULL,
      [FLVLow] [varchar](150) NULL,
      [FLVHigh] [varchar](150) NULL,
      [Updated] [datetime] NULL,
      [Published] [datetime] NULL,
      [Dimension] [varchar](50) NULL,
      [FeedId] [int] NOT NULL,
      [Imported] [bit] NOT NULL,
      [Guid] [varchar](100) NULL,
      [DateImported] [datetime] NULL,
 CONSTRAINT [PK_Clip] PRIMARY KEY CLUSTERED
(
      [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Clips] ADD  CONSTRAINT [DF_Clip_FeedId]  DEFAULT ((0)) FOR [FeedId]
GO

ALTER TABLE [dbo].[Clips] ADD  CONSTRAINT [DF_Clip_Imported]  DEFAULT ((0)) FOR [Imported]
GO
Avatar of frosty1
frosty1

ASKER

oh wait, i've found the index. Just removed it

USE [film24]
GO

/****** Object:  Index [IX_Guid]    Script Date: 03/31/2010 12:09:58 ******/
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Clips]') AND name = N'IX_Guid')
DROP INDEX [IX_Guid] ON [dbo].[Clips] WITH ( ONLINE = OFF )
GO

ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
frosty1,
I have to agree withacperkins on thuis one.  I think your problem had more to do with the data than with the table.  If you are importing data that has a GUID in it, that is usually a sign that the data is intended to be unique not only within the original database but also across databases.  That you have now done is to allow potentially duplicate data to be imported.
Perhaps a better approach would have been to import the data into a staging table that had an IDENTITY (INT 1-1) column as its PK and then to determine which rows had the same GUID value.  That would let you compare them to each other and determine whether you did, in fact, receive duplicate data.  You could then select distinct rows for inserting into the target table.
Of course, it may be that the GUID's are FK's referring to some other table that has the GUID as a Unique Index.