i am getting
 can not insert duplicate key row in objec
 how to solve with help of profiler i mean which recopred or row is the main
 problem who makes duplicates not allowing updates to come in db
 --
 m.abduInsert into a staging table first, then query to see which row would be the
duplicate.
"mohamed abdu" <mohamedabdu@.discussions.microsoft.com> wrote in message
news:CFFD1E37-3CF1-41C4-9987-6FAEE10C7DF8@.microsoft.com...
> i am getting
>
> can not insert duplicate key row in objec
> how to solve with help of profiler i mean which recopred or row is the
main
> problem who makes duplicates not allowing updates to come in db
> --
> m.abdu|||mohamed
CREATE TABLE #Demo (
 idNo int identity(1,1),
 colA int,
 colB int
)
INSERT INTO #Demo(colA,colB) VALUES (1,6)
INSERT INTO #Demo(colA,colB) VALUES (1,6)
INSERT INTO #Demo(colA,colB) VALUES (2,4)
INSERT INTO #Demo(colA,colB) VALUES (3,3)
INSERT INTO #Demo(colA,colB) VALUES (4,2)
INSERT INTO #Demo(colA,colB) VALUES (3,3)
INSERT INTO #Demo(colA,colB) VALUES (5,1)
INSERT INTO #Demo(colA,colB) VALUES (8,1)
PRINT 'Table'
SELECT * FROM #Demo
PRINT 'Duplicates in Table'
SELECT * FROM #Demo
WHERE idNo IN
 (SELECT B.idNo
 FROM #Demo A JOIN #Demo B
 ON A.idNo <> B.idNo
 AND A.colA = B.colA
 AND A.colB = B.colB)
PRINT 'Duplicates to Delete'
SELECT * FROM #Demo
WHERE idNo IN
 (SELECT B.idNo
 FROM #Demo A JOIN #Demo B
 ON A.idNo < B.idNo -- < this time, not <>
 AND A.colA = B.colA
 AND A.colB = B.colB)
DELETE FROM #Demo
WHERE idNo IN
 (SELECT B.idNo
 FROM #Demo A JOIN #Demo B
 ON A.idNo < B.idNo -- < this time, not <>
 AND A.colA = B.colA
 AND A.colB = B.colB)
PRINT 'Cleaned-up Table'
SELECT * FROM #Demo
DROP TABLE #Demo
"mohamed abdu" <mohamedabdu@.discussions.microsoft.com> wrote in message
news:CFFD1E37-3CF1-41C4-9987-6FAEE10C7DF8@.microsoft.com...
>i am getting
>
> can not insert duplicate key row in objec
> how to solve with help of profiler i mean which recopred or row is the
> main
> problem who makes duplicates not allowing updates to come in db
> --
> m.abdusql
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment