SQL Server Performance

Inserting Data but no duplication should occur

Discussion in 'SQL Server 2008 General Developer Questions' started by apat, Sep 22, 2009.

  1. apat New Member

    Hi All,I have a question on inserting data to a table where some data already exists and I don't want to add them again. here is the scenario,I have two tables.. Source and Destination( where I want to insert data). Both tables have same 5 columns. There is no Unique Constraint, Primary Key, Composite PK etc and I can't add anything. Source Table has 200 records and Destination table has 90 records. I want to insert those 110 records from source table to Destination table which do not exists in destination table now. Also, in both the tables there are duplicate records in all the columns. Each column has duplicate records. but at any time one particular ROW(Records) is not Duplicate with any other ROW(Record). How to insert this data? Thanks in advance...
  2. FrankKalis Moderator

    If I understand you correctly, you can literally translated your requirement into a query. Something like:
    INSERT INTO dbo.TargetTable
    SELECT * FROM dbo.SourceTable ST
    WHERE NOT EXISTS (SELECT 1 FROM dbo.TargetTable TT WHERE ST.<PK_Column(s)> = TT.<PK_Column(s)>)

Share This Page