SQL Server : duplicating a table with data results in constrain violation, how?

0

I am trying to duplicate a SQL Server database to a new server.

I scripted the table creates and then used the Import/Export to transfer data from one database to another.

This worked fine for all but two tables which threw errors for primary key violations!!!

So, I'm trying to figure our how that happens. I used the SQL Server Management Studio to script the tables in both the source and target databases to ensure they are identical which, no surprise, they are. Both tables have an identity column so I made sure to tick the check boxes for "Delete rows in destination table" as well as "Enable Identity Insert". The second of course to ensure relational integrity with the other ported data.

So how does this happen? Here are the two table creates and errors just to give you the details but regardless of the details of the table I don't understand how the data can exist in version of the table and cause a constraint violation in the other.

Can anyone give me an alternative way to export/import the table structure and data to get the two tables over from one DB to the other??

CREATE TABLE [dbo].[PageHeader](
    [PageHeaderID] [int] IDENTITY(1,1) NOT NULL,
    [SiteKey] [smallint] NOT NULL,
    [Page] [varchar](250) NOT NULL,
    [TitleTag] [varchar](250) NULL,
    [DescriptionTag] [varchar](250) NULL,
    [Keywords] [varchar](250) NULL,
    [ContentGroup] [varchar](50) NULL,
    [LastModified] [smalldatetime] NULL,
    [LastChecked] [smalldatetime] NULL,
 CONSTRAINT [PageHeader_key0] PRIMARY KEY CLUSTERED 
(
    [PageHeaderID] 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

- Copying to [dbo].[PageHeader] (Error)
Messages

Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Cannot insert duplicate key row in object 'dbo.PageHeader' with unique index 'PageHeader_key1'. The duplicate key value is (1, search.aspx?Q=Franck M).".
(SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. > The "Destination - PageHeader.Inputs[Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "Destination - PageHeader.Inputs[Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination - PageHeader" (43) failed with error code 0xC0209029 while processing input "Destination Input" (56). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

CREATE TABLE [dbo].[Keywords](
    [KeywordID] [int] IDENTITY(1,1) NOT NULL,
    [SiteKey] [smallint] NOT NULL,
    [SearchEngine] [varchar](50) NOT NULL,      
    [Keywords] [varchar](150) NOT NULL,
 CONSTRAINT [Keywords_key0] PRIMARY KEY CLUSTERED 
(
    [KeywordID] 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

- Copying to [dbo].[Keywords] (Error)
Messages

Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Cannot insert duplicate key row in object 'dbo.Keywords' with unique index 'Keywords_key1'. The duplicate key value is (1, Google.co.jp, ????????? 200/mab137r).".
(SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Destination - Keywords.Inputs[Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "Destination - Keywords.Inputs[Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination - Keywords" (28) failed with error code 0xC0209029 while processing input "Destination Input" (41). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
(SQL Server Import and Export Wizard)

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - Keywords returned error code 0xC02020C4. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

sql-server
duplicates
constraints
primary-key
unique-constraint
asked on Stack Overflow Feb 3, 2014 by Jason Leidigh • edited Dec 19, 2017 by Machavity

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0