sql - Insert statement with no joins results in duplicates where no duplicates existed previously? -
I am having problems with some SQL, which I would not expect. I am storing information from different tables in another table that is used as part of a search page on a website. All the page data on each page is referenced in the table called pageContentCache
with the data of other elements of other pages (such as calendar, etc.) This table usually has an index built with the following: / P>
Changing the table page Obstacle Adding Catch [IX_pageContentCache] Primary Key Cluster ([objectId])
For some reason, send me a duplicate objectId < / Code> will appear, one example of this problem is this problem Or result in the following error:
Message 1505, Level 16, State 1 Process, sp_rebuildPageContentCache, Line 50
Create Unique Index Statement Ended because a duplicate key was found for the object name 'dbo.pageContentCache' and the index 'IX_pageContentCache'. Duplicate key value (21912).
In this way, to debug this issue, give me the pageContentCache
table in a temporary table, #contentcache
, first, That's why I could see it.
This is where I'm starting to confuse a little bit ...
Once the data is #contentcache
(which has two columns, objectId
and content
), I can run the following SQL statement and it will not return anything:
Select ObjectId; count (objectId) #contentcache to be objectId from group (countId) and gt; 1
This gives no record if I run the following SQL: Insert in the pageContent cache (ObjectID, ContentData) select objectId, from #contentcache Content
This includes all data from #contentcache
in the page content cache
as you would like though, if I expect the following If I run SQL, then it gives a duplicate:
Comments
Post a Comment