1

I want all the values of the first field(custId) of sql table to start with 100 such that the first value is 1001 up to 100n-1. my sample code is :

create table customer(custId int(25) primary key not null auto_increment,);
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • 3
    Possible duplicate of [How to set initial value and auto increment in MySQL?](https://stackoverflow.com/questions/1485668/how-to-set-initial-value-and-auto-increment-in-mysql) – A. Bandtock Apr 04 '18 at 13:36
  • What happens when you hit your tenth record? Do you expect to use 1010 or 10010? In the first case you can just set your starting value in your sequence; in the second you can probably get away with sticking 100 on the front when you display it (though your use case isn't at all clear). – ChrisGPT was on strike Apr 04 '18 at 13:41
  • i want the 10th value to be 10010 – Niyonsaba Alex Apr 05 '18 at 12:38

2 Answers2

2

Try with below query

Set the Auto increment value when create the table.

create table customer(custId int(25) primary key not null auto_increment,) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1001;
Siva
  • 1,481
  • 1
  • 18
  • 29
1

Once your create query is executed, alter the auto increment start value to 1000.

ALTER TABLE customer AUTO_INCREMENT=1001;

So the first record would have custId = 1001