questions about a priamry key

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ashlar

questions about a priamry key

Post by ashlar » Sat 08 Jul 2006 00:48

In one of my tables I have a primary key which is a int. It also is a unsigned int and is set to auto-increment.

If I add lets say 20 records and then delete those 20 records how can I stop or reset it so that it doesn't start the next record on 21? How can I get it to start back at 1?

Zagawa
Posts: 21
Joined: Fri 12 May 2006 09:56

Post by Zagawa » Mon 10 Jul 2006 10:05

Here is the query to reset Auto Increment

Code: Select all

ALTER TABLE tbl_name AUTO_INCREMENT = 0

Matthew
Posts: 4
Joined: Fri 29 Jun 2012 15:12

Re: questions about a priamry key

Post by Matthew » Thu 30 Oct 2014 17:19

Is it possible to "reset" or "set" the auto-increment value inside Delphi code?
If so I need help in setting up that code, thanks,

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: questions about a priamry key

Post by ViktorV » Fri 31 Oct 2014 08:24

Here is a code example that demonstrates how to reset auto increment field:

Code: Select all

MyConnection.ExecSQL('ALTER TABLE tbl_name AUTO_INCREMENT = 0');

Matthew
Posts: 4
Joined: Fri 29 Jun 2012 15:12

Re: questions about a priamry key

Post by Matthew » Fri 31 Oct 2014 15:20

Thanks!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: questions about a priamry key

Post by ViktorV » Mon 03 Nov 2014 05:55

Feel free to contact us if you have any further questions.

Post Reply