简体   繁体   English

如何同步以前删除的行

[英]How to synchronize previously deleted rows

I have a junction/ many to many table in my database.我的数据库中有一个连接点/多对多表。 This table has 2 columns forming a composite primary key;该表有 2 列构成复合主键; userid & groupid.用户 ID 和组 ID。

I'm having an issue where once a row is deleted it can never be re-added and synced again.我遇到了一个问题,一旦一行被删除,就永远无法重新添加和同步。 For example:例如:

  1. user 123 is added to group 456 changes synchronized, upload direction.用户 123 添加到组 456 更改同步,上传方向。 Row is added to remote.行被添加到远程。
  2. user 123 removed from group 456 (row tombstoned in table meta and row removed from base table)用户 123 从组 456 中删除(表元中的行墓碑和从基表中删除的行)
  3. changes synchronized, upload direction.变化同步,上传方向。 Row is removed on remote行在远程被删除
  4. user 123 is added to group 456用户 123 添加到组 456
  5. changes synchronized, upload direction.变化同步,上传方向。 Row is not inserted in remote.行未插入远程。

I'm guessing that the scope knowledge is retaining the fact that the row was once deleted and not syncing changes to it?我猜测范围知识保留了该行曾经被删除而不同步更改的事实? Is this understanding correct?这种理解是否正确? Is there anyway to clean this knowledge?反正有没有清理这些知识?

If any of key columns have IDENTITY property set, then you cannot simply insert values in such column.如果任何键列设置了IDENTITY属性,则您不能简单地在此类列中插入值。 You should use this property wisely - its idea it to ensure keys are never repeated.你应该明智地使用这个属性——它的想法是确保键永远不会重复。

So if you really need to insert values into IDENTITY column use SET IDENTITY_INSERT MyTable ON/OFF .因此,如果您确实需要将值插入IDENTITY列,请使用SET IDENTITY_INSERT MyTable ON/OFF Only one table in a db can have this property set to ON. db 中只有一个表可以将此属性设置为 ON。 If it is off - an error occurs.如果关闭 - 会发生错误。

CREATE TABLE MyTable (ID INT IDENTITY NOT NULL)
SET IDENTITY_INSERT MyTable ON/OFF
INSERT INTO MyTable VALUES (2)
SET IDENTITY_INSERT MyTable ON/OFF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM