Disallowing duplicate entries across columns

  • Greetings . . .

    I am a newbie to this forum (and relatively new to SQL Server), so please bear with me.

    I want to import a large number of records into a SQL Server 2000 database. My concern is as follows: I do *not* want to allow import of duplicate data that spans multiple columns.

    To illustrate my question, lets say I have a row with three columns. The data in the row is as follows:

    Apple Pear Banana

    I *do* want the import to allow any of the following:

    Apple Orange Strawberry

    Apple Pear Orange

    Grape Mango Pear

    However, I do NOT want to allow the following entry:

    Apple Pear Banana

    In other words, I don't want to allow import if ALL data columns already exist.

    The import can get very large (more than 10000 records).

    Does anyone know how I can address this?

    Thanks in advance for your help!

  • First if your data is coming the DTS or Import wizard use a query to define what is coming from your remote source using the SELECT DISTINCT method, if there are additional columns this won't work though and you may need to import first, then delete those records that would duplicate.

    Then either make the columns a single Primary Key, or create a unique constriant.

    If these are the columns that matter most and queries run often against them then go the PK route across the columns and make a clustered index to save space and increase querying speed.

    If not creat a unique constriant.

    Which will stop anyone from entering another duplicate of those, but note it will stop imports as well.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • I tend to agree that a PK or alternate unique key is the best solution.

    Steve Jones

    steve@dkranch.net

  • I just tried it out (setting the multiple columns to the unique key), and it seems to work. Thanks for your help!

  • You are welcome. Glad it worked.

    Steve Jones

    steve@dkranch.net

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

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