简体   繁体   中英

update values of auto_increment ID column on MySql using c#

I am new to MySql and coding. 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.

I know that the code that i need in MySql is :

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

How can I translate this into c# code?

I recommend you don't try changing the default behaviour of 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).

Refer to this answer on a related question , it sums up the topic quite well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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