0

Sorry for my English,

How can I delete rows in a table with indexing from the beginning in mysql?

I've got one table from which I have to delete all rows. How can I do it that rows will delete but index after add new row will begin from the one "1"?

Thank You for any help.

Regards Adrian

Adrian
  • 1
  • 2
  • 2
    Does this answer your question? "[MySQL Delete all rows from table and reset ID to zero](/q/12651867/90527)", "[How to reset AUTO\_INCREMENT in MySQL](/q/8923114/90527)" – outis Oct 29 '22 at 07:14
  • Welcome to SO. Please consult the [help] articles, especially "[ask]" and on [searching](/help/searching). See also "[How much research effort is expected of Stack Overflow users?](//meta.stackoverflow.com/q/261592/90527)". – outis Oct 29 '22 at 07:18

1 Answers1

0

Truncate table removes all data from a table, including the auto increment counters I believe.

 truncate table name_table

Using TRUNCATE TABLE statement The TRUNCATE TABLE statement removes all the data from a table and resets the auto-increment value to zero.

see: MySQL Reset Auto Increment Values

Luuk
  • 12,245
  • 5
  • 22
  • 33
Gerballi
  • 441
  • 5
  • I don't like mysql much. But the internet seems to prove me right: "Using TRUNCATE TABLE statement The TRUNCATE TABLE statement removes all the data from a table and resets the auto-increment value to zero." https://www.mysqltutorial.org/mysql-reset-auto-increment#:~:text=The%20TRUNCATE%20TABLE%20statement%20removes,auto%2Dincrement%20value%20to%20zero.&text=By%20using%20the%20TRUNCATE%20TABLE,auto%2Dincrement%20value%20to%20zero. – Gerballi Oct 29 '22 at 07:16
  • @Luuk People can say what they think. why do you obstruct people even if I strongly think that mysql is amazing? – Ozan Sen Oct 29 '22 at 07:41
  • Because that comment is off-topic. "Questions which are .... primarily opinion-based", and I do think this is the same for comments (quote from: [What topics can I ask about here?](https://stackoverflow.com/help/on-topic)) – Luuk Oct 29 '22 at 07:46
  • The relevance was in this case that I can't do a small test like someone suggested, but that post seems to be deleted. I've a postgress, mssql and sqlite instance to test with but no mysql. Mysql is fine, but I prefer others. – Gerballi Oct 29 '22 at 07:47
  • @Gerballi: You can do small tests here: https://dbfiddle.uk/ – Luuk Oct 29 '22 at 07:49
  • @Luuk What is the purpose of rules if somebody has no freedom of expression? Regarding relevance, some other DB's can have strong points than mysql offers, and maybe OP specified it! – Ozan Sen Oct 29 '22 at 07:59
  • @OzanSen: I do not think this is the place to keep this discussion going. But in general i do think the reason for this opiniated expression should be given too. If not given, then the statement is useless. – Luuk Oct 29 '22 at 08:03