Page 1 of 1

help regarding auto increment

Posted: Sun Aug 23, 2009 8:20 pm
by greedyisg00d
I have a table employee where EmployeeID field is set as primary key. How can I create a custom auto increment for my EmployeeID for example:

EmployeeID
SDD00001
SDD00002
SDD00003

Thus when new records are inserted it will automatically increment just like in the example.
Any idea on how can this be done. Thanks

Re: help regarding auto increment

Posted: Sun Aug 23, 2009 8:33 pm
by Christopher
autoincrement fields are only integer. You could produce your ID with

Code: Select all

$EmployeeID = 'SDD' . str_pad($id, 5, '0', STR_PAD_LEFT);
$EmployeeID = sprintf('SDD%05u', $id);
You could also do this kind of thing in SQL to fetch an Employee ID based on an autoincrement integer.