I have a table named “myTable”
It has two columns.
They are “ID” and “myNumeric”.
Both “ID” and “myNumeric” are int and ID is primary key.
It has no records at the moment in the table.
When the code above is executed for the first time,
it produces “0” although I am expecting “1” because it is the first record.
the table becomes like the following.
Well it’s not really a fix but why not insert one row then delete it. Im pretty sure next row will AI at 1 since old IDs are not reused. But beware as rows are added and deleted you will not have a continuous 1-10,000 or whatever, you will have gaps.
I think chorn and rpkamp are right, if col is AI should start as 1. Also in my opinion, using an AI id is really only good for that - an ID. If you want to sort or something like that you probably need to manage another col
You have something else going on here. mysql autoinc does start with 1. Not sure how it is even possible to get a zero in there.
Here is a quick test you can run from a mysql console window:
use play;
DROP TABLE IF EXISTS myTable;
CREATE TABLE myTable (
id int NOT NULL AUTO_INCREMENT,
myNumeric int,
PRIMARY KEY (id)
);
INSERT INTO myTable (myNumeric) VALUES(1111);
SELECT * FROM myTable;
+----+-----------+
| id | myNumeric |
+----+-----------+
| 1 | 1111 |
+----+-----------+
1 row in set (0.00 sec)
If you have used mysql database for storing and retriving data of your project. in your database you have one table which store the student_id and name of the student. id must be unique and also primary key.so it gives the auto_increment.So insert_id starting with “1”. if you delete table and re-insert data then insert_id start with this number when it is stopped.if You truncate the table and re-insert data than it starting with “1”.my project also work for that type of functionalities.