[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 777
  • Last Modified:

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
0
frosty1
Asked:
frosty1
1 Solution
 
frosty1Author Commented:
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

0
 
Anthony PerkinsCommented:
>>i've found the index. Just removed it<<
I am not sure why you would want to do that.  The Index was not the problem, the real problem was the unique constraint, but whatever works for you...
0
 
8080_DiverCommented:
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.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now