Home Forums SQL Server 2005 T-SQL (SS2K5) INSERT avoiding duplicate error on multi-column unique index RE: INSERT avoiding duplicate error on multi-column unique index

  • This does not seem be a difficult problem. But as was mentioned, a lack of DDL for the tables and Indexes makes this very difficult to understand. This is an example of what your DDL for your tables and all the indexes should look like:

    CREATE TABLE Table1

    (

    [RIN] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,

    [Year] [int] NOT NULL,

    [TRMasterRIN] [int] NOT NULL,

    [TRValueRIN] [int] NOT NULL,

    [AttributeRIN] [int] NOT NULL,

    [QualityRIN] [int] NOT NULL,

    [VisualRIN] [int] NOT NULL,

    [ErrStringRIN] [int] NOT NULL,

    [Sequence] [int] NOT NULL,

    [Amount] [int] NOT NULL,

    [MDateTime] [datetime] NOT NULL,

    [MUser] [varchar](128) NOT NULL,

    CONSTRAINT [APL_RINX] PRIMARY KEY CLUSTERED

    (

    [RIN] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    CREATE NONCLUSTERED INDEX [TBL1_TRMasterNdx] ON [dbo].[Table1]

    (

    [Year] DESC,

    [TRMasterRIN] ASC,

    [TRValueRIN] ASC,

    [Sequence] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    Add some Insert statements for your tables and boom! Answers will show up!

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/