|
| |
Pre defined value for a MySQL auto increment field |
We can start an auto increment field from a pre defined value. For example when we issue a student ID number, where student ID is an auto increment field we can generate IDs with values 100001 from the first record. This helps as we don't want to give a number like 1 to the first student and end with number 10004. This way we can have first number as 100001 and last number 110005. This way all the students will have six digit number.
This we can take care while creating the table by adding auto increment value at the end. Here is the SQL for creating a student table with auto increment field is set to 100000
CREATE TABLE student (
id int(2) NOT NULL auto_increment,
name varchar(50) NOT NULL default '',
class varchar(10) NOT NULL default '',
mark int(3) NOT NULL default '0',
sex varchar(6) NOT NULL default 'male',
UNIQUE KEY id (id)
) auto_increment=100000 TYPE=MyISAM;
If you delete all records by truncate table sql command then while adding the first record the auto increment field will start from 1.
| |
|
|
|