5

How to execute

ALTER TABLE tblname AUTO_INCREMENT = 123

as codeigniter active records query?

There is something called dbforge->modify_column() in codeigniter , do i have to use that, if so how?

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
Learner_Programmer
  • 1,259
  • 1
  • 13
  • 38

2 Answers2

4

try this

$this->db->query("ALTER TABLE table_name AUTO_INCREMENT 1");

change value after AUTO_INCREMENT where you want to start auto increment value from like this

$this->db->query("ALTER TABLE table_name AUTO_INCREMENT 12");

Alter table operation called DDL Data Defination Language where you execute queries at database not at data.

user2727841
  • 715
  • 6
  • 21
  • This is the answer to the OP's question, since he specifically asked if it's possible to start in a different index. The MySQL `ALTER` command receives a _start value_ when `AUTO_INCREMENT` is used, therefore we can do things like this sequentially: `$this->db->delete('mytable', ['id >', 3]); $this->db->query('ALTER TABLE mytable AUTO_INCREMENT 4');`. – CPHPython Dec 04 '18 at 09:39
3

$this->db->query('ALTER TABLE tbl_name AUTO_INCREMENT 1'); is working for me.

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
Learner_Programmer
  • 1,259
  • 1
  • 13
  • 38