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

  • I am trying to find anywhere how to link fields together to match the index. These indexes range in size from 1 to 12 columns. I tried the + thing on the columns but that doesn't work correctly. f1(int)+f4(char(5)+f5(smallint).

    Is there a way to match up on more than 1 column.

    Do I have to match up on columns or is there a way to use the index names. 'where index1 not in (select index1 from table1)' ??

    DDL

    Table1 Table2

    f1 int, f1 int,

    f2 int, f3 char(50),

    f3 char(50), f4 char(125),

    f4 char(125), f5 int,

    f5 int, f7 int,

    f6 decimal(12,5), f8 char(25),

    f7 int, f9 tinyint,

    f8 char(25), f10 int,

    f9 tinyint, f11 int,

    f10 int, f12 decimal(15,8),

    Identity int; Identity int;

    index1 clustered unique (f1, f3, f10); Index1 clustered unique (f1, f3, f10);

    now Table1 has 100,000 rows that I need to INSERT the matching fields into Table2.

    So the other dept. creates Table2 and they add 1-???? rows of data into it. Some of them have the same data information that is in Table1. So when I issued the INSERT command with all the fields defined then it threw an exception (no duplicates) and didn't insert any of the data in Table1 over to Table2.

    They don't want to update the data in Table2, only insert the data from Table1. Duplicates be skipped/ignored.