how to reset the value of a AUTO_INCREMENT row in a mysql table

surafel

Lets say i have have a table with 200 records and i deleted all of them now when i try to add another record to that table i want the id of the record to start from 1 instead of 201. i tried this code but doesn't work

$connection->query("ALTER TABLE table_name AUTO_INCREMENT = 1")

is there any other way to do this?

Thanks in advance

Panda

You'll need to truncate the table:

TRUNCATE table `tablename`

Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements.

Any AUTO_INCREMENT value is reset to its start value. This is true even for MyISAM and InnoDB, which normally do not reuse sequence values.

More information at http://dev.mysql.com/doc/refman/5.7/en/truncate-table.html.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to reset the value of a AUTO_INCREMENT row in a mysql table

From Java

How to reset AUTO_INCREMENT in MySQL?

From Dev

Reset Auto_Increment Value After Data Delete MySQL

From Dev

How to reset AUTO_INCREMENT in MySQL for all tables within a DB?

From Dev

How to reset the AUTO_INCREMENT

From Dev

Using variable in setting mysql INNODB AUTO_INCREMENT table value

From Dev

How to insert a value into an auto_increment of a different table in the same string

From Dev

Reset auto_increment after deleting row

From Dev

MySQL INSERT INTO SELECT into a table with AUTO_INCREMENT

From Dev

MySQL ALTER TABLE AUTO_INCREMENT and ORDER BY

From Dev

How to find all the auto_increment table

From Dev

How to assign a AUTO_INCREMENT value in rails

From Dev

How to find if a column is auto_increment in MySQL

From Dev

How to set AUTO_INCREMENT default value and rate of increase in MySQL 5.6

From Dev

how to set default value as text and auto increment in mysql table

From Java

Get current AUTO_INCREMENT value for any table

From Dev

PROBLEM WITH - AUTO_INCREMENT VALUE IN TABLE_SCHEMA NOT UPDATING

From Dev

Add auto_increment value to table with existing data

From Dev

Mysql: What is 'AUTO_INCREMENT=5' in a create table query?

From Dev

MYSQL & innoDB alter dynamically AUTO_INCREMENT of a table

From Dev

mysql like button table id auto_increment optimization

From Dev

Find next value of AUTO_INCREMENT column in MySQL

From Dev

resetting AUTO_INCREMENT value in MySQL avoiding race condition

From Dev

MySQL - Reserving ID's before the initial auto_increment value

From Dev

resetting AUTO_INCREMENT value in MySQL avoiding race condition

From Dev

How to set AUTO_INCREMENT from another table

From Dev

How to add auto_increment field to a table with huge data?

From Dev

How to implement an auto_increment composite primary key with MySQL InnoDB?

From Dev

How to implement an auto_increment composite primary key with MySQL InnoDB?

Related Related

  1. 1

    how to reset the value of a AUTO_INCREMENT row in a mysql table

  2. 2

    How to reset AUTO_INCREMENT in MySQL?

  3. 3

    Reset Auto_Increment Value After Data Delete MySQL

  4. 4

    How to reset AUTO_INCREMENT in MySQL for all tables within a DB?

  5. 5

    How to reset the AUTO_INCREMENT

  6. 6

    Using variable in setting mysql INNODB AUTO_INCREMENT table value

  7. 7

    How to insert a value into an auto_increment of a different table in the same string

  8. 8

    Reset auto_increment after deleting row

  9. 9

    MySQL INSERT INTO SELECT into a table with AUTO_INCREMENT

  10. 10

    MySQL ALTER TABLE AUTO_INCREMENT and ORDER BY

  11. 11

    How to find all the auto_increment table

  12. 12

    How to assign a AUTO_INCREMENT value in rails

  13. 13

    How to find if a column is auto_increment in MySQL

  14. 14

    How to set AUTO_INCREMENT default value and rate of increase in MySQL 5.6

  15. 15

    how to set default value as text and auto increment in mysql table

  16. 16

    Get current AUTO_INCREMENT value for any table

  17. 17

    PROBLEM WITH - AUTO_INCREMENT VALUE IN TABLE_SCHEMA NOT UPDATING

  18. 18

    Add auto_increment value to table with existing data

  19. 19

    Mysql: What is 'AUTO_INCREMENT=5' in a create table query?

  20. 20

    MYSQL & innoDB alter dynamically AUTO_INCREMENT of a table

  21. 21

    mysql like button table id auto_increment optimization

  22. 22

    Find next value of AUTO_INCREMENT column in MySQL

  23. 23

    resetting AUTO_INCREMENT value in MySQL avoiding race condition

  24. 24

    MySQL - Reserving ID's before the initial auto_increment value

  25. 25

    resetting AUTO_INCREMENT value in MySQL avoiding race condition

  26. 26

    How to set AUTO_INCREMENT from another table

  27. 27

    How to add auto_increment field to a table with huge data?

  28. 28

    How to implement an auto_increment composite primary key with MySQL InnoDB?

  29. 29

    How to implement an auto_increment composite primary key with MySQL InnoDB?

HotTag

Archive