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:

This is then duplicated :

  objectId (no column name) 21912 2  

There is no trigger or anything associated with this table and the included statement is only a table Copying from other data, so ... Where is the duplicate coming from? Try the following:

  Insert in pagecentant cache (Object ID,   

ContentData) Choose different objectID, content from the #contact cache

can see why you will not have duplicates, as you have said, no one is included in your selection statement. Anyway, I guess the specific keywords will ensure that the duplicates will end.


Comments