简体   繁体   English

使用c#更新MySql上的auto_increment ID列的值

[英]update values of auto_increment ID column on MySql using c#

I am new to MySql and coding. 我是MySql和编码的新手。 i have an Aid column that is Primary Key and Auto Increment in settings. 我有一个“辅助”列,它是设置中的“ 主键”和“ 自动递增” But while I delete a row it doesn't update the Aid. 但是,当我删除一行时,它不会更新Aid。

I know that the code that i need in MySql is : 我知道我在MySql中需要的代码是:

SET @a = 0;
UPDATE aircraft.l1201 SET l1201.Aid = @a := @a +1;

How can I translate this into c# code? 如何将其转换为C#代码?

I recommend you don't try changing the default behaviour of AutoIncrement. 我建议您不要尝试更改AutoIncrement的默认行为。 Changing all IDs after deleting a row doesn't bring you any real advantages, but a lot of disadvantages, including a potentially high amount of update operations after every delete as well as the risk of destroying referential integrity (in case ON UPDATE CASCADE isn't used). 删除一行后更改所有ID并不会带来任何真正的好处,但是有很多缺点,包括每次删除后可能进行大量的更新操作,以及破坏参照完整性的风险(以防ON UPDATE CASCADE是' t使用)。

Refer to this answer on a related question , it sums up the topic quite well. 参考一个有关问题的答案 ,它很好地总结了话题。

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

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