I have this weird behavior of Schema Compare
in Visual Studio 2017
.
When comparing 2 databases, two identical tables I get difference that one of those has no
PK
name. If I would script out tables usingSSMS
I would see that indeed on one of the servers table script seems not to havePK
name, but if I would querysys.indexes
table I can find that this index has a same name on both of the servers.One possible solution I found is to update the table, let's say add some random index and remove it, so I am guessing that it has something to do with how SQL Server stores the objects definition. But it would be nice to know what is causing this and how to solve it in the right way and not with some kind of workarounds.
p.s. I know that the
PK
name is not "correct".Similar situation when comparing two identical
SPs
. I tried to runsp_refreshsqlmodule
andsp_recompile
but it didn't help. UpdatingSP
helps, but again this is not very nice workaround.
EDIT 1: In the first example PK with the same name exists on both databases (even though the name is not following standards). The following query ran on both databases returns identical result:
SELECT I.name
FROM sys.indexes AS I
INNER JOIN sys.objects AS O
ON O.object_id = I.object_id
INNER JOIN sys.schemas AS S
ON S.schema_id = O.schema_id
WHERE S.name = 'MySchema'
AND O.name = 'MyName'
Result: PK__TraceDat__AAAC09D801ED28A5