user3132907
user3132907

Reputation: 11

ALTER TABLE AUTO INCREMENT

I am having a problem with ALTER TABLE AUTO-INCREMENT. it does altered the table to 100 but it does not auto-increment. hope anyone can help me.. here is my code. thanks in advance.

$con=mysqli_connect("localhost","root","","info"); 
// Check connection

if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql= "ALTER TABLE profile AUTO_INCREMENT=100";


if (!mysqli_query($con,$sql))
  {
    die('Error: ' . mysqli_error($con));
  }

if (isset ($_POST['Register!']))
{
    $sql = "INSERT INTO staff_profile (name, age, address) 
    VALUES ('$name', '$age', '$address')";
    mysql_query($sql) or die (mysql_error());
}

Upvotes: 0

Views: 6254

Answers (1)

Lavneet
Lavneet

Reputation: 626

Well, you must specify the column name upon which you implemented the auto increment clause..

ALTER TABLE tbl 
    CHANGE itemid itemid INT(10) AUTO_INCREMENT PRIMARY KEY;

The above statement will change the itemid column to datatype INT, make it AUTO INCREMENT, and make it the primary key as well.

Now, you can set the initial value of auto_increment clause by following statement:

ALTER TABLE tbl AUTO_INCREMENT = 100;

Upvotes: 2

Related Questions