help regarding auto increment

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

help regarding auto increment

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: help regarding auto increment

Post 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.
(#10850)
Post Reply