error while deleting duplicate records

  • Hi everyone..

    I have dimension table like dim_customerinfo.unexpectedly i run two times,so the data load two times,i want to delete duplicate records,how can i delete duplicate records.I have written the query to delete duplicate records like this

    delete from dim_customerinfo where custkey not in (select MAX(custkey) from dim_customerinfo group by Customer_Code,Customer_FirstName,Customer_LastName)

    but it does not execute,the following error is coming

    The DELETE statement conflicted with the REFERENCE constraint "FK_Salesfact_Dim_Customerinfo". The conflict occurred in database "Narasimha_WareHouse", table "dbo.Salesfact", column 'custkey'.

    Can any one give the solution....

    Regards..
    guru12

  • Hi,

    First disable the constraints on the table and run the delete command....

  • Looks to me like your delete query is not sophisticated enough and will leave behind orphaned records - except your referential integrity rules are currently stopping that. Be careful.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

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

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