我遇到了主键违规,我不知道如何解决它。实际的错误信息是;
消息 2627,级别 14,状态 1,第 1 行违反主键约束“PK_infmtx_dat_Transactions”。无法在对象“dbo.infmtx_dat_Transactions”中插入重复键。
我的代码如下:
INSERT INTO infmtx_dat_Transactions (tranid,chgid,chgidagnst,incnumagnst,rptpd,aid,claimid
,chgsvcpd,trantype,doschg,doscalpd,postdtchg,postdtchgcalpd,postdttran
,postdttrancalpd,depositdt,depositcalpd,cptid,cptcode,cptcomp,billprov
,rendprov,facid,posid,dptid,priminsmne,priminscatid,transcode,crcat
,refprovid,modalid,units,adjunits,patcnt,enccnt,cptcnt,amt,chgallow
,totworkrvu,totfacrvu,denial,curresponsible,curbal,curinsmne
,curopenbalflag,curcreditbalflag,denyflag,denycode,denydate,feetypeid )
SELECT
trn.tran_id
,trn.chg_id
,chg.chgidagnst
,chg.incnumagnst
,trn.rptpd
,trn.acctid
,chg.claimid
,chg.rptpd
,tcd.trantype
,chg.doschg
,chg.doscalpd
,chg.postdtchg
,chg.postdtchgcalpd
,trn.tranpostdt
,trn.tranpostpd
,trn.pmtdate
,trn.pmtpd
,chg.cptid
,chg.cptcode
,chg.cptcomp
,chg.billprov
,chg.rendprov
,chg.facid
,chg.posid
,chg.dptid
,chg.priminsmne
,chg.priminscatid
,trn.payermne
,tcd.crcat
,chg.refprovid
,chg.modalid
,0
,0
,0
,0
,0
,trn.trnamt
,chg.chgallow
,0
,0
,0
,''
,0
,''
,'N'
,'N'
,'N'
,''
,Null
,chg.feetypeid
FROM tmp_dat_OtherTrans trn
LEFT JOIN infmtx_dat_Transactions chg on trn.chg_id = chg.tranid AND trn.chg_id = chg.chgid
AND trn.chg_id = chg.chgidagnst
LEFT JOIN infmtx_dic_TransCode tcd on trn.payermne = tcd.trancodemne
ORDER BY trn.tran_id;
我将如何设置查询以查找重复记录。
表上的主键infmtx_dat_Transactions
有:tranid、chgid、chgidagnst、rptpd和trantype