SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

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.


Further readings
MySQL Auto Increment field to generate unique record ID
How to start auto increment value from a predefined value ?
mysql_insert_id() to get the auto increment number of just inserted record








Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
SQL Tutorial List
SQL Commands
SQL Sections
Date & Time
Join Table
String
Math
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.