Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Argentina
    Posts
    26

    Unanswered: Don't Insert duplicate rows

    Hi, I need to insert rows into table1 from table2 and table3 but I don't want to insert repeated combinations of col2, col3. So, table1 has the primary key col2, col3.

    This the table1:

    create table table1(
    col1 int not null,
    col2 int not null,
    col3 int not null,
    constraint PK_table1 primary key (col2, col3)
    )

    This is my "insert" code:

    INSERT INTO table1
    SELECT table2.col1,table2.col2, table3.col3
    FROM table2, table3
    WHERE table2.col1 = table3.col1

    Wich conditions shoud i add to this code?

    Thanks.

    fmilano.

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    If Col2 and Col3 is controlled by Primary key then it will be taken care and if any data is added will be errored.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

  3. #3
    Join Date
    Feb 2004
    Location
    Argentina
    Posts
    26
    To be erroed is what I want to avoid. So, I want to filter this rows by columns col2 and col3.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •