Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset autoincrement value in mysql?

Tags:

mysql

My company has different type of invoices. Example:

H00001/2013 . . . H99999/2013

and

T00001/2013 . . . T99999/2013

The problem is, the numbering is increasing for new year. How can I make auto increment value reset for each new year?

This is my current code:

    CREATE TABLE `invoices` ( 
      `invoicenumber` mediumint unsigned NOT NULL auto_increment, 
      `invoicetype` enum('A','B') NOT NULL, 
      `date` date NOT NULL, 
      `client` varchar(100) NOT NULL,
      PRIMARY KEY (invoicetype,invoicenumber)
    ) COMMENT='' ENGINE='MyISAM'; 
like image 525
user2862056 Avatar asked Dec 20 '22 23:12

user2862056


1 Answers

Hey if you are using any client application for database like MysqlWorkBench or MYSQL Query Browser then you can do below steps to set AutoIncrement no -

  • Right click on Table and go to Alter Table
  • Select Options tab
  • Under that you can find Auto Increment label there you can reset the number.
like image 186
Dharm Avatar answered Jan 13 '23 15:01

Dharm