Inserting problem

  • I can able to add values in to table but the problem is i want to add distinct values to the table i.e the value should not be repeated ...

    BULK

    INSERT dummy2

    FROM 'c:\bulk.txt'

    WITH

    (

    FIELDTERMINATOR = '\t',

    ROWTERMINATOR = '\t'

    )

    gururajan.k

  • gururajan (11/10/2008)


    I can able to add values in to table but the problem is i want to add distinct values to the table i.e the value should not be repeated ...

    BULK

    INSERT dummy2

    FROM 'c:\bulk.txt'

    WITH

    (

    FIELDTERMINATOR = '\t',

    ROWTERMINATOR = '\t'

    )

    gururajan.k

    write an insert trigger that will check for the duplicate value in the table

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • I think doing the validation in the trigger and returning an error will cause the whole bulkinsert to fail. If this is the behaviour you want then its fine.

    Any chance of checking the data before doing bulk insert.

    "Keep Trying"

  • You shouldn't ever bulk insert directly into the final table that already has rows in it. Bulk insert into a staging table first, check it for dupes, than then do an insert from that table into the final table while also checking for dupes. It'll be a lot faster than trying to do the same thing with a trigger.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply